Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

rotation angles

Posted on 2006-10-28
1
Medium Priority
?
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 84

Accepted Solution

by:
ozo earned 750 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

618 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