Quaternion.hx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. class Quaternion extends hxd.App {
  2. var cube : h3d.scene.Mesh;
  3. var tx : Float = 0.;
  4. var ty : Float = 0.;
  5. var tz : Float = 0.;
  6. override function init() {
  7. var p = new h3d.prim.Cube(1, 1, 1);
  8. p.translate( -0.25, -0.5, -0.5);
  9. p.addUVs();
  10. p.addNormals();
  11. cube = new h3d.scene.Mesh(p, s3d);
  12. cube.material.texture = h2d.Tile.fromColor(0x808080).getTexture();
  13. var axis = new h3d.scene.Object(s3d);
  14. var ax = new h3d.scene.Box(0xFFFF0000, true, axis);
  15. ax.x = 0.5;
  16. ax.scaleY = 0.001;
  17. ax.scaleZ = 0.001;
  18. var ay = new h3d.scene.Box(0xFF00FF00, true, axis);
  19. ay.y = 0.5;
  20. ay.scaleX = 0.001;
  21. ay.scaleZ = 0.001;
  22. var az = new h3d.scene.Box(0xFF0000FF, true, axis);
  23. az.z = 0.5;
  24. az.scaleX = 0.001;
  25. az.scaleY = 0.001;
  26. var ax = new h3d.scene.Box(0xFF800000, true, cube);
  27. ax.x = 0.5;
  28. ax.scaleY = 0.001;
  29. ax.scaleZ = 0.001;
  30. var ay = new h3d.scene.Box(0xFF008000, true, cube);
  31. ay.y = 0.5;
  32. ay.scaleX = 0.001;
  33. ay.scaleZ = 0.001;
  34. var az = new h3d.scene.Box(0xFF000080, true, cube);
  35. az.z = 0.5;
  36. az.scaleX = 0.001;
  37. az.scaleY = 0.001;
  38. var ldir = new h3d.Vector( -1, -2, -5);
  39. ldir.normalize();
  40. /*
  41. cube.material.lightSystem = {
  42. ambient : new h3d.Vector(0.5, 0.5, 0.5),
  43. points : [],
  44. dirs : [{
  45. dir : ldir,
  46. color : new h3d.Vector(1, 1, 1),
  47. }],
  48. };
  49. */
  50. }
  51. var time = 0.;
  52. override function update(dt:Float) {
  53. time += dt * 0.6;
  54. var q = new h3d.Quat();
  55. var d = new h3d.Vector( Math.cos(time), Math.sin(time), Math.cos(time / 3) * 0.1);
  56. q.initDirection(d);
  57. cube.setRotationQuat(q);
  58. }
  59. static function main() {
  60. new Quaternion();
  61. }
  62. }