Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 374
  • Last Modified:

Matrix Concatenation and Glide

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:
However, this does not work. The matrixs are:
            matrix Org={10,0,0,10,
                        matrix roat={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

  • 4
  • 2
1 Solution
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,

For rotation, to represent according to z -axis


along x-axis

along y-axis

And then shift back from orgin

matrix MoveBack={1,0,0,0,

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

laeuchliAuthor Commented:
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?
laeuchliAuthor Commented:
Could you show me a finished example matrix for a roation about the x axis?I seem to have bug in my program.

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

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;

 struct Point p;
 struct Point np;
 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++)

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


 // 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);
laeuchliAuthor Commented:
ok, thanks I will get back to you, after I test it.

laeuchliAuthor Commented:
Thanks, that did the trick
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now