Jump to content

Request Help ==>> covert local rotation to global rotation


photo

Recommended Posts

Request Help

 

To move the boat on the surface of the water waves on the boat

I wave height across the water and I have to manually rotate my boat

 

My problem is in the local and global direction

I need to convert global to local rotation

Link to comment

What do you mean by local rotation/direction ? A rotation expresses translational/rotational differences BETWEEN two ore more reference frames/coordinate systems. It would be very helpful if you could provide a simple drawing of your coordinate frames (world/local) to illustrate your problem.

Link to comment

This Code Used To Move Boat

 

 


#include <Project/scripts/euler.h>
#include <core/scripts/camera.h>
#include <math.h>[/color]
[color=#b22222]int init() {
CreateBoat();
SetPlayer();

Boat_UP.setTransform(transform);
Boat_UP.setPosition(vec3(0,0,0));
[/color]
[color=#b22222]return 1;
}
int update() {

  GetKeyState();
  quat r=Boat_UP.getRotation();
  ControlBoat();
return 1;
}
void GetPoint(){
vec3 pos=Boat_UP.getPosition();
float F,B, L,R;
float e1=(L_AngularVelocity + R_AngularVelocity+1.0f) ;
//===============================
B=water2.getHeight(vec3(pos.x-6,pos.y,0));
F=water2.getHeight(vec3(pos.x+6,pos.y,0));
//===============================
R=water2.getHeight(vec3(pos.x,pos.y+1.2f,pos.z+0.01f));
L= water2.getHeight(vec3(pos.x,pos.y-1.2f,pos.z+0.01f));
//===============================[/color]
[color=#b22222]Rot_X = ((L -R)*0.1f);
Rot_Y = ((F-B)*0.03f);
Rot_Z =( L_AngularVelocity - R_AngularVelocity)*0.01f+(farmoon*(L_AngularVelocity+R_AngularVelocity)/1000.0f);
//engine.message("  Rot_X= %2.3f  Rot_Y= %2.3f  Rot_Z= %2.3f \n\n",Rot_X,Rot_Y,Rot_Z);
}
void ControlBoat(){
 GetKeyState();
update_speed();
GetPoint();
 vec3 pos=Boat_UP.getPosition();
 vec3 dir=persecutor.getDirection();
//================================

pos.x+=((L_AngularVelocity+R_AngularVelocity)/400.0f)*dir.x;
pos.y+=((L_AngularVelocity+R_AngularVelocity)/400.0f)*dir.y;
pos.z=(pos.z-water2.getHeight(Boat_UP.getPosition()))/30.0f ;
Boat_UP.setPosition(pos);
setRot();



}
void setRot(){//
mat4  transform = Boat_UP.getTransform() *rotateY(Rot_Y) *  rotateX(Rot_X)* rotateZ(Rot_Z) ; 
 } 

}

}
[/color]





[color=#b22222]
Link to comment

Your code is quite hard to understand, but maybe this paper can provide a solution to your problem. Still - at least for me - your local rotation reference frame it unclear (as rotation definies attitude difference between 2 referenec frames)

Link to comment

Thank you

More details

I am using the following method to move the boat

Take four point

 

  	vec3 pos=Boat_UP.getPosition();
float F,B, L,R;
vec3 point1,point2,point3,point4 ;
point1=vec3(pos.x-6,pos.y,0)
point2=vec3(pos.x+6,pos.y,0)
point3=vec3(pos.x,pos.y+1.2f,pos.z+0.01f)
point4=vec3(pos.x,pos.y-1.2f,pos.z+0.01f)

Link to comment

And the wave height of the water in this four-point gain

//===============================
B=water2.getHeight(point1);
F=water2.getHeight(point2);
//===============================
R=water2.getHeight(point3);
L= water2.getHeight(point4);
//===============================

Water wave impact on the boat to do the following acts

Rot_X = ((L -R)*0.1f);
Rot_Y = ((F-B)*0.03f);
Rot_Z =( L_AngularVelocity - R_AngularVelocity)*0.01f+(farmoon*(L_AngularVelocity+R_AngularVelocity)/1000.0f);
mat4  transform = Boat_UP.getTransform() *rotateY(Rot_Y) *  rotateX(Rot_X)*rotateZ(Rot_Z) ;
Boat_UP.setTransform(transform );

Edited by mohsen.nikroo
Link to comment

Mohsen, it's really hard to understand your code, and it is not clear what the problem is and what do you want to get as a result.

 

Maybe if you explain it in a more clear way, attach screenshots (and draw how you want your boats to be rotated), we could help you. Right now we can't get you, sorry.

Link to comment
×
×
  • Create New...