Skip to main content
deleted 314 characters in body
Source Link

In my code, I didn't save the previous state and then multiply that previous state to the transformation I did earlier.

The problem is I keep creating a new model matrix base on the origin state so that make my model shifts when I choose a new pivot base on the NEW STATE but meanwhile reset the state to origin. Have to save the previous matrix to use it later, I do these steps (Example code):

// Global variable
Matrix4d prevModelMatrix = Matrix4d.Identity;
Matrix4d modelMatrix = Matrix4d.Identity;

function Render() {
  ...
  GL.LoadMatrix(modelMatrix);
  ...
  Transformation... (Use offset instead of using new rotate and translate value to avoid accumulating)
  For example: 
    - GL.Rotate(offsetAngleX, 1,0,0);
  ...
  prevModelMatrix = modelMatrix;
}

// Apply previous state before transforming
function MouseDown() {
  Matrix4d offsetRotateMatrix = Matrix4d.Rotate(offsetAngleX, offsetAngleY, 0);
  ...
  modelMatrix = translateToPivotMatrix * offsetRotateMatrix * translateBackFromPivotMatrix * prevModelMatrix;
  ...
}

// Reset offsets to 0 to avoid Render() function still use the offset to transform the scene
function MouseUp() {
  offsetAngleX = 0;
  ...
}
```

In my code, I didn't save the previous state and then multiply that previous state to the transformation I did earlier.

The problem is I keep creating a new model matrix base on the origin state so that make my model shifts when I choose a new pivot base on the NEW STATE but meanwhile reset the state to origin. Have to save the previous matrix to use it later, I do these steps (Example code):

// Global variable
Matrix4d prevModelMatrix = Matrix4d.Identity;
Matrix4d modelMatrix = Matrix4d.Identity;

function Render() {
  GL.LoadMatrix(modelMatrix);
  ...
  Transformation... (Use offset instead of using new rotate and translate value to avoid accumulating)
  For example: 
    - GL.Rotate(offsetAngleX, 1,0,0);
  ...
  prevModelMatrix = modelMatrix;
}

// Apply previous state before transforming
function MouseDown() {
  Matrix4d offsetRotateMatrix = Matrix4d.Rotate(offsetAngleX, offsetAngleY, 0);
  ...
  modelMatrix = translateToPivotMatrix * offsetRotateMatrix * translateBackFromPivotMatrix * prevModelMatrix;
  ...
}

// Reset offsets to 0 to avoid Render() function still use the offset to transform the scene
function MouseUp() {
  offsetAngleX = 0;
  ...
}
```

In my code, I didn't save the previous state and then multiply that previous state to the transformation I did earlier.

The problem is I keep creating a new model matrix base on the origin state so that make my model shifts when I choose a new pivot base on the NEW STATE but meanwhile reset the state to origin. Have to save the previous matrix to use it later, I do these steps (Example code):

// Global variable
Matrix4d prevModelMatrix = Matrix4d.Identity;
Matrix4d modelMatrix = Matrix4d.Identity;

function Render() {
  ...
  GL.LoadMatrix(modelMatrix);
  ...
  Transformation... (Use offset instead of using new rotate and translate value to avoid accumulating)
  For example: 
    - GL.Rotate(offsetAngleX, 1,0,0);
}

// Reset offsets to 0 to avoid Render() function still use the offset to transform the scene
function MouseUp() {
  offsetAngleX = 0;
  ...
}
```
Source Link

In my code, I didn't save the previous state and then multiply that previous state to the transformation I did earlier.

The problem is I keep creating a new model matrix base on the origin state so that make my model shifts when I choose a new pivot base on the NEW STATE but meanwhile reset the state to origin. Have to save the previous matrix to use it later, I do these steps (Example code):

// Global variable
Matrix4d prevModelMatrix = Matrix4d.Identity;
Matrix4d modelMatrix = Matrix4d.Identity;

function Render() {
  GL.LoadMatrix(modelMatrix);
  ...
  Transformation... (Use offset instead of using new rotate and translate value to avoid accumulating)
  For example: 
    - GL.Rotate(offsetAngleX, 1,0,0);
  ...
  prevModelMatrix = modelMatrix;
}

// Apply previous state before transforming
function MouseDown() {
  Matrix4d offsetRotateMatrix = Matrix4d.Rotate(offsetAngleX, offsetAngleY, 0);
  ...
  modelMatrix = translateToPivotMatrix * offsetRotateMatrix * translateBackFromPivotMatrix * prevModelMatrix;
  ...
}

// Reset offsets to 0 to avoid Render() function still use the offset to transform the scene
function MouseUp() {
  offsetAngleX = 0;
  ...
}
```