Bonsoir,
Je suis en train d'essayer d'implémenter les rotations sur les axes X, Y et Z d'un objet 3D.
Je veux programmer la rotation sur le pitch, roll et yaw.
Ce que j'ai fait dans un premier temps correspond à cela :
-je remets l'objet au centre (0,0,0)
-j'applique une rotation sur l'axe X, Y ou Z
-puis enfin je le remets à sa place.
Mais, cela est très limite quand on veut appliquer plusieurs rotations... Il faudra mettre à jour aussi les positions des axes qui subissent la rotation
J'ai cherché partout sur internet pour implémenter cela notamment avec les formules trigonométriques, mais ça ne marche pas comme je veux...
Voilà tout ce que j'ai pu faire :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
 
if (current_event.key.keysym.sym == SDLK_u)
{
	t = physics[scene["mario"]]->getWorldTransform();
	((btRigidBody *)physics[scene["mario"]])->setMotionState(new btDefaultMotionState(t));
 
 
	scene["mario"]->translate(-x, -y, -z);
	scene["mario"]->rotate(pitch, +0.05);
	float oldy, oldz;
	pitchAng += 0.05;
	oldy = yaw.y; oldz = yaw.z;
	yaw.y = oldy * cos(+0.05) - oldz * sin(+0.05);
	yaw.z = oldy * sin(+0.05) + oldz * cos(+0.05);
 
	oldy = roll.y; oldz = roll.z;
	roll.y = oldy * cos(+0.05) - oldz * sin(+0.05);
	roll.z = oldy * sin(+0.05) + oldz * cos(+0.05);
 
	scene["mario"]->translate(x, y, z);
	physics.setModelMatrix(scene["mario"]);
 
 
	cout << " PITCH ANGLE " << pitchAng << endl;
	cout << " YAW " << yaw.x << " " << yaw.y << " " << yaw.z << endl;
	cout << " ROLL " << roll.x << " " << roll.y << " " << roll.z << endl;
}
if (current_event.key.keysym.sym == SDLK_i)
{
	btTransform t = physics[scene["mario"]]->getWorldTransform();
	((btRigidBody *)physics[scene["mario"]])->setMotionState(new btDefaultMotionState(t));
 
 
	scene["mario"]->translate(-x, -y, -z);
	scene["mario"]->rotate(yaw, +0.05);
	yawAng += 0.05;
	float oldx, oldz;
	oldx = roll.x; oldz = roll.z;
	roll.x = oldx * cos(+0.05) + oldz * sin(+0.05);
	roll.z = oldx * -sin(+0.05) + oldz * cos(+0.05);
 
	oldx = pitch.x; oldz = pitch.z;
	pitch.x = oldx * cos(+0.05) + oldz * sin(+0.05);
	pitch.z = oldx * -sin(+0.05) + oldz * cos(+0.05);
 
	scene["mario"]->translate(x, y, z);
	physics.setModelMatrix(scene["mario"]);
 
}
if (current_event.key.keysym.sym == SDLK_o)
{
	btTransform t = physics[scene["mario"]]->getWorldTransform();
	((btRigidBody *)physics[scene["mario"]])->setMotionState(new btDefaultMotionState(t));
 
 
	scene["mario"]->translate(-x, -y, -z);
	scene["mario"]->rotate(roll, +0.05);
	rollAng += 0.05;
	float oldx, oldy;
	oldx = pitch.x; oldy = pitch.y;
	pitch.x = oldx * cos(DegToRad(.05)) - oldy * sin(DegToRad(.05));
	pitch.y = oldx * sin(+DegToRad(.05)) + oldy * cos(+DegToRad(.05));
 
	oldx = yaw.x; oldy = yaw.y;
	yaw.x = oldx * cos(+DegToRad(.05)) - oldy * sin(+DegToRad(.05));
	yaw.y = oldx * sin(+DegToRad(.05)) + oldy * cos(+DegToRad(.05));
 
	scene["mario"]->translate(x, y, z);
	physics.setModelMatrix(scene["mario"]);
}

Est-ce que vous avez des pistes pour implémenter cela?
Merci