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 > 3D Camera??

#88304 - dexter0 - Sun Jun 18, 2006 5:52 pm

I have been using 3d programs for a while now and decided to try programming 3D on the DS. I am using a combination of PA_LIB and libnds in my code. All the objects seem to position correctly but when I set my camera/perspective to 1.0,0.0,1.5,0.0,0.0,0.0 the camera does not seem to be moving ONLY on the x-axis. It appears to be orbiting around the center. Changing the Y position does the same except it orbits vertically. The Z position behaves correctly except that when Z hits a negative value the camera rotates 180. Is this standard 3D behavior or am I not doing something right?

Code:
#include <PA9.h>
int main()
{
float x=1.0;
float y=0.0;
float z=1.5;
float rx=0.0;
PA_Init();
PA_InitVBL();
PA_InitText(1,0);
PA_SetTextCol(1,31,31,31);
PA_Init3D();//init the 3d
PA_Init3DDrawing(1.0,0.0,1.5,0.0,0.0,0.0);//eyex, eyey, eyez
while(1)
{
PA_OutputText(1,0,0,"PosX: %f", x);
PA_OutputText(1,0,1,"PosY: %f", y);
PA_OutputText(1,0,2,"PosZ: %f", z);
PA_OutputText(1,0,3,"RotX: %f", rx);
if(Pad.Held.Left) {
x=x-0.05; }
if(Pad.Held.Right) {
x=x+0.05; }
if(Pad.Held.Up) {
y=y-0.05; }
if(Pad.Held.Down) {
y=y+0.05; }
if(Pad.Held.X) {
z=z-0.05; }
if(Pad.Held.Y) {
z=z+0.05; }
if(Pad.Held.L) {
rx=rx-0.05; }
if(Pad.Held.R) {
rx=rx+0.05; }
if(Pad.Held.A) {
x=0.0;
y=0.0;
z=1.0;
rx=0.0; }
gluLookAt(x,y,z,rx,0.0,0.0,0.0,0.1,0.0);
glPushMatrix();
PA_3DBox(0.0,0.0,0.0,0.5,0.5,0.5,0.0,0.0,0.0,255,255,255);//color
PA_3DBox(0.0,0.0,0.0,2.0,0.1,0.1,0.0,0.0,0.0,0,255,0);//color
PA_3DBox(0.0,0.0,0.0,0.1,2.0,0.1,0.0,0.0,0.0,0,0,255);//color
PA_3DBox(0.0,0.0,0.0,0.1,0.1,2.0,0.0,0.0,0.0,255,0,0);//color
glPopMatrix(1);
glFlush();//show
}

return 0;
}

#88316 - ProblemBaby - Sun Jun 18, 2006 7:13 pm

I just skim through the post but I think you have misunderstood the behaviour of LookAt, first comes the position of the "eye" then the point to look at, and last which direction is up. So when you change the position of the eye (without changing the "look at"-point) it will still look at the same point just move the eye or camera.

I Hope this helped

#88320 - silent_code - Sun Jun 18, 2006 7:32 pm

in other words: first rotate the camera, then translate it... though this is just said the simple way ;)

what you have now is a camera orbiting around a point. such a camera model is good for modeling and third person perspectives. but for flyby cams and ego views this is not useful.

ps: didn't read your code...