?
Solved

Matrix Concatenation and Glide

Posted on 2000-02-15
6
Medium Priority
?
369 Views
Last Modified: 2008-02-01
Hey, I have writen a small 3d engine.
However, I need to rotate a object, as well as keep the object in place and expand it.  I have read in the MSDN that the corret way to do this is to multiply the two matrixs. I did this, using the code on question:http://www.experts-exchange.com/jsp/qShow.jsp?ta=cprog&qid=10294246
However, this does not work. The matrixs are:
            matrix Org={10,0,0,10,
                    0,10,0,10,
                    0,0,10,10,
                    0,0,0,0};
            
            
                        matrix roat={1,1,1,1,
                                           1,cosf(movex),sinf(movex),1,
                                           1,(-sinf(movex)),cosf(movex),1,
                                           1,1,1,1};
could someone show me the correct matrix? Or if this is correct, can someone show me a multiplied matrix that works, so I can debug? Thanks

0
Comment
Question by:laeuchli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 1

Expert Comment

by:sthung
ID: 2526934
For 3D rotation, you have to multiply 3 matrix to the coordinates

The first one is shift to orgin

matrix MoveToOrg={1,0,0,0,
                  0,1,0,0,
                  0,0,1,0,
                  -x,-y,-z,1};

For rotation, to represent according to z -axis

matrix
RotatoZ={conf(anglez),sinf(anglez),0,0,
         sinf(anglez),conf(anglez),0,0,
         0,0,1,0,
         0,0,0,1};

along x-axis
RotateX={1,0,0,0,
         0,conf(anglex),sinf(anglex),0,
         0,-sinf(anglex),cosf(anglex),0,
         0,0,0,1};

along y-axis
RotateY={cosf(angley),0,-sinf(angley),0,
         0,1,0,0,
         sinf(angley),0,cosf(angley),0,
         0,0,0,1};

And then shift back from orgin

matrix MoveBack={1,0,0,0,
                 0,1,0,0,
                 0,0,1,0,
                 x,y,z,1};

You have to multiply all of them in order to produce a new matrix for 3D object rotation

 
0
 
LVL 5

Author Comment

by:laeuchli
ID: 2527019
All I really wanted to do, was roate on the X axis, and keep every thing the right size. I don't at the time want to rotate on the Y and Z axis. Do I still have to multily all the matrixs?
0
 
LVL 5

Author Comment

by:laeuchli
ID: 2529552
Could you show me a finished example matrix for a roation about the x axis?I seem to have bug in my program.

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Accepted Solution

by:
sthung earned 280 total points
ID: 2530060
For example if you want to rotate along x-axia for 30 degree

First of all you have to change the unit from degree to radian
Let's assume the rotation center is at origin

#include <math.h>

struct Point
(
 float x,y,z;
};

main()
{
 struct Point p;
 struct Point np;
 p.x=1;
 p.y=1;
 p.z=1;
 
 float d=30;
 float r=(float)d*PI/180.0;

 float MatRotat[4][4];

 for(int i=0;i<4;i++)
  for(int j=0;j<4;j++)
   MatRotat[i][j]=0;

 // 1,   0   ,  0   ,0
 // 0, cos(r),sin(r),0
 // 0,-sin(r),cos(r),0
 // 0,   0   ,  0   ,1

 MatRotat[0][0]=1;
 MatRotat[1][1]=cos(r);
 MatRotat[1][2]=sin(r);
 MatRotat[2][1]=-sin(r);
 MatRotat[2][2]=cos(r);
 MatRotat[3][3]=1;
 
 np.x=p.x*MatRotat[0][0]+p.y*MatRotat[0][1]+p.z*MatRotat[0][2]+MatRotat[0][3];
 np.y=p.x*MatRotat[1][0]+p.y*MatRotat[1][1]+p.z*MatRotat[1][2]+MatRotat[1][3];
 np.z=p.x*MatRotat[2][0]+p.y*MatRotat[2][1]+p.z*MatRotat[2][2]+MatRotat[2][3];

 // np is holding new point after rotate
 printf("After rotate 30 along x-axis and rotation center is origin\n");
 printf("Original point (%.2f,%.2f,%.2f)\n",p.x,p.y,p.z);
 printf("New point (%.2f,%.2f,%.2f)\n",np.x,np.y,np.z);
 
}
0
 
LVL 5

Author Comment

by:laeuchli
ID: 2530965
ok, thanks I will get back to you, after I test it.

0
 
LVL 5

Author Comment

by:laeuchli
ID: 2540966
Thanks, that did the trick
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question