gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > model position function?

#57157 - chrissieboy - Thu Oct 13, 2005 11:45 pm

Im busy with making a chase cam, so i got a vehicle and the camera must chase the object. So the perspective is 3rd person.

But now i must know the x,y,z position of my vehicle, is there some function in ndslib or something? Wich knows the place of the mesh?

Because gltranslate places my mesh but don't knows the place after a few moves.

I saw some documentation about popmatrix and pushmatrix but i realy don't understand where this is usefull for??

I looked myself in opengl.c but can't find a function or something to read out object positions.

Thanx!

#57362 - dXtr - Sat Oct 15, 2005 7:07 am

first of all.. you really should read some linear algebra :)
and second of all.. I'm not an OpenGL guy.. so this can be wrong

in a column based 4x4 matrix it looks like this:
1, 0, 0, 0
0, 1, 0, 0
0, 0, 1, 0
X, Y, Z, 1

and in a row based 4x4 matrix it looks like this:
1, 0, 0, X,
0, 1, 0, Y,
0, 0, 1, Z,
0, 0, 0, 1

to retrive the model-view matrix:
float fModelView[16];
glGetFloatv(GL_MODELVIEW_MATRIX, fModelView);

edit: changed some of my post.. b\c I'm kind of tired and not really sure what I'm writing ;D
think it's time to get some sleep..

#57407 - dovoto - Sat Oct 15, 2005 5:20 pm

Sorry no glGetxxx functions implemented in libnds at the momen.
_________________
www.drunkencoders.com

#57472 - dXtr - Sun Oct 16, 2005 8:35 am

now when I had some sleep..
don't you save the position for the mesh somewhere? if not you really should.. this is something normal is all (or atleast most) to save position and rotation (saved as a matrix or using vectors).

so if you do have this saved you should just let the camera ask the object it is following, what the position of the object is.

#57860 - discoloda - Tue Oct 18, 2005 10:33 pm

vec3 origin; // viewer origin
vec3 travel; // directional vector for the way the viewer is going

vec3 camera; // resulting camera position

camera = origin - (travel*cameradistance) + cameraoffset;

after that just do a glTranslatef(-camera[0], -camera[1], -camera[2]);