Jump to content

  • Log In with Google      Sign In   
  • Create Account


BlackJoker

Member Since 28 Feb 2013
Offline Last Active Today, 12:33 AM

Posts I've Made

In Topic: How to get rid of camera z-axis rotation

Yesterday, 11:57 PM

 

I still not really understand what do you mean from scratch. You mean I need to make qRotation Identity each time after multiply or what? 
ViewMatrix is building from scratch each time.


I think you are very close. What we are saying is that instead of representing the current state as `qRotation', you should keep two accumulators called `pitch' and `yaw', of type float. You increment or decrement those in response to user input, and then build the ViewMatrix starting from the identity and applying the x-axis rotation and the y-axis rotation.

 

 

So, the code is the same, but I must keep angles and create quaternons from this angles?


In Topic: How to get rid of camera z-axis rotation

Yesterday, 04:46 PM

I still not really understand what do you mean from scratch. You mean I need to make qRotation Identity each time after multiply or what? 

ViewMatrix is building from scratch each time.

 

Sorry, but I really don`t understand for now your concept. Maybe if you could change my code with yours (even pseudo code) it will help me to understand at last.


In Topic: How to get rid of camera z-axis rotation

Yesterday, 03:41 PM

Here is my code:

 

take degrees for X and Y

if (mouseInput.MouseState.RightButton.Down)
            {
                basicCamera.RotateX(-mouseInput.MouseState.DeltaX * mouseRotationSpeed);
                basicCamera.RotateY(-mouseInput.MouseState.DeltaY * mouseRotationSpeed);
               
            }

Then do quaternion multiply:

public void RotateX(float _degree_angle)
        {
            if (cameraType == CamType.ThirdPerson)
            {
                _degree_angle = -_degree_angle;
            }

            qRotation = Quaternion.Multiply(Quaternion.RotationAxis(Vector3.UnitX, MathUtil.DegreesToRadians(_degree_angle)), qRotation);
            
            UpdateViewMatrix();
        }

        public void RotateY(float _degree_angle)
        {
            if (cameraType == CamType.ThirdPerson)
            {
                _degree_angle = -_degree_angle;
            }
            qRotation = Quaternion.Multiply(qRotation, Quaternion.RotationAxis(Vector3.UnitY, MathUtil.DegreesToRadians(_degree_angle)));
            
            UpdateViewMatrix();
        }

FInally update view matrix:

private void UpdateViewMatrix()
        {
            qRotation = Quaternion.Normalize(qRotation);

            if (CameraType == CamType.ThirdPerson)
            {
                ViewMatrix = Matrix.Translation(Vector3.Negate(position)) * Matrix.RotationQuaternion(qRotation);

                position -= new Vector3(ViewMatrix.M13, ViewMatrix.M23, ViewMatrix.M33) * radius;

                ViewMatrix = Matrix.LookAtLH(position, lookAt, new Vector3(ViewMatrix.M12, ViewMatrix.M22, ViewMatrix.M32));
            }
            else
            {
                ViewMatrix = Matrix.Translation(Vector3.Negate(position)) * Matrix.RotationQuaternion(qRotation);
            }
        }

P.S. quaternion multiply order in Y rotation changed because it prevent camera to move around its z-axis, but it causes it to turn upside down when moving on diagonal. If I dont change the order, then moving on diagonal is good, but camera is rotating on z-axis each time I move it around x and y axis.


In Topic: How to get rid of camera z-axis rotation

Yesterday, 11:27 AM

 

Even if you are using a free camera, I'm not sure why you would ever want roll (but it looks like you aren't actually doing anything with that value). As Álvaro said, you should probably be using those values as accumulators rather than just delta rotation angles. Otherwise if you are just applying those delta rotations each frame you're going to be rotating in whatever space you were previously in which could cause the weird behavior you are seeing - hence building the camera matrix EVERY frame so you keep your transform space "clean" since you are just rebuilding it based on a few values.

class Camera
{
  //... previous code
  
  void rotate(float yaw, float pitch)
  {
  	m_yaw += yaw;
  	// Wrap around if we exceed 2 PI, or go below 0
  	if (m_yaw > TWO_PI) 
  	{
  		m_yaw -= TWO_PI;
  	}
  	else if (m_yaw < 0.0f)
  	{
  		m_yaw += TWO_PI;
  	}
  	
  	m_pitch += pitch
  	// With pitch, we probably dont want to wrap around as that would cause some ugliness, so just clamp.
  	if (m_pitch > HALF_PI)
  	{
  		m_pitch = HALF_PI;
  	}
  	else if (m_pitch < -HALF_PI)
  	{
  		m_pitch = -HALF_PI;
  	}
  }
}

 

I already tried this, but this has no effect. Described Issues still present.

 

I think problem is that in curtain moment camera`s UP vector become something like 0,-1,0 instead of 0,1,0

 

So, my question here, how to set up correct UP vector after my manipulations with quaternions so, that no to break the view matrix?

 

Or this is issue with wrog view direction, because when I made 180 degrees rotation on diagonal, I still see the model. but I must not see it, because camera must look at the another point opposit to the model. 

How do you think?


In Topic: How to get rid of camera z-axis rotation

Yesterday, 07:16 AM

Are headingDegrees, pitchDegrees and rollDegrees accumulators, or are they an instantaneous indication of how you are rotating?

 

This is just delta mouse position * rotation speed:

heading = -mouse.xPosRelative() * rotationSpeed;
		pitch = -mouse.yPosRelative() * rotationSpeed;
		roll = direction.x *cameraDX_Free->getCameraSpeedFlight() * elapsedTimeSec;
		cameraDX_Free->rotate(heading, pitch, 0.0f);

PARTNERS