View Full Version : draw a cube in direction of a vector!
06-23-2010, 02:39 PM
i am absolutle begginer in opengl(in fact it's my first program)
i want to draw a cube in direction of a vector!
i need this to draw a robotic arm.
i just have 2 points which shows begin and end of arm(a cube for example) and i want to draw in direction of vector of that 2 points!
i searched a lot but nothing seems to do that.
is there any way that i can do this?
sorry for my bad english
06-24-2010, 10:48 AM
you'll need another vector to know which way is up in order to position the cube otherwise you don't know which way it's tilted along it's z axis, if there's no roll involved use vector3(0.0,1.0,0.0) that will point up in world coordinates. You also need the dimensions of the cube. so given:
Zvector(direction the cube is oriented, obtained by point2-point1)
Xvector(Obtained from the cross product of up and Z)
YVector(Cross product of Xvector and Zvector)
and it's position
You can create a transformation matrix (xvector,yvector,zvector,position). use that as your model matrix to position your cube.
06-24-2010, 12:11 PM
thanks a lot.
but as i said i'm beginner and i don't know how i can create that matrixes, cross product them, create tranformation matrix and use it as a model matrix :( :(
my program is big itself and i can't start to calculate cross matrixes with c++ in order to draw that cube.
is there any way opengl do all that and i just give to it vector of direction and up vector?
if any one can please post an opengl code which for example draw a cube in direction of (1,1,1).
thanks in advance
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.