* FAQ    * Search  * Register * Login 
Active topics
Unanswered topics

All times are UTC-06:00



Post new topic  Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Need help on OpenGL projection stuff
PostPosted: Mon Mar 27, 2006 2:40 pm 
Offline
D2X Master
D2X Master
User avatar

Joined: Thu Nov 05, 1998 12:01 pm
Posts: 5278
Website: http://www.descent2.de
Given:

- viewer position vp (vector)
- viewer orientation vo (matrix)
- model position mp (vector)
- model orientation mo (matrix)

How do I have to manipulate the modelview matrix so that the model is properly rendered?

I had thought

glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glMultMatrixf (vo);
glTranslatef (vp);
glMultMatrixf (mo);
glTranslatef (mp);

would do the trick; but neither this nor any permutation does. I have read tutorials and the redbook about this, but to no avail. :(

I had also tried

glMultMatrixf (mo); //rotate the model first
glTranslatef (vo - mo); //move to offset distance from viewer pos; tried vo + mo too
glMultMatrixf (mo); //rotate the entire scene depending on viewer orientation


Top
   
 Post subject:
PostPosted: Mon Mar 27, 2006 9:18 pm 
Offline
DBB Benefactor
DBB Benefactor
User avatar

Joined: Sun Jun 03, 2001 2:01 am
Posts: 935
Location: Illinois
Here's what I did to setup the view of a model in OOF Editor...

Code:
 Call glMatrixMode(mmModelView)
 Call glLoadIdentity
 Call glTranslatef(0!, 0!, -1!)
 ' Move to starting position, rotation to draw model
 Call glTranslatef(rXaxisPan, rYaxisPan, rZoom)
 Call glRotatef(rYaxis, 1!, 0!, 0!)
 Call glRotatef(rXaxis, 0!, 1!, 0!)


This didn't use matrix's however in setting up the viewpoint so I'm not sure how applicable you'll find this, but at least you can see that...

1. Selected the modelview matrix
2. Loaded the identity matrix into it
3. Translated out from that position -1 in the Z axis
4. Translated out the X,Y and zoom level
5. Rotated about Y axis, then X axis

From what I understand, OpenGL uses matrix's behind the scenes when Translate and Rotate functions are used. Perhaps you can attempt doing discreet matrix multiplications in this order and at least have a starting point.

Wish I could be more help on the matrix stuff but it's been many years since I have worked with them.


Top
   
 Post subject:
PostPosted: Mon Mar 27, 2006 9:22 pm 
Offline
DBB Benefactor
DBB Benefactor
User avatar

Joined: Sun Jun 03, 2001 2:01 am
Posts: 935
Location: Illinois
Almost forgot, great site that you probably already know about, for tutorials on OpenGL...

http://nehe.gamedev.net/

and...

http://www.flipcode.com/documents/matrfaq.html


Top
   
 Post subject:
PostPosted: Tue Mar 28, 2006 3:24 am 
Offline
D2X Master
D2X Master
User avatar

Joined: Thu Nov 05, 1998 12:01 pm
Posts: 5278
Website: http://www.descent2.de
Thx. I figured a few things, but still cannot render an object in the proper location.

The Nehe tuts plain suck, imho. Lots and lots of text (blah blah blah), lots of code around what you really want to know, and sucky explanations. The OpenGL Redbook is far better.

One problem I had to figure was that the matrixes in D2 had a different ordering from the OpenGL ones (apart from OpenGL being column major matrixes).

I am still having issues with lateral distortions when banking, and control direction reversing when being upside down, all related to matrix handling by D2. Ack.

Actually the first problem I wanted to solve was to render the Pyro in-game from external view, i.e. I am having Pyro position and orientation, and viewer position and orientation (which happens to be the Pyro pos/orient from a few frames before).

So what I need to do is to rotate the Pyro according to its orientation, move it out (glTranslate) from the view point (delta of Pyro and viewer) pos, and rotate the entire thing according to viewer orientation. But I always end up with the Pyro being far out.

In case you have too much time, I could tell you where to look in the D2X-XL code for that, and how to enable it (simple command line switch and a few code lines in main/oof.c::OOF_RenderObject() :mrgreen: ).


Top
   
 Post subject:
PostPosted: Tue Mar 28, 2006 1:06 pm 
Offline
DBB Ace
DBB Ace
User avatar

Joined: Tue Jan 10, 2006 5:15 pm
Posts: 73
Website: http://www.viscerallogic.com
AOL: eMacPaul
Location: Ann Arbor, MI, USA
It probably depends how your orientation matrices are defined...

In Event Horizon, I use position as <x, y, z>, and then orientation in terms of angles around the axes. Here's the code I use:

glLoadIdentity();
glRotatef( -sys->pitch, 1, 0, 0 );
glRotatef( -sys->roll, 0, 0, 1 );
glRotatef( -sys->angle, 0, 1, 0 ); // sys angle
glTranslatef( x - sys->x, y - sys->y, sys->z - z ); // position self
glRotatef( angle, 0, 1, 0 ); // rotate to own angle
glRotatef( roll, 0, 0, 1 );
glRotatef( pitch, 1, 0, 0 );

where \"sys\" is the player. But my axes are also defined kind of funny (left-handed), as you can see I have x-sys->x, y-sys->y, but then sys->z-z.

_________________
Differentiation is an integral part of calculus.


Top
   
 Post subject:
PostPosted: Wed Mar 29, 2006 7:20 am 
Offline
D2X Master
D2X Master
User avatar

Joined: Thu Nov 05, 1998 12:01 pm
Posts: 5278
Website: http://www.descent2.de
Paul, I want to utilize the matrices already present in D2, or I would need to rewrite a real lot of stuff.

Currently I am simply trying to render the mine (not any objects) using the driver transformations:

float fZoom = ((float) viewInfo.zoom) / 65536.0f;
glMatrixMode (GL_MODELVIEW);
glPushMatrix ();
glLoadIdentity ();
glScalef (1.0f, 1.0f, -fZoom); //scale the coordinates
glMultMatrixf (viewInfo.glViewf); //rotate view
glTranslatef (viewInfo.glPosf [0], viewInfo.glPosf [1], -viewInfo.glPosf [2]); //offset view point

//viewInfo.glViewf is the orientation matrix
//viewInfo.glPosf is the position vector
//fZoom holds the zoom factor scaled from D2's coordinate system (everything * 65536) to an OpenGL conformant one

I am pretty close, but strangely enough my call to glTranslate offsets the view position a little too much. Weird.

Edit:

I have it: I have to put all position offsets negative, not just z:

glTranslatef (-viewInfo.glPosf [0], -viewInfo.glPosf [1], -viewInfo.glPosf [2]);


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 6 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Descent'rs have piloted these pages
 
The layout and contents contained within this site are © DescentBB.net 1997-2006.
Descent, Descent II are © Parallax Software Corporation.
Descent III is Outrage Entertainment.
Descent is a Trademark of Interplay Productions.

Miner Wars™ is trademark of Keen Software House s. r. o.
.


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group