Link to home
Start Free TrialLog in
Avatar of vadim85
vadim85

asked on

rotation angles

I have two lines:
1) First one is drawn somewhere line in 3d space.  I know coordinates of this line.
2) Second line is a vertical line starts in center of the coordinate system (0,0,0) .

I need to move the second line from 0,0,0 to the exact position of the first line in the 3D space, I have to use gltranslate and glrotate functions.

I'm using OpenGL + VB

Can you please help me to find what is wrong with my code? It doesn't draw the line in the right position


Public Sub CalculateRotAngles(x1 As Single, y1 As Single, z1 As Single, _
                              x2 As Single, y2 As Single, z2 As Single, _
                              rX As Single, rZ As Single, rY As Single, length As Single)
             
                       
Dim P1 As tPoint, P2 As tPoint, P3 As tPoint
Dim L1 As Single
Dim L2 As Single
Dim LineSlope As Single
Dim dx As Single, dZ As Single, dy As Single
Dim P2P3 As Single, LineLen As Single
                       
    P1.X = x1
    P1.Y = y1
    P1.z = z1

    P2.X = x2
    P2.Y = y2
    P2.z = z2

   
    'L1 = Sqr((P1.X - P2.X) ^ 2 + (P1.z - P2.z) ^ 2)
    'length = L1
   
    dx = Abs(P1.X - P2.X)
    dy = Abs(P1.Y - P2.Y)
    dZ = Abs(P1.z - P2.z)
   
    L1 = Sqr(dx * dx + dy * dy + dZ * dZ)
    length = L1

    rX = RadToDegf(ArcCos(dx / L1))
    rZ = RadToDegf(ArcCos(dZ / L1))
    rY = RadToDegf(ArcCos(dy / L1))
End Sub



'Draw

glPushMatrix


glTranslatef begX, begY, begZ
glRotatef rX, 1, 0, 0
'glRotatef rY, 0, 1, 0
glRotatef rZ, 0, 0, 1

glColor3f 1, 1, 0
DrawLineCoordinate 0, 0, 0, _
                              0, length, 0
glPopMatrix


Thank you.
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial