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 > ds fps or 3ps camera?

#176797 - t377y000 - Fri Oct 14, 2011 6:08 am

hi was just wondering if anyone knew how to put a fps camera together in opengl/c.

iv tried kinda got it working, but cant seem to figure it out.
useing the example code from example>nds>graphics>3d>boxtest.
exactly how the camera works in ds fps games like call of duty or metroid.

exactly like this.
http://www.youtube.com/watch?v=BY7BVAYjSUo

anyone help?

#176888 - keldon - Sat Oct 15, 2011 5:45 pm

Well I had a look at the video on your site and you seem to have it moving around. What exactly are you having troubles with?

#176903 - t377y000 - Sun Oct 16, 2011 8:03 pm

keldon wrote:
Well I had a look at the video on your site and you seem to have it moving around. What exactly are you having troubles with?


sorry if it took long to reply, but actually on that video im using nitro engine.
this:
http://antoniond.drunkencoders.com/nitroengine.html

but now im wanting to use stright libnds with open gl & c.

also that video you see on my page the camera is moved & rotated with the dpad not touch screen.
_________________
https://sites.google.com/site/t3gameszero/Home

#176904 - keldon - Sun Oct 16, 2011 11:17 pm

Well the stylus input is easy; write some code that makes sense of the stylus input to detect x/y plane movement ... convert that into an angle to rotate or a distance to move, apply that to the appropriate matrices.

In writing this response I made some initial assumptions based on what I got from your query (please don't be offended if that is not the case, I'm not too sure so feel free to correct me ^_^):
- This is your first 3d engine and will be stepping in some fairly new territory
- Some areas will be quite foreign, so you'll have to learn a few concepts such as frustum culling, back face elimination and lighting equations etc, due to the engine usually taking care of that

As for moving from NitroEngine to libogc; you will have to write the model struct/classes yourself, etc. Thankfully the OpenGL Redbook explains plenty of 3d concepts, such as Chapter 3 (viewing) where it explains the different matrix transformations that go on in modelling, and also hierarchical modelling (though it may use a different name for it).

So if this is your first 3d engine (as I presume) then creating a framework whereby you can write the type of code below will tell you just about everything you need to know about how to achieve what you are after.
Code:
// Note: every 'Object' has the following matrices:
// - Local matrix, changed rarely
// - Current matrix, regularly changed
// - Operation matrix, applied to Current matrix whenever default operation is called,
//   this can be used to create objects that constantly rotate around it's axis or something
// ... The operation matrix is really there to illustrate this example

// Create a 3d box that can fit inside of a unit length circle
Object* Create3dBox()
{
   // Vertice units so that square fits inside a unit length circle
   Fixed32 a(Fixed32(2).SquareRoot());

   int vertexCount = 8;
   Vertex *vertices = new Vertex[vertexCount];
   vertices[0] = Vertex(a, a, a);
   vertices[1] = Vertex(a, a, -a);
   vertices[2] = Vertex(a, -a, -a);
   // ... and so on

   int faceCount = 6;
   Face *faces = new Face[faceCount];
   int *indexArray;
   int faceIndexCount = 4;
   // Face 0 (east)
      indexArray = new int[faceIndexCount];
      indexArray[0] = 0;
      indexArray[1] = 1;
      indexArray[2] = 2;
      indexArray[3] = 3;
      faces[0] = Face(vertices, indexArray, faceIndexCount);
   // Face 1 (front)
      indexArray = new int[faceIndexCount];
      indexArray[0] = 4;
      indexArray[1] = 0;
      indexArray[2] = 3;
      indexArray[3] = 7;
   // ... and so on

   return new Object(vertices, vertexCount, faces, faceCount);
      
} // Create3dBox


// Creates a model of our solar system, fitting inside of a unit
// length circle (with planets being represented by cubes)
// The moon will circle the Earth
Model* CreateSolarSystem()
{
   int objectCount = 9; // Sun, 8 (real planets that does not include pluto)

   // filled with objectCount+1(with the moon's data being the last element).
   Fixed32 solarSystemObjectSizes[] = { /* Array filled with valid data */};
   Fixed32 distanceFromSun[] = { /*Array filled with valid data */};
   Fixed32 orbitRotation[] = { /*Array filled with valid data */};
   


   Model *models = new Model[objectCount];

   // Moon will orbit the Earth
   Model *moon = new Model[1];

   for(int i = 0; i < objectCount+1; ++i)
   {
      // Note that the moon is object 9 and will orbit the Earth, which will be later reflected in the model created
      Matrix local;
      local.setToIdentity();
      // Is moon object ?
      if( i == 9 )
      {
         // Descale size of Earth for the moon, since the moon's operations will occur after the Earth
         local.scale(Fixed32(1) / Fixed32(solarSystemObjectSizes[3]));
      }
      local.translate(distanceFromSun[i], 0, 0);
      local.scale(solarSystemObjectSizes[i]);

      // Operation matrix that will make the object orbit
      Matrix operation;
      operation.setToIdentity();
      operation.rotateY(orbitRotation)

      Matrix current;
      current.setToIdentity();

      Object *object = Create3dBox();

      Model *childModel = null;
      int childModelCount = 0;

      // Is earth object ?
      if( i == 3 )
      {
         childModel = moon;
         childModelCount = 1;
      }
      Model *model = new Model(object, local, current, operation,
         childModel, childModelCount);
   }

   Matrix identity;
   matrix.setToIdentity();

   Object *nullObject = null;
   Model *solarSystem = new Model(nullObject, identity, identity, identity,
      models, objectCount+1);
   return solarSystem;
}


Also you can draw from the NitroEngine code, though much of what is important to learn (I believe) often comes from the experience of just coding it.

And it would be very helpful to know what stage you're at and the sort of experience you have in order to better provide you with the right knowledge or questions for your query as I've been quite presumptuous in my response, and I do see you've done quite a bit of 3d work on the ds. You do seem to be making plenty of progress so I'm really looking forward to your work!


Happy coding.

#176907 - t377y000 - Mon Oct 17, 2011 9:14 pm

keldon wrote:
Well the stylus input is easy; write some code that makes sense of the stylus input to detect x/y plane movement ... convert that into an angle to rotate or a distance to move, apply that to the appropriate matrices.

In writing this response I made some initial assumptions based on what I got from your query (please don't be offended if that is not the case, I'm not too sure so feel free to correct me ^_^):
- This is your first 3d engine and will be stepping in some fairly new territory
- Some areas will be quite foreign, so you'll have to learn a few concepts such as frustum culling, back face elimination and lighting equations etc, due to the engine usually taking care of that

As for moving from NitroEngine to libogc; you will have to write the model struct/classes yourself, etc. Thankfully the OpenGL Redbook explains plenty of 3d concepts, such as Chapter 3 (viewing) where it explains the different matrix transformations that go on in modelling, and also hierarchical modelling (though it may use a different name for it).



Also you can draw from the NitroEngine code, though much of what is important to learn (I believe) often comes from the experience of just coding it.

And it would be very helpful to know what stage you're at and the sort of experience you have in order to better provide you with the right knowledge or questions for your query as I've been quite presumptuous in my response, and I do see you've done quite a bit of 3d work on the ds. You do seem to be making plenty of progress so I'm really looking forward to your work!


Happy coding.



my 1st 3d engine? ^.^
well sorta, i worked in open gl before & direct x/dark gdk, that was years ago & sorta just did some practice stuff.
never started getting into open gl until now. started using nitro engine my sophomore year, which was like 3 or 4 years ago. learned everything on my own tho. also learned o use blender very well i use it for modeling & animation.
my 1st project in nitro engine was gta 3 ds.
below is 1st vid of like 6 vids showing different progress learning to use nitro engine.
http://www.youtube.com/watch?v=KzF6ngBxloc
demo here:
https://sites.google.com/site/t3gameszero/downloads/ds-games/gta_3_ds

then some other practice projects(like loading sonic models & stuff like that.)
then i cancelled gta 3 ds to start on sandbox engine ds-dsi. which is my main project now. planning on making into a huge game when i get this basic sandbox game camera & open gl/c thing down lol.

some areas will be foreign? yes possible, im a fast learner tho, in nitro engine i did some culling back & front stuff like that, & in libnds i learned to change drawing distance, which i couldn't find out to do on nitro engine lol. gluprospective();

& thanks for you're time
can i email you to show you the current source codes & compiled versions i have been trying?
_________________
https://sites.google.com/site/t3gameszero/Home

#176912 - keldon - Tue Oct 18, 2011 10:40 pm

Well why not make them public on something like Github or mediafire for all to see? If not I can pm my email and have a look at it some time.

#176936 - t377y000 - Sun Oct 30, 2011 3:26 am

keldon wrote:
Well why not make them public on something like Github or mediafire for all to see? If not I can pm my email and have a look at it some time.


sorry took so long to reply been busy trying to work on this & stuff. but check this out.

ok this is what im useing.

actually i tried this. its in open gl

Code:
(this parts up at top near the includes)
//touch rot camera
int rx = 0, ry = 0;
int oldx = 0, oldy = 0;
 
(this parts in the middle under main & while)
(useing the opengl functions)
//camera with touchscreen
glLoadIdentity();
touchRead(&touchXY);
//reset x and y when user touches screen
if( Press & KEY_TOUCH){
oldx = touchXY.px;
oldy = touchXY.py;}
//if user drags then grab the delta
if( held & KEY_TOUCH){
rx += touchXY.px - oldx;
oldx = touchXY.px;
ry += touchXY.py - oldy;
oldy = touchXY.py;}
 
(this parts at bottom)
glRotateX(ry);
glRotateY(rx);