frankie-on-platform/Sources/arm/Intro_cam.hx
2019-04-17 01:04:52 +02:00

130 lines
3.8 KiB
Haxe

package arm;
import iron.Scene;
import iron.math.Vec4;
import iron.math.Quat;
import iron.data.SceneFormat;
import iron.data.Data;
import iron.data.MeshData;
import iron.data.MaterialData;
import iron.system.Input;
import iron.system.Time;
import iron.system.Tween;
//
// Intro_cam : Animation for the begining
//
class Intro_cam extends iron.Trait {
public function new() {
super();
// Start
var go= false;
// Suiveur
var loc_init = new Vec4 (0 , 0, 0);
var loc_to = new Vec4 (0 , 0, 0);
var loc_from = new Vec4 (0 , 0, 0);
var deltaxyz = new Vec4 (0 , 0, 0);
var deltax = 0.0;
var deltay = 0.0;
var deltaz = 0.0;
var position = 0;
// Tempo
var duration_cycle=0.01;
var duration=0.0;
// Positions (repère objet de la courbe)
var delta = [
new Vec4 (0.0, 0.0, 0.0),
new Vec4 (-0.714604914188385, -1.9046026468276978, 0.36248692870140076),
new Vec4 (-0.2727598547935486, -3.9623684883117676, 0.6186656355857849),
new Vec4 (1.2784634828567505, -5.851366996765137, 0.7989855408668518),
new Vec4 (3.764294147491455, -7.323999881744385, 0.9349323511123657),
new Vec4 (6.88226318359375, -8.207002639770508, 1.0590277910232544),
new Vec4 (9.54699420928955, -8.419892311096191, 1.1722874641418457),
new Vec4 (12.064346313476562, -8.174274444580078, 1.3170785903930664),
new Vec4 (14.102925300598145, -7.484195232391357, 1.5114848613739014),
new Vec4 (15.088809967041016, -6.700578689575195, 1.7009670734405518),
new Vec4 (15.388349533081055, -6.067254543304443, 1.852500081062317),
new Vec4 (15.33479118347168, -5.358070373535156, 2.0269899368286133),
new Vec4 (14.867095947265625, -4.586199760437012, 2.226856231689453),
new Vec4 (14.457979202270508, -4.181393623352051, 2.337069272994995)
];
// Cible camera
// var target = new Vec4 (0 , 0, 0);
//
// notifyOnInit
//
notifyOnInit(function() {
loc_init = object.transform.loc;
duration=duration_cycle;
go= false;
});
//
// notifyOnUpdate
//
notifyOnUpdate(function() {
// Point 1
var mouse = Input.getMouse();
if (mouse.started()) {
position=1;
loc_from = object.transform.loc;
deltax = (delta[position].x-delta[position-1].x);
deltay = (delta[position].y-delta[position-1].y);
deltaz = (delta[position].z-delta[position-1].z);
deltaxyz.set(deltax, deltay, deltaz);
loc_to.addvecs(loc_from,deltaxyz);
trace("position "+Std.string(position));
trace("loc_from "+Std.string(loc_from));
trace("loc_to "+Std.string(loc_to));
trace("deltaxyz "+Std.string(deltaxyz));
trace("Delta "+Std.string(deltax)+" " +Std.string(deltay)+" " +Std.string(deltaz));
go= true;
}
// Déplacement
if (go) {
duration -= iron.system.Time.delta;
if (duration <= 0.0) {
object.transform.translate(deltax/100, deltay/100, deltaz/100); // x, y, z
duration=duration_cycle;
// Arrivée ?
if (loc_to.x - object.transform.loc.x < 0.01 && loc_to.y - object.transform.loc.y < 0.01 && loc_to.z - object.transform.loc.z < 0.01) {
object.transform.translate(loc_to.x - object.transform.loc.x, loc_to.y - object.transform.loc.y, loc_to.z - object.transform.loc.z);
// Point ++
if (position<13) {
position++;
loc_from = object.transform.loc;
deltax = (delta[position].x-delta[position-1].x);
deltay = (delta[position].y-delta[position-1].y);
deltaz = (delta[position].z-delta[position-1].z);
deltaxyz.set(deltax, deltay, deltaz);
loc_to.addvecs(loc_from,deltaxyz);
trace("position "+Std.string(position));
trace("loc_from "+Std.string(loc_from));
trace("loc_to "+Std.string(loc_to));
trace("deltaxyz "+Std.string(deltaxyz));
trace("Delta "+Std.string(deltax)+" " +Std.string(deltay)+" " +Std.string(deltaz));
go= true;
}
else go= false;
}
}}
});
}}