I understand i need to get the Dotproduct of the 2 vectors and then set the rotationz for the bottom teapot so it looks up at the other above it ,do you have to convert the DotProduct to radians as its in degrea's?
vectors are
D3DXVECTOR3 TeaPotPos(0.0f,-3.0f,-10.0f);
D3DXVECTOR3 TeaPotPos2(0.0f,3.0f,-10.0f);
pic included
http://img709.images.../1994/helpk.jpg
Thanks for reading
Compute Angle to rotate
Started by Anddos, Dec 16 2009 06:23 PM
8 replies to this topic
#1
Posted 16 December 2009 - 06:23 PM
#2
Posted 16 December 2009 - 08:04 PM
First of all, the angle in your picture is 90 degrees, not 180 radians. There are only 2pi radians in a circle, so 180 radians doesn't make sense. Secondly, forget degrees, start thinking in radians. Everything in math programming is always in radians.
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.
-
Currently working on: the 3D engine for Tomb Raider.
#3
Posted 16 December 2009 - 08:06 PM
Also the dot product doesn't return degrees or radians. To get an angle out of it, first you have to normalize the two vectors you're dotting. Then the dot product is the cosine of the angle between them. Call acos() and you've got the angle in radians.
reedbeta.com - developer blog, OpenGL demos, and other projects
#4
Posted 16 December 2009 - 08:38 PM
Thank you so much i will try that now , yeh it was a typo saying 180 , i did mean 90 :)
so i try this, dosen't look like its done what i want
Angle says 0.761013
so i try this, dosen't look like its done what i want
Angle says 0.761013
D3DXVECTOR3 TeaPot1Pos(0.0f,2.0f,-5.0f); D3DXVECTOR3 TeaPot2Pos(0.0f,-2.0f,-5.0f); D3DXVec3Normalize (&TeaPot1Pos,&TeaPot1Pos); D3DXVec3Normalize (&TeaPot2Pos,&TeaPot2Pos); float Dot = D3DXVec3Dot(&TeaPot1Pos,&TeaPot2Pos); float Angle = acos(Dot); //should be 90 D3DXMATRIX TeaPot1Matrix; D3DXMatrixTranslation(&TeaPot1Matrix,TeaPot1Pos.x,TeaPot1Pos.y,TeaPot1Pos.z); D3DXMATRIX TeaPot1Rot; D3DXMatrixRotationZ(&TeaPot1Rot,Angle); d3ddev->SetTransform(D3DTS_WORLD,&(TeaPot1Rot * TeaPot1Matrix)); meshTeapot->DrawSubset(0); D3DXMATRIX TeaPot2Matrix; D3DXMatrixTranslation(&TeaPot2Matrix,TeaPot2Pos.x,TeaPot2Pos.y,TeaPot2Pos.z); d3ddev->SetTransform(D3DTS_WORLD,&TeaPot2Matrix); meshTeapot2->DrawSubset(0);
#5
Posted 16 December 2009 - 09:01 PM
Anddos said:
Thank you so much i will try that now , yeh it was a typo saying 180 , i did mean 90 
Quote
float Angle = acos(Dot); //should be 90
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.
-
Currently working on: the 3D engine for Tomb Raider.
#6
Posted 16 December 2009 - 09:10 PM
ok sorry , so it should be 180 radians,Angle says 0.761013, should it not be 180 float
#7
Posted 16 December 2009 - 11:39 PM
LOL. Maybe you should try actually READING the messages people write to you. Look at this: http://www.math.rice...re/drg_txt.html. Degrees are the ones that go from 0 to 360. Radians are the ones that go from 0 to 2*pi.
reedbeta.com - developer blog, OpenGL demos, and other projects
#8
Posted 17 December 2009 - 06:33 AM
I have no idea.
you used to be able to fit a game on a disk, then you used to be able to fit a game on a cd, then you used to be able to fit a game on a dvd, now you can barely fit one on your harddrive.
#9
Posted 17 December 2009 - 11:59 AM
Anddos said:
ok sorry , so it should be 180 radians,Angle says 0.761013, should it not be 180 float
But indeed, I haven't looked at the actual coordinates at first, but the angle seems correct to me (0.761013 radians equals roughly 43.6 degrees). Just flipping a vector about the y-axis doesn't mean it's rotated 180 degrees. I get the feeling you're actually thinking in 2D, while your vectors are in 3D.
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.
-
Currently working on: the 3D engine for Tomb Raider.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












