Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Thread: My first matrix

  1. #1
    Member Contributor
    Join Date
    Feb 2001
    Location
    Sydney, NSW, Australia
    Posts
    60

    My first matrix

    I've tried to create a matrix class that is useful and that i can understand (as I can't quite grasp anyone else's classes).

    My matrix class is only designed to be used by opengl commands so I probably won't need to know a lot to make it work.

    I've done a lot of groundwork before posting and have read a lot of matrix articles. I'm stuck on one point though.

    So far I have a camera and an object matrix. The way I understand this is that the object matrix represents a local coordinate system. It's translation moves the local coordinate system around in world space. (Mhen multiplied).

    I rotate my object around the Z axis(roll) by 45deg then rotate around the Y axis 45 deg(yaw) then tell it to move down the Z axis X units. This seems to squish the object at the object remains on the z plane.

    Here are some code samples to show what I'm doing:
    Code :
    inline void CMatrix::Yaw(const float a_Degrees)
    {
    	float Radians = Degrees2Radians(a_Degrees);
    	float c = Cos(Radians);
    	float s = Sin(Radians);
     
    	m[0] = c;   
    	m[2] = -s;
    	m[8] = s;  
    	m[10] = c;
    }
     and 
     
    inline void CMatrix::Forward(const float a_Units)
    {
       m[12] = m[8]  * a_Units + m[12];
       m[13] = m[9]  * a_Units + m[13];
       m[14] = m[10] * a_Units + m[14];
       m[15] = m[11] * a_Units + m[15];
    }
     
    inline void CMatrix::Roll(const float a_Degrees)
    {
    	float Radians = Degrees2Radians(a_Degrees);
    	float c = Cos(Radians);
    	float s = Sin(Radians);
     
    	m[0] = c;   
    	m[1] = s;
    	m[4] = -s;  
    	m[5] = c;
    }
     
    and this is how I'd like to use my matrix:
     
    	glMatrixMode(GL_MODELVIEW);
    	CMatrix Camera = -Viewer;
    	glLoadMatrixf(Camera);
     
     
    	glPushMatrix();
    		glMultMatrixf(Object1);
    		glColor3f(0,0,1);
    		glRotatef(180,0,1,0); //Glut cone is back to front
    		glutWireCone(0.5,1,10,6);
    	glPopMatrix();
    Can anyone see where I'm going wrong?

    I also have another problem with that code while it's up, I can't seem to work out how to rotate multiple times. How do I take the rotation I have, then 'add' another rotation to it. I assume I'll need to renormalise at some point. Do I renormalise all the 9 elements together or each vector seperatly?

    Many, many thanks. (I really need to work this out.

    Chris

    [This message has been edited by gimp (edited 02-26-2001).]

  2. #2
    Member Newbie
    Join Date
    Feb 2001
    Location
    Atlanta Georgia
    Posts
    32

    Re: My first matrix

    My best estimation is that you are not using correct translation matrixes. I don't understand where you got the whole:

    inline void CMatrix::Forward(const float a_Units)
    {
    m[12] = m[8] * a_Units + m[12];
    m[13] = m[9] * a_Units + m[13];
    m[14] = m[10] * a_Units + m[14];
    m[15] = m[11] * a_Units + m[15];
    }

    function from... all the translation matrixes I have seen are in the form:

    1 0 0 0;
    0 1 0 0;
    0 0 1 0;
    x y z 1;

    so if you m[8]-m[11] are anything but 0's or 1's, you have some odd sort of matrix. Your code looks good as far as theory goes. If you want multiply translation/rotations/ect to affect you camera, you simply need to multiply your camera matrix by each in order.

    Please note: that camera motion is inverse of percieved motion, meaning you need to translate/rotate it like a normal object, then invert it before passing it to glLoadMatrixf to get correct motion.

    GL (goodluck)
    "Close before striking. Keep away from Children"--Strike on the box matches.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Nov 2000
    Posts
    370

    Re: My first matrix

    Yeah, why are you using m[15]? Do a search on multmatrix on this board, and you will find a ~90 thread message that has all this stuff in it. Your modifying the wrong elements is your first problem. For rotations, after you have your rotation matrix made, you could use that again, or just rebuild one again. It depends what you want done.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Dec 2007
    Posts
    1,077

    Re: My first matrix

    Elixer, should we just run a faked discussion here?

  5. #5
    Senior Member Regular Contributor
    Join Date
    Nov 2000
    Posts
    370

    Re: My first matrix

    LOL

    It is too bad we can't "flag" certain messages that are helpfull to lots of people. Maybe the board operator can make a "FAQ" section, and then move all the helpfull messages to that area?

  6. #6
    Member Contributor
    Join Date
    Feb 2001
    Location
    Sydney, NSW, Australia
    Posts
    60

    Re: My first matrix

    I'm sorry I only partialy get what your talking about... Are you suggesting keeping this thread running so you don't see it appear again by a different person in a few days?

    I have missed the point when it comes to m15, I have no idea as to what it's for. I think the 4th member of a vector normally has something to do with scaling... No idea with matricies.

    I DID have a look for the 90 post thread, though the search engine doesn't show how many posts each topic has, does anyone know a word that would be in there other than 'matrix' ?

    I've also been reading as much as I can relating to this subject though books I have like "3D Game Engine Design","Real time rendering","OpenGL(Red Book)","3D Graphics Programming" + a few other books all seem to jump from basics to advanced. I know how to invert(transpose?) a matrix but not move a local coordinate system.

    My forward example was trying to simplfy my case, obviously a local transform can be handled just as easily(in fact Forward should probably reimplement a generic local transform)

    A faq would be great that covers in detail the structure of a matrix, I've seen nothing on the net that does this. (Yes, I also have hexapods matrix & Quat faq)

    I'd really love to learn this stuff, My curiosity has been awakened to all this cool math stuff I've been getting in to recently to the point where I'm thinking about finaly going to uni(after 10+ years since HS).

    The reason I'm asking about this is I'm building a scene graph and want each object to store it's matrix so I can transform them quickly (ie a turret on a tank is easily positioned relative to the tank). I'd also like to be able to jump my camera between objects so at some point I'll probably need to learn how to apply projective transforms, but one step at a time huh?

    I have found many Matrix Class example but non have a member function that does transform that are affected by local rotations. Am I missing something?

    Many thanks

    Chris

    Can someone help me find that 90 post thread?

  7. #7
    Guest

    Re: My first matrix

    Do search multmatrix. I find there.

  8. #8
    Senior Member Regular Contributor
    Join Date
    Dec 1969
    Location
    Munich,Germany
    Posts
    227

    Re: My first matrix

    yes

  9. #9
    Senior Member Regular Contributor
    Join Date
    Oct 2000
    Location
    USA
    Posts
    302

    Re: My first matrix

    As far as:

    inline void CMatrix::Forward(const float a_Units)
    {
    m[12] = m[8] * a_Units + m[12];
    m[13] = m[9] * a_Units + m[13];
    m[14] = m[10] * a_Units + m[14];
    m[15] = m[11] * a_Units + m[15];
    }


    It makes perfect sense to me... why doesn't it make sense to anyone else? He's moving the center (local origin) of the matrix (12,13,14 but 15 I'm not so sure) in the direction of the "front" vector (8,9,10 and again I'm not sure about 11) multiplied by a certain distance. If he wanted to do the same only move it in the "up" direction, he'd do the same except instead of 8,9, and 10, he'd use 4,5, and 6. What's so wrong with that? I realize it may not be what most people do and is a bit unusual but it should work.

  10. #10
    Senior Member Regular Contributor
    Join Date
    Dec 1969
    Location
    Munich,Germany
    Posts
    227

    Re: My first matrix

    Punchey did you by any chance read the ~90 msgs. thread?
    yes

Page 1 of 3 123 LastLast

Similar Threads

  1. Replies: 0
    Last Post: 09-16-2015, 03:27 PM
  2. Replies: 1
    Last Post: 07-20-2014, 03:29 PM
  3. Replies: 3
    Last Post: 04-03-2010, 03:10 PM
  4. Need an advice on separating model matrix from view matrix.
    By Obli in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 10-09-2003, 06:07 AM
  5. Can concatenate projection matrix with viewport transformation matrix?
    By MelvinEng in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 07-07-2002, 10:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean