Rotation matrices

This is a discussion on Rotation matrices within the C Programming forums, part of the General Programming Boards category; I'm currently doing a programming project and decided to leave the easiest bit till last. however, im having some trouble ...

  1. #1
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72

    Post Rotation matrices

    I'm currently doing a programming project and decided to leave the easiest bit till last. however, im having some trouble with it . im sure im missing something simple.

    All i want to do is take some inputted points for a triangle, and rotate them. Is the following code correct?

    matrix((vertex[count][X]-mX), (vertex[count][Y]-mY));

    the call is that ^

    The theory is to minus the triangle mid-point (mX,mY) from the existing entered points (vertex[count][X], vertex[count][Y]). Then rotate by the matrices. Then shift back.

    DEG2RAD is just the conversion factor from degrees to radians needed for sin/cos etc
    Code:
    void matrix(float tempx, float tempy)
    {
    int count;
    float matrix[4]={cos(5*DEG2RAD), sin(5*DEG2RAD), -sin(5*DEG2RAD), cos(5*DEG2RAD)};
    
    for(count=0; count<=3; count++)
    	{
    	vertex[count][X]=(matrix[0]*tempx)+(matrix[2]*tempx)+mX;
    	vertex[count][Y]=(matrix[1]*tempy)+(matrix[3]*tempx)+mY;
    	}
    
    return;
    }
    Its in opengl but im not allowed to use any preritten functions for the rotation or anything

    Code tags added by Hammer

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    this site explains matrix translation, rotation, and the like.

    http://www.geocities.com/SiliconVall.../matrices.html
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72
    cool i'll take a look, although i did look at some sites like mathworld but the scope goes a little beyond what i wanted... cheers

  4. #4
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72
    yep sorry just seen the post about adding code tags, i'll remember that :$

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. camera rotation matrix
    By Vick jr in forum Game Programming
    Replies: 5
    Last Post: 05-26-2009, 08:16 AM
  2. working with rotation matrices
    By hannibar in forum Game Programming
    Replies: 23
    Last Post: 03-30-2005, 12:10 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. DirectX rotation matrices
    By confuted in forum Game Programming
    Replies: 7
    Last Post: 08-10-2003, 03:05 PM
  5. Problem multiplying rotation matrices together
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 03-04-2003, 08:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21