Skip to content
This repository was archived by the owner on Apr 13, 2024. It is now read-only.

Commit bd15416

Browse files
author
celian
committed
problem of camera rotation solved
1 parent 08dbef0 commit bd15416

4 files changed

Lines changed: 70 additions & 20 deletions

File tree

Rando/Rando.Builds.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ RANDO.Builds.route = function(scene, vertices, cam_b, lin_b, sph_b, cyl_b, pan_
9292
);
9393

9494
// Current position of the camera : the first point
95+
scene.activeCamera.rotation = new BABYLON.Vector3.Zero();
9596
var position = scene.activeCamera.position;
9697
// Target of the camera : the fourth point
9798
var target = new BABYLON.Vector3(

Rando/Rando.Utils.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ RANDO.Utils.angleFromAxis = function(A, B, axis){
144144
);
145145

146146
angle = Math.acos(AH/AB);
147+
//if (angle > Math.PI/2)
148+
//angle = -((Math.PI/2)-angle)
147149
if (B.x < A.x)
148150
return -angle;
149151
return angle;
@@ -211,7 +213,7 @@ RANDO.Utils.initCamera = function(scene){
211213
var camera = new BABYLON.FreeCamera("Camera", new BABYLON.Vector3(0, 0, 0), scene);
212214
camera.checkCollisions = true;
213215
camera.maxZ = 10000;
214-
camera.speed = 5;
216+
camera.speed = 20;
215217
camera.keysUp = [90]; // Touche Z
216218
camera.keysDown = [83]; // Touche S
217219
camera.keysLeft = [81]; // Touche Q
@@ -230,7 +232,7 @@ RANDO.Utils.initCamera = function(scene){
230232
* return the camera
231233
* */
232234
RANDO.Utils.animateCamera = function(vertices, cam_z_off, scene){
233-
var fpk = 10; // Time to go from a point to another (frame per key)
235+
var fpk = 20; // Time to go from a point to another (frame per key)
234236
var fps = 30; // Frame per Second
235237
var d = 5 // Distance between the current point and the point watched
236238
scene.activeCamera.position.y += cam_z_off;
@@ -254,17 +256,31 @@ RANDO.Utils.animateCamera = function(vertices, cam_z_off, scene){
254256
);
255257

256258
// Arrays with all animation keys
257-
var keys_rot = [];
259+
var keys_rot = [];
258260
var keys_tr = [];
259261
for (var i = 0; i < vertices.length-d; i+=d){
260-
var a = vertices[i];
261-
var b = vertices[i+d];
262+
var a = vertices[i],
263+
b = vertices[i+d],
264+
alpha1,
265+
alpha2 = RANDO.Utils.angleFromAxis(a, b, BABYLON.Axis.Y);
266+
267+
if(i!=0){
268+
alpha1 = keys_rot[(i/d)-1].value;
269+
// Correction of a particular case
270+
if(alpha1*alpha2<0 && Math.abs(alpha1) > Math.PI/2 && Math.abs(alpha2) > Math.PI/2){
271+
alpha2 = (2*Math.PI - Math.abs(alpha2));
272+
}
273+
}
274+
275+
console.log("Vertice "+ i);
276+
console.log(vertices[i], vertices[i+d])
277+
console.log(alpha2*180/Math.PI);
262278
keys_rot.push({
263-
frame: i*fpk,
264-
value: RANDO.Utils.angleFromAxis(a, b, BABYLON.Axis.Y)
279+
frame : (i/d)*fpk,
280+
value : alpha2
265281
});
266282
keys_tr.push({
267-
frame: i*fpk,
283+
frame: (i/d)*fpk,
268284
value: new BABYLON.Vector3(
269285
a.x,
270286
a.y + cam_z_off,

index.html

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,49 @@
1010
height: 100%;
1111
padding: 0;
1212
margin: 0;
13+
font-family: arial;
1314
}
1415
canvas {
1516
display:block;
1617
}
18+
div {
19+
border-radius: 3px;
20+
}
1721
#menu {
1822
position: absolute;
1923
top: 10px;
2024
left: 10px;
21-
height: 100px;
22-
width : 500px;
25+
height: auto;
26+
width: 400px;;
27+
background-color: rgba(255,255,255, 0.8);
28+
padding: 5px;
29+
text-align: center;
30+
font-size: 20px;
31+
2332
}
24-
#menu span {
25-
display: inline-block;
26-
opacity: 0.8;
27-
background-color: white;
33+
#menu .choice {
34+
float: left;
35+
padding: 5px;
36+
margin: 5px;
37+
background-color: rgba(100,100,100, 0.8);
38+
font-size: 18px;
39+
color: white;
40+
}
41+
42+
#infos {
43+
position: absolute;
44+
top: 10px;
45+
right: 10px;
46+
height: auto;
47+
width : 300px;
48+
background-color: rgba(255,255,255, 0.8);
49+
padding : 5px;
50+
51+
}
52+
#infos span{
53+
float: left;
54+
width: 100%;
2855
}
29-
3056
</style>
3157
<script src="lib/jquery-1.9.1.js"></script>
3258
<!-- BABYLON-->
@@ -44,10 +70,17 @@
4470
<canvas id="canvas_renderer"></canvas>
4571
</div>
4672
<div id="menu">
47-
<span data-id="903488">Le vallon de Vaccivier</span>
48-
<span data-id="903469">Le refuge de la Lavey</span>
73+
<span> <b>Choix du Modèle Numérique Terrain</b> </span>
74+
<span data-id="903488" class = "choice">Le vallon de Vaccivier</span>
75+
<span data-id="903469" class = "choice">Le refuge de la Lavey</span>
4976
</div>
50-
77+
78+
<div id="infos">
79+
<span><b>Q, Z, S, D </b>: se déplacer </span>
80+
<span><b>Espace</b>: play/pause survol de la caméra </span>
81+
<span><b>Entrée</b>: retour au départ </span>
82+
</div>
83+
5184
<script src="index.js"></script>
5285
</body>
5386

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* python -m SimpleHTTPServer
2424
* to launch in chromium
2525
* */
26-
$("#menu span").click(function() {
26+
$("#menu .choice").click(function() {
2727
var id = $(this).data('id');
2828

2929
// clear engine if it contains something
@@ -114,4 +114,4 @@ $("#menu span").click(function() {
114114
scene.render();
115115
});
116116
});
117-
$("#menu span:first").click();
117+
$("#menu .choice:first").click();

0 commit comments

Comments
 (0)