yeh that''s weird.
I get -0.000004 when using cos(1.5708)
Rotating Points about origin
You mean u don't get 6.123 on your computer?
[edited by - GamerSg on July 7, 2003 7:33:07 AM]
[edited by - GamerSg on July 7, 2003 7:33:07 AM]
Well i got
-3.6732051033725085976773671369636e-6
using Windows calculator when i cos(1.5708)
So this appears to be limited to only the PC.
I don''t know what the letter e means. Does it mean that the following number is actually 6 decimal points away from the decimal point?
i.e
-0.00000036732051033725085976773671369636
-3.6732051033725085976773671369636e-6
using Windows calculator when i cos(1.5708)
So this appears to be limited to only the PC.
I don''t know what the letter e means. Does it mean that the following number is actually 6 decimal points away from the decimal point?
i.e
-0.00000036732051033725085976773671369636
"Different AP"
Cosine and Sine will never return a value greater than 1 or less than -1
The Cosine of 90 degrees is 0. Try using 1.5707982f for your angle.
quote:Original post by GamerSg
Ok this is really weird.
the cos of 90 degrees which is 1.5708 in radians.
When i cos(1.5708) and print out the results, i get 6.123....
But when i cos(1.5708) on my scientific calculator in radian mode i get almost 0.
Im using the math.h library and i don''t know why i am getting incorrect results.
quote:Original post by GamerSg 90 degrees which is 1.5708 in radians;correct
quote:Original post by GamerSg When i cos(1.5708) and print out the results, I get 6.123;
Cosine and Sine will never return a value greater than 1 or less than -1
quote:Original post by GamerSg But when i cos(1.5708) on my scientific calculator in radian mode i get almost 0.
The Cosine of 90 degrees is 0. Try using 1.5707982f for your angle.
quote:Original post by GamerSg
Does it mean that the following number is actually 6 decimal points away from the decimal point?
i.e
-0.00000036732051033725085976773671369636
Correct. It''s a form of scientific notation.
quote:Original post by Bero_Avrion
Sure it would! But sometimes you need the real coordinates, not only the result...
//x,y,z:original coordinates, x_a, y_a, z_a: angles for rotation
void vertex(float x, float y, float z, float x_a, float y_a, float z_a)
{
float x_alt, y_alt, z_alt;
x_a=(x_a/180)*PI;
y_a=(y_a/180)*PI;
z_a=(z_a/180)*PI;
//rotate z-axis
x_alt=x;
y_alt=y;
z_alt=z;
x=x_alt*cos(z_a)-y_alt*sin(z_a);
y=y_alt*cos(z_a)+x_alt*sin(z_a);
//rotate y-axis
x_alt=x;
y_alt=y;
z_alt=z;
x=(x_alt*cos(y_a)-z_alt*sin(y_a));
z=(z_alt*cos(y_a)+x_alt*sin(y_a));
//rotate x-axis
x_alt=x;
y_alt=y;
z_alt=z;
y=(y_alt*cos(x_a)-z_alt*sin(x_a));
z=(z_alt*cos(x_a)+y_alt*sin(x_a));
glVertex3f(x,y,z);
}
perhaps this will help you.
<SPAN CLASS=editedby>[edited by - Bero_Avrion on July 6, 2003 4:07:43 PM]</SPAN>
<SPAN CLASS=editedby>[edited by - Bero_Avrion on July 6, 2003 4:09:48 PM]</SPAN>
I''m now using the algorithm you quoted and it works fine only if the the rotation value is 0 or 360 meaning it does not rotate at all.
void Scene::initCol() { //float distance=0; float tx; float tz; float sinr; float cosr; for(int i=0;i<numOfObj;i++) { sinr=float(sin(Objects.rotY*PI/180));//amount to rotate collission detection values cosr=float(cos(Objects.rotY*PI/180));//amount to rotate collission detection values<br> for(int j=0;j<Objects.numOfVertex;j++)<br> {<br> //x=(x_alt*cos(y_a)-z_alt*sin(y_a));<br> //z=(z_alt*cos(y_a)+x_alt*sin(y_a)); <br> tx=Objects.vertex[j][0];<br> tz=Objects.vertex[j][2];<br> Objects.vertex[j][0]=tx*cosr-tz*sinr;<br> Objects.vertex[j][2]=tz*cosr+tx*sinr;<br> Objects.vertex[j][0]+=Objects.posX;<br> Objects.vertex[j][1]+=Objects.posY;<br> Objects.vertex[j][2]+=Objects.posZ;<br><br> }<br><br> }<br> }<br> </pre> <br><br>Still can''t get it to work with any other angle other than 0 and 360. </i>
Used wrong tag.
void Scene::initCol() { //float distance=0; float tx; float tz; float sinr; float cosr; for(int i=0;i<numOfObj;i++) { sinr=float(sin(Objects[i].rotY*PI/180));//amount to rotate collission detection values cosr=float(cos(Objects[i].rotY*PI/180));//amount to rotate collission detection values for(int j=0;j<Objects[i].numOfVertex;j++) { //x=(x_alt*cos(y_a)-z_alt*sin(y_a)); //z=(z_alt*cos(y_a)+x_alt*sin(y_a)); tx=Objects[i].vertex[j][0]; tz=Objects[i].vertex[j][2]; Objects[i].vertex[j][0]=tx*cosr-tz*sinr; Objects[i].vertex[j][2]=tz*cosr+tx*sinr; Objects[i].vertex[j][0]+=Objects[i].posX; Objects[i].vertex[j][1]+=Objects[i].posY; Objects[i].vertex[j][2]+=Objects[i].posZ; } } }
Quick question: I noticed the word "collision". Are you using this to rotate two objects' centers to a specific angle before doing a specific collision test? Because you can do most (if not all) of that stuff using vector projection.
[edited by - Nypyren on July 7, 2003 10:53:24 PM]
[edited by - Nypyren on July 7, 2003 10:53:24 PM]
Eh sorry but i dont understand what you are talking about.
I think i know whats wrong now, its not the code, its just that i forgot that when i am calculating the new vertices, i also have to recalculate the normals, this is why it was working when there was no rotation.
Thanks to Bero_Avrion for the algorithm.
I think i know whats wrong now, its not the code, its just that i forgot that when i am calculating the new vertices, i also have to recalculate the normals, this is why it was working when there was no rotation.
Thanks to Bero_Avrion for the algorithm.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement