Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8198823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:02:16+00:00 2026-06-07T06:02:16+00:00

I have a case where I need a method to rotate a model matrix

  • 0

I have a case where I need a method to rotate a model matrix in OpenGL to absolute value. Most of the rotate() methods out there add rotation to a current one multiplying the current matrix with the new rotation. I need to rotate the model matrix to some value without keeping the old rotation. What I currently do is to destroy the current matrix to identity. Then calculate its scale from scratch based on scale variables I set before. Then multiply it with rotation matrix acquired from quaternion and eventually again translating it.

It looks to me as too many calculations for such a task. Is there a shorter way to reset matrix rotation while keeping its scale and translation parts intact? Here is my current method (Java):

 public void rotateTo3( float xr,float yr,float zr) {



 Quaternion  xrotQ=   Glm.angleAxis( (xr),Vec3.X_AXIS);
 Quaternion  yrotQ=   Glm.angleAxis( (yr),Vec3.Y_AXIS);
 Quaternion  zrotQ=   Glm.angleAxis( (zr),Vec3.Z_AXIS);
  xrotQ= Glm.normalize(xrotQ);
  yrotQ= Glm.normalize(yrotQ);
  zrotQ= Glm.normalize(zrotQ);

  Quaternion acumQuat=new Quaternion();
  acumQuat= Quaternion.mul(xrotQ,yrotQ);
  acumQuat= Quaternion.mul(acumQuat,zrotQ);


  Mat4 rotMat=new Mat4(1);
  rotMat=Glm.matCast(acumQuat);

    _model = new Mat4(1);




   scaleTo(_scaleX, _scaleY, _scaleZ);//reconstruct scale
   _model = Glm.translate(_model, new Vec3(_pivot.x, _pivot.y, 0));


  _model=rotMat.mul(_model); ///add new rotation


   _model = Glm.translate(_model, new Vec3(-_pivot.x, -_pivot.y, 0));



   translateTo(_x, _y, _z);//reconstruct translation

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:02:17+00:00Added an answer on June 7, 2026 at 6:02 am

    This is actually done rather easy. The key insight is, that a homogenous transformation matrix consists 3 parts: The upper left 3×3 matrix is a rotation-scaling, the rightmost top 1×3 column is the translation, the bottom left 3×1 allows for affine scaling and the bottom right is 1.

    So we can write it as

    RS T
     A 1
    

    Now what you want to do is decomposing a given RS into R and S. Now rotations are always orthogonal, which means R^T = R^-1. But scalings are not, as for a scaling S^T = S != S^-1, hence we can write

    (RS)^T * RS = S^T * R^T * R * S = S^T * R^-1 * R * S = S^T * S = S^2
    

    scaling happens only on the diagonal, so you can extract the x, y and z scaling factors by taking the square root of the elements on the diagonal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a use case where I need to call a (non-static) method in
I have a use case where I need to add information about the user
I have a case where I need to select a random item, but I
I have a case where I need to load bitmap from a resource dll
I have a case where I need to update a jqgrid based on some
I have a very specific case that I need to debug. I need to
I have a use case where I only need to store certain fields to
I have a complicated problem, and I need help. I have a base case,
I have a strong use case for pre-allocating all the memory I need upfront
I'm very much new to objective C. I have a case where I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.