Solved

rotation angles

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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 tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

815 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

8 Experts available now in Live!

Get 1:1 Help Now