forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Small bug in gumInternal.c

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
ciccan



Joined: 17 Jul 2005
Posts: 2

PostPosted: Sun Aug 28, 2005 5:13 pm    Post subject: Small bug in gumInternal.c Reply with quote

Code:
Index: gumInternal.c
===================================================================
--- gumInternal.c       (revision 946)
+++ gumInternal.c       (working copy)
@@ -65,7 +65,7 @@
 
 void gumNormalize(ScePspFVector3* v)
 {
-       float l = (v->x*v->x) + (v->y*v->y) + (v->z*v->z);
+       float l = sqrtf((v->x*v->x) + (v->y*v->y) + (v->z*v->z));
        if (l > GUM_EPSILON)
        {
                float il = 1.0f / l;
Back to top
View user's profile Send private message
chp



Joined: 23 Jun 2004
Posts: 313

PostPosted: Sun Aug 28, 2005 11:46 pm    Post subject: Reply with quote

Oops! That's what I get for writing code on a train without ability to test it. :)

Fixed. Thanks!
_________________
GE Dominator
Back to top
View user's profile Send private message
ciccan



Joined: 17 Jul 2005
Posts: 2

PostPosted: Mon Aug 29, 2005 10:56 am    Post subject: Reply with quote

Here's a couple more. I think sceGumLookAt is OK with these changes.

Code:
Index: gumInternal.c
===================================================================
--- gumInternal.c       (revision 963)
+++ gumInternal.c       (working copy)
@@ -58,9 +58,9 @@
 
 void gumCrossProduct(ScePspFVector3*r, const ScePspFVector3* a, const ScePspFVector3* b)
 {
-       r->x = (a->y * b->z) + (a->z * b->y);
-       r->y = (a->z * b->x) + (a->x * b->z);
-       r->z = (a->x * b->y) + (a->y * b->x);
+       r->x = (a->y * b->z) - (a->z * b->y);
+       r->y = (a->z * b->x) - (a->x * b->z);
+       r->z = (a->x * b->y) - (a->y * b->x);
 }
 
 void gumNormalize(ScePspFVector3* v)
Index: sceGumLookAt.c
===================================================================
--- sceGumLookAt.c      (revision 963)
+++ sceGumLookAt.c      (working copy)
@@ -37,8 +37,8 @@
   m.y.z = -forward.y;
   m.z.z = -forward.z;
 
-  sceGumMultMatrix(&m);
-
   ieye.x = -eye->x; ieye.y = -eye->y; ieye.z = -eye->z;
   sceGumTranslate(&ieye);
+
+  sceGumMultMatrix(&m);
 }
Back to top
View user's profile Send private message
chp



Joined: 23 Jun 2004
Posts: 313

PostPosted: Tue Aug 30, 2005 5:03 am    Post subject: Reply with quote

Thanks! Good thing someone tests this code. I sure didn't before submitting. And see how it turned out. :)
_________________
GE Dominator
Back to top
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Tue Aug 30, 2005 4:07 pm    Post subject: Reply with quote

Code:

-       float l = (v->x*v->x) + (v->y*v->y) + (v->z*v->z);
+       float l = sqrtf((v->x*v->x) + (v->y*v->y) + (v->z*v->z));
        if (l > GUM_EPSILON)
        {
                float il = 1.0f / l;


I think
Code:

        float l = (v->x*v->x) + (v->y*v->y) + (v->z*v->z);
-        if (l > GUM_EPSILON)
+        if (l > GUM_EPSILON*GUM_EPSILON)
         {
-                float il = 1.0f / l;
+                float il = 1.0f / sqrtf(l);


would be better.

Don't know how often this fragment is called though.

Great work with psp gl!

Jim
_________________
http://www.dbfinteractive.com
Back to top
View user's profile Send private message Visit poster's website
chp



Joined: 23 Jun 2004
Posts: 313

PostPosted: Tue Aug 30, 2005 5:26 pm    Post subject: Reply with quote

Well, the if() is only to avoid creating a NaN from the division, so it should always be true as long as you pass it valid data.

Oh, and this isn't for pspgl... :)
_________________
GE Dominator
Back to top
View user's profile Send private message
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Tue Aug 30, 2005 5:49 pm    Post subject: Reply with quote

You're right, if GUM_EPSILON is very tiny, then GUM_EPSILON * GUM_EPSILON might underflow anyway.

Jim
_________________
http://www.dbfinteractive.com
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group