#### Archived

This topic is now archived and is closed to further replies.

# How to rotate without glRotate() ?

This topic is 5889 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Thats it! How to rotate a shape/poly without using glRotate() given the X, Y and Z coords for all the shape/poly''s vertices? I need to know the resulting vertices'' coordinates instead of drawing them... need to store them. How do I do this? Thank you guys! See you!

##### Share on other sites
That''s like saying..
"I want to drink water without water!"
OR
"I want to breath, but without air!"

UNLESS.. U use GLULookat

Don''t forget to include "glu.h"

void gluLookAt(GLdouble eyex,GLdouble eyey,GLdouble eyez,
GLdouble centerx,GLdouble centery,GLdouble centerz,
GLdouble upx,GLdouble upy,GLdouble upz);

eye = Where the camera is
center = what ya lookin'' at
up = rotation axis... typical values = 0,1,0

##### Share on other sites
quote:
Original post by TerraX
That's like saying..
"I want to drink water without water!"
OR
"I want to breath, but without air!"

UNLESS.. U use GLULookat

Don't forget to include "glu.h"

void gluLookAt(GLdouble eyex,GLdouble eyey,GLdouble eyez,
GLdouble centerx,GLdouble centery,GLdouble centerz,
GLdouble upx,GLdouble upy,GLdouble upz);

eye = Where the camera is
center = what ya lookin' at
up = rotation axis... typical values = 0,1,0

well.. why do i need opengl to rotate?

he asks for the math, because he has to calculate it for himself..

my suggestion (as i don't have the code around currently):
type glRotatef source code MESA in google.. and.. well.. take a look around hope you find it..

"take a look around" - limp bizkit

[edited by - davepermen on May 1, 2002 7:26:15 AM]

##### Share on other sites
I do a bit of software transform in my LOTR demo. I''m afraid the code''s horrible, but here it is:

  if (vertices[initialVertex + 2] != 0)	radialAngle = atan(vertices[initialVertex] / vertices[initialVertex + 2]);else if (vertices[initialVertex] < 0)	radialAngle = (3 * PI) / 2;else	radialAngle = (PI / 2);if (vertices[initialVertex + 2] < 0)	radialAngle += PI;radialAngle += yRotation;pointDistance = sqrt((vertices[initialVertex] * vertices[initialVertex]) + (vertices[initialVertex + 2] * vertices[initialVertex + 2]));xCoordinate = pointDistance * sin(radialAngle);zCoordinate = pointDistance * cos(radialAngle);if (vertices[initialVertex + 1] != 0)	elevationAngle = atan(zCoordinate / vertices[initialVertex + 1]);else if (zCoordinate < 0)	elevationAngle = (3 * PI) / 2;else	elevationAngle = (PI / 2);if (vertices[initialVertex + 1] < 0)	elevationAngle += PI;elevationAngle += xRotation;pointDistance = sqrt((vertices[initialVertex + 1] * vertices[initialVertex + 1]) + (zCoordinate * zCoordinate));yCoordinate = pointDistance * cos(elevationAngle);zCoordinate = pointDistance * sin(elevationAngle);

Note - this does a rotate about the y-axis, then a rotate about the x-axis - order IS important.

Sorry that the code isn''t commented - if you can''t understand it & are willing to wait a few days (''til I''ve finished the latest batch of coursework!) then i''ll try and explain it better.

Enigma
------
... We do much, much more harm than good. ...

##### Share on other sites
Whoops, err, is it better to post a reply, look stoopid and hope that the person asking the question is a newbie (like me)
Or better to just say nuffin?
*blush*

##### Share on other sites
That depends on how bad you feel about making an a out of yourself

- An eye for an eye will make the world go blind -

##### Share on other sites
Eugh - you''re right that code is hideous!

And cmon guys, you can''t send this programmer on a wild goose chase though the mesa source code - that library is huge!! Besides, what this guy wants to know is common knowledge...

Ah - errr... Ok go look at the maths library I posted on my website (Link at end of post), it''s in the downloads section (Sorry for not posting the code). If you have any questions, please post them on my forum so that the information is documented.

The basic idea is this - change to modelview matrix (if you''re currently in worldview), create your own matrix, perform rotate function on matrix, upload the matrix to opengl, draw verts as usual. Et voila

BTW: " That''s like saying..
"I want to drink water without water!"
OR
"I want to breath, but without air!"

UNLESS.. U use GLULookat" - Please refrain from misinforming other programmers as that golden nugget of knowledge is complete rubbish If you dont know the answer to the question posed then please keep shtum because it just confuses the newbies.

A couple of interesting notes:
1) gluLookAt is a very useful function but I have heard word that it is quite a slow function and should be avoided if possible. Feel free to investigate this if you have overlooked it in the past.
2) Writing your own version of glRotate is all well and good, but you will find that the boys at SGI (Microsoft?) are quite smart (Microsoft is excluded from that statement) and actually optimised this function quite well and it is not necessary to write your own glRotate function because in one way or another it is working in exactly the same way.
3) Programmers most often write their own maths routines when it becomes a necessity - why reinvent the wheel without good reason? For example, DX8 and OpenGL work differently, so a maths library which can do it independantly of the API is therefore useful.

Hope that helps!

-------- E y e .Scream Software --------
----------------------------------------
/-\
http://www.eyescream.cjb.net | * |
\-/
----------------------------------------

##### Share on other sites
Ok guys,

First off, let me thank you for the replies!

I''ll try to explain myself. What i''m trying to do is calculate the vertices of all objects in my world. My program is loading the objects'' information from a file, but it don''t know the vertices coordinates, the file just tells the object''s center coordinates, the type of object and it''s size.

But, to do collision, I need the objects'' vertices... I know how to cauculate the vertices for objects that are orthogonal to the X, Y ans Z axis... but, when the world information file tells to the program that the object is to be rotated in a given angle, the program need to rotate the collision area''s vertices too... thats why I need to cauculate the rotation by myself... or I need some kind of glRotate() function that return the result vertices to me... I just need to store the result vertices after rotation into an array to pass them to the collision function.

Any idea?

Thank you guys!... And sorry about my English errors!

See you!

##### Share on other sites
I read in the OpenGL docs that you can actually return transformed vertexed. I''m not sure how it works though (and I dont have the docs here in my office so I can''t look it up for you).

- An eye for an eye will make the world go blind -

##### Share on other sites
Up!

Please... someone who could point me to a site, text or something?

Thanks!

1. 1
2. 2
3. 3
4. 4
Rutin
18
5. 5

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631415
• Total Posts
2999964
×