Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Need professional help...
Index -> General Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Homer_simpson




PostPosted: Sat Mar 06, 2004 9:47 pm   Post subject: Need professional help...

First of all no spamming i'll delete yer spams and take bits away Evil or Very Mad

here's the situation:
i got normals for my polygons... and as we all know normals are vectors...
then i got the normalized vector from my light source to my vector.
after normalizing the light source vectori use the dotproduct to calculate the angle in between the 2 angles and the answers comes in radians...
but sometimes for some reason the answer is bigger than one... so when i pass it through arcsin i get errors anyone know why? here's my code:

code:

            lightv [0] = light1 [0] - polynormals [i] [0]; //first we subtract the object locating from light source to get it's vector
            lightv [1] = light1 [1] - polynormals [i] [1];
            lightv [2] = light1 [2] - polynormals [i] [2];
            tmagnitude = Math.sqrt ((lightv [0] * lightv [0]) + (lightv [1] * lightv [1]) + (lightv [0] * lightv [0])); //then calculate the length to normalize
            lightv [0] /= tmagnitude; //normalize the light source vector
            lightv [1] /= tmagnitude;
            lightv [2] /= tmagnitude;

            dotproduct = (lightv [0] * polynormals [i] [0]) + (lightv [1] * polynormals [i] [1]) + (lightv [2] * polynormals [i] [2]); //obviously dot product
            angle = Math.acos (dotproduct) / (3.141592653 / 180); //here's where da error is


i can't seem to figure it out Crying or Very sad
Posted Image, might have been reduced in size. Click Image to view fullscreen.



vector.JPG
 Description:
 Filesize:  11.06 KB
 Viewed:  2813 Time(s)

vector.JPG


Sponsor
Sponsor
Sponsor
sponsor
Catalyst




PostPosted: Sat Mar 06, 2004 11:33 pm   Post subject: (No subject)

shouldnt this

code:

tmagnitude = Math.sqrt ((lightv [0] * lightv [0]) + (lightv [1] * lightv [1]) + (lightv [0] * lightv [0]));


be this
code:

tmagnitude = Math.sqrt ((lightv [0] * lightv [0]) + (lightv [1] * lightv [1]) + (lightv [2] * lightv [2]));
Homer_simpson




PostPosted: Sun Mar 07, 2004 12:52 am   Post subject: (No subject)

Laughing Laughing Laughing Laughing Laughing Laughing Laughing
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHAHAHAHAHAHAAAAA!!!!! Man i'm a fvckin stoner!!! What a stupid mistake!

Man that deserves bits! +lotsa bits!

thx a lot man it works perfectly fine now. would have never figured that without yer help! LOL


btw i made a little graphic thingy in assembly for pascal... pm me if u want it.
da_foz




PostPosted: Mon Mar 08, 2004 4:25 pm   Post subject: (No subject)

Subscripts are the devil. So hard to find the mistakes.
wtd




PostPosted: Mon Mar 08, 2004 4:42 pm   Post subject: (No subject)

da_foz wrote:
Subscripts are the devil. So hard to find the mistakes.


While I don't necessarily agree with that, you should attempt to refactor your code. There should never be that much code in one function.
Homer_simpson




PostPosted: Mon Mar 08, 2004 6:09 pm   Post subject: (No subject)

Maaaan!!! the thread is already over!
shut the hell up! Evil or Very Mad
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: