| 1 |
crank=this.scene.nodes.getByName("manivelle-1-1"); |
| 2 |
cross=this.scene.nodes.getByName("croix-1-1"); |
| 3 |
|
| 4 |
function cntrClockWise(){dir=1; speed=lastspeed;} |
| 5 |
function pause(){if(speed)lastspeed=speed; speed=0;} |
| 6 |
function clockWise(){dir=-1; speed=lastspeed;} |
| 7 |
function scaleSpeed(s){lastspeed*=s; if(speed) speed=lastspeed;} |
| 8 |
function origSpeed(){lastspeed=1; if(speed) speed=lastspeed;} |
| 9 |
|
| 10 |
Ocrank=new Vector3(-0.025, 0, 0); |
| 11 |
Ocross=new Vector3(0.025, 0, 0); |
| 12 |
|
| 13 |
axeZ=new Vector3(0,0,1); |
| 14 |
mx4x4=new Matrix4x4(); |
| 15 |
|
| 16 |
var omega0=Math.PI; // init. angular frequency (half turn per second) |
| 17 |
var dir=1; // init. direction |
| 18 |
var speed=0; // speed multiplier |
| 19 |
var lastspeed=1; |
| 20 |
var alpha=0; |
| 21 |
|
| 22 |
timeEvHnd=new TimeEventHandler(); |
| 23 |
timeEvHnd.onEvent=function(event) { |
| 24 |
var dalpha=dir*speed*omega0*event.deltaTime; |
| 25 |
if (dalpha!=0){ |
| 26 |
mx4x4.setIdentity(); |
| 27 |
mx4x4.rotateAboutLineInPlace(alpha,Ocrank,axeZ); |
| 28 |
crank.transform.set(mx4x4); |
| 29 |
with (Math){ |
| 30 |
if (alpha<3*PI/2) beta=0; |
| 31 |
else beta=-atan(sin(alpha+PI/4)/(sqrt(2)-cos(alpha+PI/4)))+PI/4; |
| 32 |
} |
| 33 |
mx4x4.setIdentity(); |
| 34 |
mx4x4.rotateAboutLineInPlace(beta,Ocross,axeZ); |
| 35 |
cross.transform.set(mx4x4); |
| 36 |
alpha+=dalpha+2*Math.PI; |
| 37 |
alpha%=2*Math.PI; |
| 38 |
scene.update(); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
runtime.addEventHandler(timeEvHnd); |