?
Solved

openGL vector math problem in C++

Posted on 2005-03-01
1
Medium Priority
?
2,222 Views
Last Modified: 2008-02-26
I am writing a graphics  program in C++ utilizing openGL.  It is the typical "solar system" exercise where I have a central object (the sun) rotating on its axis and 2 planets orbiting the sun rotating on their axis'.  The viewer (camera) is on a satellite that is in the outermost orbit of the solar system so that all objects are visible at the same time.  The satellite can move either direction in its orbit. (orbit to the right, orbit to the left).  The satellite can rotate on its own axis while always facing the sun.  In other words the "up" direction can change simultaneously while orbiting the sun.  How do I calculate the vector for the "UP" position given an angle of rotation and the current x, y coordinates.  Specifically, how do I calculate the z coordinate with respect to x, y, theta?   ("up" is defined as the reference vector in which you perceive "up" to be.  If  I tilt my head 45 degrees to the right, up for me would be the vector (1, 1))
For Example:

Satelite is located at (0, 0, 1) facing the origin.  The normal up vector would be (0, 1, 0)(WRT the origin translated to the satellite) or (cos(theta)*r, sin(theta)*r, 0.0). If I rotate the "up" position by 45 degrees (rotate the satellite axis by 45 degrees) this formula works fine as long as I'm stationary at location (0, 0, 1).  If I move the satellite to position (cos(60), 0.0, sin(60)) in the satellite orbit and I want to rotate the satellite on its axis by 45 degrees (while always facing the origin), the z coordinate changes also.  How do I calculate the (x, y, z) coordinates for my up position as I orbit about the origin on the plane x = 0??  
0
Comment
Question by:VBStudent
[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 1

Accepted Solution

by:
anpluto earned 2000 total points
ID: 13441213
Your making this much harder then it should be.

What you really want to do is change the order of translation/rotation.

glPushMatrix();
position();

glPushMatrix();
  glRotatef(rotate, 0.0f, 1.0f, 0.0f);
glPopMatrix();

glRotatef(45.0f, 0.0f, 0.0f, 1.0f);

drawmodel();
glPopMatrix();
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses

752 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