# Rotate model with mouse

Its just maths really…

1 Like

But vector in 3D space.

1. get cam direction (vector) and projection of the vector onto the plane (new vector)
2. rotate
3. get cam direction (vector) and projection of the vector onto the plane (new vector) 2
4. get angle
5. rotate model

I did not get this way…

1 Like
1. translate vector 3d to simple vector
2. rotate
3. get new vector 3d translate to simple vector
4. get angle

vector1 (z1,x1)
vector2(z2,x2)

Vmod = z1x1 + z2x2

V1 = sqrt(z1z1 + x1x1)

V2 = sqrt(z2z2 + x2x2)

cos = Vmod/V1*V1

1 Like
1 Like

I have varibles:

``````camRotation.getX()
camRotation.getY()
camRotation.getZ()
camRotation.getW()

camDir.getX();
camDir.getY()
camDir.getZ()

camLeft.getX()
camLeft.getY()
camLeft.getZ()
``````

can i rotate model with this variables?

``        characterModel.rotate(0.0f, camRotationY, 0.0f);``
1 Like

Quaternion values are magic. Do not try to interpret meaning from them.
Quaternion values are magic. Do not try to interpret meaning from them.
Quaternion values are magic. Do not try to interpret meaning from them.
Quaternion values are magic. Do not try to interpret meaning from them.
Quaternion values are magic. Do not try to interpret meaning from them.

Repeat as needed.

But since you don’t know where the javadoc is… I’m not sure I want to be your google.

1 Like

Method

``````/**
* Retun radian angle between two 2 vectors (get from Vector 3d)
* @param x1
* @param y1
* @param x2
* @param y2
* @return
*/
public float getRotation(float x1,float y1,float x2,float y2){
float Vmod = x1*y1 + x2*y2;
float V1   = (float) Math.sqrt(x1*x1 + y1*y1);
float V2   = (float) Math.sqrt(x2*x2 + y2*y2);

float cos  =  Vmod/V1*V2;

float radian = (float) (cos *  Math.PI / 180);

}``````
1 Like

mySpatial =…

float moustMovedLeftRight = …

mySpatial.rotate(0, moustMovedLeftRight * turnSpeed, 0);

1 Like

I need get angles for character model from camera rotation and direction.

float moustMovedLeftRight = …

angle… but witch formula

1 Like

float mouseMovedLeftRight = mousePosition.x - lastMousePosition.x

I think one of two things are happening:

1. you are making this WAY more complicated than it needs to be.
2. you have not provided enough information.

I know for a fact that number (2) is true. I don’t know about number (1), though.

1 Like

I have variables this is camera vectors.

and

camLeftOld = camLeft;

``````        camRotation = new Quaternion(camRotationX, camRotationY, camRotationZ, camRotationW);
camDir      = new Vector3f(camDirectionX, camDirectionY, camDirectionZ);
camLeft     = new Vector3f(camLeftX, camLeftY, camLeftZ);
``````

and this

characterModel.rotate(0.0f, camRotationY, 0.0f);

1 Like

not mouse move

character model rotation by camera (mouse)

if i oldMouse.x - newMuse.x = number

i need angle between vectors

1 Like

I think

``````float[] camAngles = camRotation.toAngles(null);

float rotationY = camAngles;

//localRotation.multL

characterModel.rotate(0.0f, rotationY, 0.0f);``````
1 Like

We don’t know what you are trying to do or why you have to go through 20 strange steps to do it.

Maybe you are trying to reuse too much. It seems really strange to me to use camera movement to rotate your spatial when you could just hook it up directly and avoid the 20 different math steps between you and the mouse.

1 Like

i need rotate model with camera left right move.

rotate variables:

1. Quaternion
2. angles
1 Like

Work this
float[] camAngles = camRotation.toAngles(null);

``````        float rotationY = camAngles;

float rotateCharacter = rotationYOld - rotationY;

rotationYOld = rotationY;

//Quaternion localRotation = new Quaternion(-0.173f, rotationY, -0.002364515f, 0.9830f);

//localRotation.multL

characterModel.rotate(0.0f, rotateCharacter, 0.0f);
``````

But character must be rotate with camera direction

1 Like

use lookAt method for this. but no clue what you are doing, to talk to you is like talking with robot. We suggest something and you make a different proposal. So I fear nobody is really able to help you, maybe a huge language barrier…

1 Like

for example?
model.spatial.getLocalRotation().lookAt( destination, up );

what in destination variable and up variable?

1 Like

Hey @nnpa, you are maybe thinking way to complicated.
The following is out of my head. This might be an approach how to get what you want:

``````float[] angles = new float;
cam.getRotation().toAngles(angles); // we get the cam angles here
angles = 0; // you don't want to rotate along the x-axis, so we set it to 0
angles = 0; // you don't want to rotate along the z-axis, so we set it to 0
player.setLocalRotation(player.getLocalRotation().fromAngles(angles)); // apply new player rot``````
2 Likes

Work good.

1 Like