Solved

rotation angles

Posted on 2006-10-28
1
226 Views
Last Modified: 2013-12-26
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.
0
Comment
Question by:vadim85
1 Comment
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
ID: 17827940
2) Second line is a vertical line starts in center of the coordinate system (0,0,0) .
does this mean from (0,0,0) to (0,0,1)?
   
    dx = P1.X - P2.X
    dy = P1.Y - P2.Y
    dZ = P1.z - P2.z
     
     vx = 0-0
     vy = 0-0
     vz = 1-0
 

     cx = vy*dz-dy-vz
     cy = vz*dx-dz*vx
     cz = vx*dy-dy*vx

    r = atan2(sqrt(cx*cx+cy*cy+cz*cz)/(dx*cx+dy*cy+dz*cz)
End Sub


glRotatef r, cx, cy, cz
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now