1 module testbed.physicsentity; 2 3 import dlib.core.memory; 4 import dlib.math.vector; 5 import dlib.math.matrix; 6 import dgl.core.interfaces; 7 import dgl.graphics.entity; 8 import dgl.graphics.material; 9 import dmech.rigidbody; 10 import dmech.shape; 11 12 class PhysicsEntity: Entity 13 { 14 ShapeComponent shape; 15 RigidBody rbody; 16 Material material; 17 bool useMaterial = true; 18 19 this(Drawable d, RigidBody rb, uint shapeIndex = 0) 20 { 21 rbody = rb; 22 23 if (rbody.shapes.length > shapeIndex) 24 { 25 shape = rbody.shapes[shapeIndex]; 26 } 27 28 if (shape) 29 super(d, shape.position); 30 else 31 super(d, Vector3f(0, 0, 0)); 32 } 33 34 override void draw(double dt) 35 { 36 if (shape !is null) 37 transformation = shape.transformation; 38 else 39 transformation = Matrix4x4f.identity; 40 super.draw(dt); 41 } 42 43 override void drawModel(double dt) 44 { 45 if (material && useMaterial) 46 material.bind(dt); 47 super.drawModel(dt); 48 if (material && useMaterial) 49 material.unbind(); 50 } 51 52 override void free() 53 { 54 Delete(this); 55 } 56 }