package arm; import iron.Scene; import iron.math.Vec4; import iron.math.Quat; import iron.math.Mat4; 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; import armory.trait.PhysicsBreak; // // Intro_cam : Animation for the begining // class Intro_cam extends iron.Trait { public function new() { super(); // Start var go= false; // Suiveur var loc_to = new Vec4 (); var loc_from = new Vec4 (); var deltaxyz = new Vec4 (); var scale = new Vec4 (); var deltax = 0.0; var deltay = 0.0; var deltaz = 0.0; var delta_a = 0.0; var delta_b = 0.0; var delta_c = 0.0; var position = 0; // Tempo var duration_cycle=0.01; var duration=0.0; // Positions (repère objet de la courbe (dump python)) 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 (2.2124, -6.7793, 0.95099); var rot_from = new Quat(); var rot_from2 = new Quat(); var rot_to = new Quat(); var rot_to2 = new Quat(); // // notifyOnInit // notifyOnInit(function() { duration=duration_cycle; go= false; }); // // notifyOnUpdate // notifyOnUpdate(function() { // Point 1 var mouse = Input.getMouse(); if (mouse.started()) { position=1; // Localisation 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)); // Rotation // object.transform.scale.z = -1; object.transform.buildMatrix(); rot_from.fromMat(iron.Scene.active.getChild("Target_pos0").transform.world); rot_from2.set(rot_from.x*1, rot_from.y*1, rot_from.z*1, rot_from.w*1); object.transform.rot.fromEuler(rot_from2.getEuler().x, rot_from2.getEuler().y, rot_from2.getEuler().z); object.transform.buildMatrix(); rot_to.fromMat(iron.Scene.active.getChild("Target_pos1").transform.world); rot_to2.set(rot_to.x*1, rot_to.y*1, rot_to.z*1, rot_to.w*1); trace("rot_from "+Std.string(rot_from2)); trace("rot_to "+Std.string(rot_to2)); delta_a = ((rot_to2.getEuler().x)-(rot_from2.getEuler().x)); delta_b = (rot_to2.getEuler().y-rot_from2.getEuler().y); delta_c = (rot_to2.getEuler().z-rot_from2.getEuler().z); // orientation_from.set(target.x-object.transform.world.getLoc().x, target.y-object.transform.world.getLoc().y, target.z-object.transform.world.getLoc().z); // orientation_to.set(target.x-object.transform.world.getLoc().x, target.y-object.transform.world.getLoc().y, target.z-object.transform.world.getLoc().z); // trace("object.transform.world.getLoc() "+Std.string(object.transform.world.getLoc())); // trace("target "+Std.string(target)); // orientation_from.set(target.x-object.transform.world.getLoc().x, target.y-object.transform.world.getLoc().y, target.z-object.transform.world.getLoc().z); // orientation_to.set(target.x-loc_from.x, target.y-loc_from.y, target.z-loc_from.z); // orientation_to.set(target.x-loc_to.x, target.y-loc_to.y, target.z-loc_to.z); // trace("orientation_from "+Std.string(orientation_from)); // trace("orientation_to "+Std.string(orientation_to)); // orientation_quat.fromTo(orientation_from, orientation_to); go= true; } // Déplacement if (go) { duration -= iron.system.Time.delta; if (duration <= 0.0) { object.transform.translate(deltax/100, deltay/100, deltaz/100); // Translation x, y, z object.transform.rotate(Vec4.xAxis(), delta_a/100); object.transform.rotate(Vec4.yAxis(), delta_b/100); object.transform.rotate(Vec4.zAxis(), delta_c/100); 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) { // Correction du point de départ 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++; trace("position "+Std.string(position)); // Localisation 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)); // Rotation rot_from.fromMat(iron.Scene.active.getChild("Target_pos"+Std.string(position-1)).transform.world); rot_from2.set(rot_from.x*1, rot_from.y*1, rot_from.z*1, rot_from.w*1); object.transform.rot.fromEuler(rot_from2.getEuler().x, rot_from2.getEuler().y, rot_from2.getEuler().z); object.transform.buildMatrix(); rot_to.fromMat(iron.Scene.active.getChild("Target_pos"+Std.string(position)).transform.world); rot_to2.set(rot_to.x*1, rot_to.y*1, rot_to.z*1, rot_to.w*1); trace("rot_from "+Std.string(rot_from2)); trace("rot_to "+Std.string(rot_to2)); delta_a = (rot_to2.getEuler().x-rot_from2.getEuler().x); delta_b = (rot_to2.getEuler().y-rot_from2.getEuler().y); delta_c = (rot_to2.getEuler().z-rot_from2.getEuler().z); go= true; } else go= false; } }} }); }}