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 > Object Rotation

#142579 - NeX - Wed Oct 10, 2007 4:05 pm

I have two rotation variables; pitch (X) and roll (z). I can get both of these to look absolutely correct by themselves, and as the rotation commands are one axis at a time, if I rotate along the X and then the Z each frame, the rotation looks fine until I roll and then pitch. The object pitches up along the world axis. If I do Z first, the roll is wrong. It's something of a catch-22. Is there a way to get it to rotate along both axis at once?
_________________
Strummer or Drummer?.
Or maybe you would rather play with sand? Sandscape is for you in that case.

#142590 - Peter - Wed Oct 10, 2007 6:03 pm

I guess you work with matrices?! Then just create the corresponding x,z rotation matrices and multiply them. The resulting matrix contains boths rotations.

My solution is too simple, I probably didn't understand your problem :-/ Hope it helps you anyway!
_________________
Kind Regards,
Peter

#142594 - Miked0801 - Wed Oct 10, 2007 6:16 pm

You do both at the same time, but if you add a 3rd rotation in at the same time, you can get something known as gimble lock. This is where quaternions become your friend.

#142600 - NeX - Wed Oct 10, 2007 7:30 pm

Nope, I'm just after pitch and roll. I'm trying to find out how exactly you would use a matrix.
_________________
Strummer or Drummer?.
Or maybe you would rather play with sand? Sandscape is for you in that case.

#142611 - tepples - Wed Oct 10, 2007 9:05 pm

You can start at [[Transformation matrix]].
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#142614 - NeX - Wed Oct 10, 2007 9:16 pm

Alright... I've looked around and I believe by multiply the matrix, you mean multiply each item within by its counterpart in another. But, won't this cause problems as there are quite a few zeroes in both?
_________________
Strummer or Drummer?.
Or maybe you would rather play with sand? Sandscape is for you in that case.

#142615 - tepples - Wed Oct 10, 2007 9:24 pm

NeX wrote:
Alright... I've looked around and I believe by multiply the matrix, you mean multiply each item within by its counterpart in another.

You might be confusing standard matrix multiplication with the Hadamard product used in JPEG.

First you'll need to know what a dot product is. Then each cell of the product is the dot product of the corresponding row of the first matrix with the corresponding column of the second matrix.

And the DS 3D hardware does most of this for you, so once you understand how it works, you won't need to optimize the matrix multiplication itself for speed.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#142617 - NeX - Wed Oct 10, 2007 9:31 pm

Think I'm getting it. Thanks. Unbelievable how wrapped in cotton wool you are when using a simplified language like Dark Basic.
_________________
Strummer or Drummer?.
Or maybe you would rather play with sand? Sandscape is for you in that case.

#142619 - NeX - Wed Oct 10, 2007 9:51 pm

Have I got most of this right? The screen is blank upon run.
Code:

      u16 ref=integ(wrapvalue512(xangle/360.0)*512);
      xrot.m[0]=1;
      xrot.m[4]=COS_bin[ref];
      xrot.m[5]=SIN_bin[ref];
      xrot.m[7]=-SIN_bin[ref];
      xrot.m[8]=COS_bin[ref];
      ref=integ(wrapvalue512(zangle/360.0)*512);
      zrot.m[4]=COS_bin[ref];
      zrot.m[3]=-SIN_bin[ref];
      zrot.m[8]=1;
      zrot.m[1]=SIN_bin[ref];
      zrot.m[8]=COS_bin[ref];      

      glLoadMatrix4x4(&xrot);
      glMultMatrix4x4(&zrot);
      glPushMatrix();

_________________
Strummer or Drummer?.
Or maybe you would rather play with sand? Sandscape is for you in that case.

#142621 - Peter - Wed Oct 10, 2007 10:12 pm

Scroll down to the Rotate chapter, you'll find matrices for x,y,z rotation there: Transforms (Direct3D 9).

Don't be afraid that's the Direct-X documentation. The MSDN is very good and there is more or less everything explained you need to know about how to work with matrices.

PS: If you don't really want to come up with your own matrix and vector math, you can download N3D. You don't need to use the render system (N3DDEVICE), but it provides Matrix and 3D-Vector math modules. The N3D Matrix and Vector modules are implemented in software (don't use any NDS matrix hardware feature), but matrix setup-code isn't really slow anyway, except the multiply is much faster done in hardware.

Using the N3D functions you code would be something like this:
Code:

N3DMATRIX matTrans;
N3DMATRIX matRotX;
N3DMATRIX matRotZ;

N3DMatrixTranlation(matTrans, xpos, ypos, zpos);
N3DMatrixRotationX(matRotX, xangle_in_radians);
N3DMatrixRotationZ(matRotZ, zangle_in_radians);

// I'm not sure about the multiplication order in opengl, so
// maybe its the other way around.
glLoadMatrix4x4(&matRotZ);
glMultMatrix4x4(&matRotX);
glMultMatrix4x4(&matTrans);

_________________
Kind Regards,
Peter


Last edited by Peter on Wed Oct 10, 2007 10:21 pm; edited 1 time in total

#142622 - NeX - Wed Oct 10, 2007 10:16 pm

I think it's merely the commands I'm using. The helicopter is displaying. The physics are working exactly as I want them. Unfortunately, it's still not turning. Do I have to multiply the SIN_bin[] and COS_bin[] by something?

Code:

      glTranslate3f32(floattof32(xpos), floattof32(ypos), floattof32(zpos));


      glPushMatrix();
      u16 ref=integ(wrapvalue512(xangle/360.0)*512);
      xrot.m[0]=1;
      xrot.m[4]=COS_bin[ref];
      xrot.m[5]=SIN_bin[ref];
      xrot.m[7]=-SIN_bin[ref];
      xrot.m[8]=COS_bin[ref];
      ref=integ(wrapvalue512(zangle/360.0)*512);
      zrot.m[4]=COS_bin[ref];
      zrot.m[3]=-SIN_bin[ref];
      zrot.m[8]=1;
      zrot.m[1]=SIN_bin[ref];
      zrot.m[8]=COS_bin[ref];      

      glLoadMatrix4x4(&xrot);
      glMultMatrix4x4(&zrot);
      glPopMatrix(1);
      
      glScalef(400.0,400.0,400.0);

                (Draw Helicopter)

_________________
Strummer or Drummer?.
Or maybe you would rather play with sand? Sandscape is for you in that case.

#142627 - NeX - Wed Oct 10, 2007 10:56 pm

I think it's about time I called it a day. Still don't really understand how the matrix commands work, or what any of them actually do. I've just found tutorials and fiddled with them.

Code:

                //Do Something
      glPushMatrix();
      //gluLookAt(   -2.0, 0.5, -2.0,      //camera possition
      //      xpos, ypos, zpos,      //look at
      //      0.0, 1.0, 0.0);      //up   
      //X angle
      u16 ref=integ(wrapvalue512(xangle/360.0)*512);
      xrot.m[0]=1;
      xrot.m[4]=COS_bin[ref];
      xrot.m[5]=SIN_bin[ref];
      xrot.m[7]=-SIN_bin[ref];
      xrot.m[8]=COS_bin[ref];
      //Z angle
      ref=integ(wrapvalue512(zangle/360.0)*512);
      zrot.m[4]=COS_bin[ref];
      zrot.m[3]=-SIN_bin[ref];
      zrot.m[8]=1;
      zrot.m[1]=SIN_bin[ref];
      zrot.m[8]=COS_bin[ref];
      
      //Scale Me
      trans.m[0]=400;
      trans.m[5]=400;
      trans.m[10]=400;
      trans.m[15]=1;
      
      //Move Me
      trans.m[3]=integ(xpos*4096.0);
      trans.m[7]=integ(ypos*4096.0);
      trans.m[11]=integ(zpos*4096.0);
      
                //Stuff
      glLoadMatrix4x4(&xrot);
      glMultMatrix4x4(&zrot);
      glMultMatrix4x4(&trans);
      
           //Draw the helicopter using shoddy code
      u8 i=0;
      while(i<64)
      {
         glBegin(GL_TRIANGLE);
            glNormal(NORMAL_PACK(0,inttov10(-1),0));

            GFX_TEX_COORD = (TEXTURE_PACK(0, inttot16(127)));
            glVertex3v16(BetterHeli[(i*9)+0],   BetterHeli[(i*9)+1],BetterHeli[(i*9)+2] );
   
            GFX_TEX_COORD = (TEXTURE_PACK(inttot16(127),inttot16(127)));
            glVertex3v16(BetterHeli[(i*9)+3],   BetterHeli[(i*9)+4],BetterHeli[(i*9)+5] );
   
            GFX_TEX_COORD = (TEXTURE_PACK(inttot16(127), 0));
            glVertex3v16(BetterHeli[(i*9)+6],   BetterHeli[(i*9)+7],BetterHeli[(i*9)+8] );

      
         glEnd();
         i++;
      }
                //And do something else
      glPopMatrix(1);


That N3D sounds great. How the hell do you install it? On my PC, it reads the .h and throws error after error. There are no installation instructions I can find. I've put things where I guess they should go, but that's hardly going to work.
_________________
Strummer or Drummer?.
Or maybe you would rather play with sand? Sandscape is for you in that case.

#142629 - DekuTree64 - Wed Oct 10, 2007 11:12 pm

One thing that could definitely cause weirdness is those integer constants. Matrices are 24.12 fixed-point, so they need to be shifted up 12 bits (I think the macro for it is called inttof32).

And if it still doesn't work, try setting the matrix mode to position-vector before doing the load/multiplies, just incase it's left to projection or something.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#142630 - NeX - Wed Oct 10, 2007 11:19 pm

It'd probably help if I had the faintest what half of you were talking about. What does the matrix mode do? Why? How should I implement it? I've probably made the most stupid mistake, but can't tell because to be quite honest I have no idea where half of the facts were plucked from. Perhaps I should simply butcher the camera looking code. Also, about installing libraries; how? Where do I put all the stuff? The installation guide for N3D is the vaguest passage I have read since I last did an English essay.

Quote:
Installation
This document describes how to install N3D.

Make sure to meet the Requirements. Once you have the required software and you can compile the libnds samples from devkitARM, it's easy going.

You solely have to extract the N3D .zip archive, which you probably just downloaded, to your devkitPro installation root folder. You should then find a "libn3d" directory there.

The libn3d directory contains all relevant N3D files, such as C++ header files, library files, utilities and this documentation of course.


At no point does it tell me what to do with any of the files on this entire page. And no, just copying that folder to the root of devkitPro doesn't do anything.
_________________
Strummer or Drummer?.
Or maybe you would rather play with sand? Sandscape is for you in that case.

#142654 - Peter - Thu Oct 11, 2007 7:38 am

NeX wrote:
At no point does it tell me what to do with any of the files on this entire page. And no, just copying that folder to the root of devkitPro doesn't do anything.

Oh ok, I thought my "guide" is pretty straight forward, obviosly I was wrong :)

Here is a hopefully more complete one:

1) Extract libn3d.zip to /devkitpro
2) Go to /devkitpro/libn3d/
3) You should see dirctories named "include", "lib"

"include" contains all header files. You need to include "n3d.h" in your project.

"lib" contains the libraries, which you need to link to your projct. "libn3d.a" is the release lib, "libn3d_d.a" the debug one. But in n3d v0.2 they are same.

Pass either _DEBUG or _RELEASE to the compiler to enable debug facilities or remove them. In _RELEASE mode more functions are inlined.

The makefiles of the n3d sample projects (in /devkitpro/n3d/samples) add the include and lib directories to the correspondng variables in makefile:
Code:

#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
# -ln3d = release lib
# -ln3d_d = debug lib
LIBS   := -lnds9 -ln3d

# compile with no debug stuff
CFLAGS   += -D_RELEASE

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS   :=   $(LIBNDS) $(DEVKITPRO)/libn3d

_________________
Kind Regards,
Peter

#142673 - NeX - Thu Oct 11, 2007 3:42 pm

Thank you.
Still get a screenful of errors though. It seems to really dislike that there .h file. Well, the types it includes to be specific.
Quote:

c:/devkitPro/libnds/include/n3d/n3dtypes.h:51: error: expected specifier-qualifier-list before 'inline'
c:/devkitPro/libnds/include/n3d/n3dtypes.h:118: error: expected specifier-qualifier-list before 'inline'
c:/devkitPro/libnds/include/n3d/n3dtypes.h:135: error: expected specifier-qualifier-list before 'inline'
c:/devkitPro/libnds/include/n3d/n3dtypes.h:151: error: expected specifier-qualifier-list before 'N3DFLOAT'
c:/devkitPro/libnds/include/n3d/n3dtypes.h:180: error: expected specifier-qualifier-list before 'N3DCOLOR'
c:/devkitPro/libnds/include/n3d/n3dtypes.h:197: error: expected specifier-qualifier-list before 'N3DCOLOR'
In file included from c:/devkitPro/libnds/include/n3d/n3dtypes.h:483,
from c:/devkitPro/libnds/include/n3d.h:70,
from c:/devkitpro/Heli/source/main.c:3:
c:/devkitPro/libnds/include/n3d/n3dcolor.inl:2: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
c:/devkitPro/libnds/include/n3d/n3dcolor.inl:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
c:/devkitPro/libnds/include/n3d/n3dcolor.inl:13: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
In file included from c:/devkitPro/libnds/include/n3d/n3dtypes.h:484,
from c:/devkitPro/libnds/include/n3d.h:70,
from c:/devkitpro/Heli/source/main.c:3:
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:8: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:16: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:24: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:32: error: expected '=', ',', ';', 'asm' or '__attribute__' before '&' token
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:41: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:49: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:57: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'N3DFLOAT'
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:68: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'N3DFLOAT'
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:79: error: expected '=', ',', ';', 'asm' or '__attribute__' before '&' token
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:88: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'N3DFLOAT'
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:99: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'N3DFLOAT'
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:110: error: expected '=', ',', ';', 'asm' or '__attribute__' before '&' token
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:119: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'N3DFLOAT'
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:130: error: expected '=', ',', ';', 'asm' or '__attribute__' before '&' token
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:139: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'N3DFLOAT'
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:151: error: expected '=', ',', ';', 'asm' or '__attribute__' before '&' token
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:161: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:169: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:177: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:185: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:193: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:201: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:215: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Abs'
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:223: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Ceil'
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:234: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Sign'
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:250: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Lerp'
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:258: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'DegreeToRadian'
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:273: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'RadianToDegree'
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:289: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Sin'
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:316: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'SinRecip'
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:324: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Cos'
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:332: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'CosRecip'
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:340: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Sqrt'
c:/devkitPro/libnds/include/n3d/n3dfloat.inl:350: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Mul64'
In file included from c:/devkitPro/libnds/include/n3d/n3dtypes.h:487,
from c:/devkitPro/libnds/include/n3d.h:70,
from c:/devkitpro/Heli/source/main.c:3:
c:/devkitPro/libnds/include/n3d/n3dvector3.inl:2: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
c:/devkitPro/libnds/include/n3d/n3dvector3.inl:6: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
c:/devkitPro/libnds/include/n3d/n3dvector3.inl:13: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
c:/devkitPro/libnds/include/n3d/n3dvector3.inl:20: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
In file included from c:/devkitPro/libnds/include/n3d.h:71,
from c:/devkitpro/Heli/source/main.c:3:
c:/devkitPro/libnds/include/n3d/n3dmath.h:11: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:12: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:13: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'N3DVec3Dot'
c:/devkitPro/libnds/include/n3d/n3dmath.h:14: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'N3DVec3Length'
c:/devkitPro/libnds/include/n3d/n3dmath.h:15: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'N3DVec3LengthSq'
c:/devkitPro/libnds/include/n3d/n3dmath.h:16: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:17: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:18: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:19: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:20: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:21: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:22: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:23: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:24: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:32: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:33: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:34: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:35: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:36: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:37: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:38: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:39: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:40: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:41: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:42: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:43: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:44: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:45: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dmath.h:46: error: expected ')' before '&' token
In file included from c:/devkitPro/libnds/include/n3d/n3dmath.h:54,
from c:/devkitPro/libnds/include/n3d.h:71,
from c:/devkitpro/Heli/source/main.c:3:
c:/devkitPro/libnds/include/n3d/n3dvec3math.inl:19: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dvec3math.inl:39: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dvec3math.inl:62: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'N3DVec3Dot'
c:/devkitPro/libnds/include/n3d/n3dvec3math.inl:80: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dvec3math.inl:100: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dvec3math.inl:114: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'N3DVec3Length'
c:/devkitPro/libnds/include/n3d/n3dvec3math.inl:131: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'N3DVec3LengthSq'
c:/devkitPro/libnds/include/n3d/n3dvec3math.inl:151: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dvec3math.inl:195: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dvec3math.inl:215: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dvec3math.inl:238: error: expected ')' before '&' token
c:/devkitPro/libnds/include/n3d/n3dvec3math.inl:259: error: expected ')' before '&' token
In file included from c:/devkitPro/libnds/include/n3d/nds/arm9/n3d_nds.h:25,
from c:/devkitPro/libnds/include/n3d.h:79,
from c:/devkitpro/Heli/source/main.c:3:
c:/devkitPro/libnds/include/n3d/nds/arm9/n3ddevice.h:11: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'N3DDEVICE'

_________________
Strummer or Drummer?.
Or maybe you would rather play with sand? Sandscape is for you in that case.

#142675 - NeX - Thu Oct 11, 2007 4:25 pm

Wait, is this compatible with C or just C++? Just C++. Whoops.
_________________
Strummer or Drummer?.
Or maybe you would rather play with sand? Sandscape is for you in that case.

#142676 - Peter - Thu Oct 11, 2007 5:29 pm

Yes, only C++.

However, I just briefly looked at the "Simple_Quad" example from libnds and it seems there are already functions that multiply the current transformation by a rotation matrix:
Code:

 //move it away from the camera
 glTranslate3f32(0, 0, floattof32(-1));

 glRotateX(rotateX);
 glRotateY(rotateY);

Why don't you use glRotateX and glRotateZ? :)
_________________
Kind Regards,
Peter

#142677 - NeX - Thu Oct 11, 2007 5:35 pm

Because. if you read the original post, depending upon the order in which I use rotateX and rotateZ, the helicopter rotates properly in direction but not in the other. I want to do both rotations at the same time, which you cannot do with the X and Z commands. Multiplying the matricies overcomes this, right? Please tell me I haven't just wasted all the time I spent trying to get the matricies to work.
_________________
Strummer or Drummer?.
Or maybe you would rather play with sand? Sandscape is for you in that case.

#142690 - keldon - Thu Oct 11, 2007 11:14 pm

You can use UVN vectors to produce more complex rotations.

#142692 - Anthius - Thu Oct 11, 2007 11:39 pm

For a better understanding of what you're doing outside of the code you may want to look up "Rigid Body Dynamics"... you can find a lot of really complicated stuff on it online, but if you can find a good basic sight it may help you solve the problem yourself (and give you a headache). A lot of it is complicated, but there are 3 very simple matricies (you multiply your object's matrix by them) for pitch/roll/yaw controll... the matricies escape me at the moment...

#142705 - Rajveer - Fri Oct 12, 2007 2:37 am

If you want to try doing it yourself (read slow, information overload!):

Do a google search for 3D Affine Transformations. In this subject read up on the formulas for rotations and the derivation of a rotation matrix (and what each of it's columns/rows means). Read up on Euler angle rotations which is what glRotatex e.t.c. do (and which leads to gimbal lock i.e. your rotation problem), then read up on axis-angle rotations. These are the simplest type of rotation to understand as you simply have one axis and an angle to rotate it by, and any amount of axis-angle rotations can be combined together to produce a single matrix (i.e. multiplying, with the dot product, a matrix which rotates the helicopter in its x-axis and another which rotates it in its z-axis produces another matrix which you can simply multiply the modelview matrix by). Then you'll probably realise that what gimbal lock actually means is constantly rotating the helicopter around the world x, y and z axis instead of the helicopter's own x, y and z axis. By initially creating a 4x4 identity matrix for the helicopter and multiplying this matrix by x, y and z rotation matrices you will rotate the helicopter around it's own x, y or z axis each time.

Once you understand this all you'll realise how easy it is, its just grasping the concept which can be hard. Good luck!

#142958 - silent_code - Mon Oct 15, 2007 3:48 pm

quaternions anyone? they can be a pain, though.