Advertisement

moving a vertex using rotation from a point

Started by March 28, 2001 05:52 AM
8 comments, last by redmonkey 23 years, 7 months ago
that sounds odd, but the kinda thing i need to do is move a point at say 20,13,10 around the point 0,0,0, by specified angles on the Z and X axis someone mentioned matricies once, but i havent found any good tutorials on it... __________________ graham "red" reeves. red@deadpenguin.org www.deadpenguin.org
__________________graham "red" reeves.[email=red@deadpenguin.org]red@deadpenguin.org[/email]www.deadpenguin.org
On the web i suppose u should search it were thi s is used.

Why u don''t see in the opengl specifications?

www.opengl.org

u should download the bluebook... I.e the opengl specification 1.2 or may be also the redbook (The opengl manual) .

u have to know a bit of trigonometry to do this... (sin, cos, ...)

matrix is only a way to make in a standard way every kind of linear trasfomation: rotation, translation, scaling, ...

i can''t tell u were u can search it... i learn it at my school!
I''m sorry. Now i''m not souch time to explain it.
Advertisement
essentially i just want glrotatef() but i need to store the new coordinates...


Edited by - redmonkey on March 28, 2001 7:25:30 AM
__________________graham "red" reeves.[email=red@deadpenguin.org]red@deadpenguin.org[/email]www.deadpenguin.org
ive been reading ogl superbible for 2 days now, on page 140 or something and it tells you how to rotate polygons. heres some code that i use, dont know if it will be very helpful though

// The rotation amounts
static GLfloat xRot = 0.0f;
static GLfloat yRot = 0.0f;

// save matrix state and do the rotation
glPushMatrix();
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
glRotatef(yRot, 0.0f, 1.0f, 0.0f);

// Begin the scene (this rotates a cone along the circle of a triangle fan)
// do rotation
for(angle = 0.0f; angle < (2.0f*GL_PI); angle += (GL_PI/8.0f))
{
// Calcuate x and y postion of the next vertex
x = 50.0f*sin(angle);
y = 50.0f*cos(angle);

// you probably get the point hope that helped a little
bad!

redmonkey wrote: "essentially i just want glrotatef() but i need to store the new coordinates... "

What do you mean you want to store the new coordinates?

To rotate a point in space around the origin you must first perform the translation of the point then a rotation. For example, if you want have a point at (0, 0, 10 ) and you want to rotate it about the x axis by 45 degrees:

glLoadIdentity()
glRotatef(45, 1, 0, 0 );
glTranslatef(0, 0, 10);

I hope this helps.
Guy
no offense, i know how to transform and rotate, hence the fact i know i want to store my results

right, i have a [poled]sphere forming a planet. it''s center is at 0,0,0 and has an effective radius of 1.

i cant use the same algorithm/formula i use to generate the points on the sphere for determining a new position of said object.

now, i have my objects''s position (say -1.2,-1,0.1) and i need to "rotate" it *around* my sphere. theres probably a very long and complex way of wrking out the new position when (imagine this in your head) i rotate the position[of the object] around the edge of my sphere, by a certain amount (only using the Z and X axis'')

now, glrotatef() produces the desired effect yes. but, i cant then use my drawn position to work out collision,spawning etc. instead, i need to use the same sort of code that glrotate() does, rotating on a point (0,0,0, the centre of the planet in this case)

for example, if my 3D coords we''re -1,0,0 (far left-viewwise- of the sphere) and i wanted to rotate it on the Z-axis (thats the one going from top to bottom, spinning the world around if you cant imagine it :]) 45 degress, the point would now be in front of you at [estimation] 0,0,-1

now, i dont know how to do that in numerical form, because if i wanted to draw that opengl does it for me.

now, my orignal point was, someone said once that matricies might perform this action, although i dont know how flexible or easy that might be

a simple formula would be much appriciated too, dont hesistate to go into too much depth, [no offense but] im not a newbie


__________________
graham "red" reeves.

red@deadpenguin.org
www.deadpenguin.org
__________________graham "red" reeves.[email=red@deadpenguin.org]red@deadpenguin.org[/email]www.deadpenguin.org
Advertisement
Hi,

I''m not 100% sure about this (I try to avoid touching matrices!), but I''m fairly certain that you want to do this -

Get the current matrix for your scene, after applying any rotations, translations, scaleings, etc. with

double matrix[16];
glGetdoublev(GL_MODELVIEW_MATRIX, matrix);

matrix now contains all 16 values from the current matrix.

Then, for each point that you want to find it''s final position, multiply it by this matrix. If all goes well, you should have the point you are looking for.

I hope this works, but bear in mind that if it does, it''s probably not hardware T&L friendly.

Dan

Dan

I''m pretty sure that what you want is glPushMatrix and glPopMatrix. After drawing the sphere, call glPushMatrix(), then glLoadIdentity(), and then move to the coordinates of your moon (or whatever). When you''re done drawing the moon (whatever), call glPopMatrix and the old coordinate state will be restored (I hope).
danbrown: this looks prety damn good, but going through me debugger i cant work out what all the values are :/

have you got a reference somewhere? (i just need the new x/y/z coord of the "pen" or whatevre they call it :] -it was a pen in the LOGO days )

tsuraan: i cant stress this enough, i need to work out a new position, not position something!

__________________
graham "red" reeves.

red@deadpenguin.org
www.deadpenguin.org
__________________graham "red" reeves.[email=red@deadpenguin.org]red@deadpenguin.org[/email]www.deadpenguin.org
Try this:

procedure RotateX(ang : Single; var dest : TVector);var  y0, z0 : Single;  radAng : Single;begin  y0 := dest[1];  z0 := dest[2];  radAng := DegToRad(ang);  dest[1] := (y0 * cos(radAng)) - (z0 * sin(radAng));  dest[2] := (y0 * sin(radAng)) + (z0 * cos(radAng));end;procedure RotateY(ang : Single; var dest : TVector);var  x0, z0 : Single;  radAng : Single;begin  x0 := dest[0];  z0 := dest[2];  radAng := DegToRad(ang);  dest[0] := (x0 * cos(radAng)) + (z0 * sin(radAng));  dest[2] := (z0 * cos(radAng)) - (x0 * sin(radAng));end;procedure RotateZ(ang : Single; var dest : TVector);var  x0, y0 : Single;  radAng : Single;begin  x0 := dest[0];  y0 := dest[1];  radAng := DegToRad(ang);  dest[0] := (x0 * cos(radAng)) - (y0 * sin(radAng));  dest[1] := (y0 * cos(radAng)) + (x0 * sin(radAng));end; 


---
I write code.
DelphiGL (http://delphigl.cfxweb.net)
---I write code.DelphiGL (http://delphigl.cfxweb.net)

This topic is closed to new replies.

Advertisement