Solved

rotation angles

Posted on 2006-10-28
1
232 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Questions about virtual reality solution 8 323
old35  java challenge 4 137
Any decent scenery blocks for my RTS 6 90
What are programming codes and how do they work? 7 103
What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

828 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