Permalink
Browse files

Add support for DrawStuff Library in ODE

  • Loading branch information...
1 parent 68ac322 commit 5fde867a25e8c37f496482c115bbc98603125d97 @Teslos Teslos committed Sep 18, 2013
View
@@ -0,0 +1,26 @@
+#!/usr/bin/env io
+
+// drawstuff.io - A simple DrawStuff test program
+// (C) ∃teslos 2013
+ODE
+DrawStuff
+
+DrawStuffApp := DrawStuff clone do(
+ appendProto(DrawStuff)
+
+ start := method(xyz, hpr,
+ xyz := vector(0,0,0)
+ hpr := vector(0,0,0)
+ dsGetViewpoint(xyz, hpr)
+ dsSetViewpoint(xyz, hpr)
+ )
+ step := nil
+ run := method(
+ writeln("Running run method")
+ eventTarget(self)
+ self dsSimulationLoop(400,400)
+ )
+)
+
+//DrawStuffApp clone run
+
@@ -0,0 +1,79 @@
+#!/usr/bin/env io
+
+// drawstuff.io - A simple DrawStuff test program
+// (C) ∃teslos 2013
+// Based on dstest in ode-0.12 distribution
+
+ODE
+DrawStuff
+
+DrawStuffApp := DrawStuff clone do(
+ appendProto(DrawStuff)
+
+ start := method(xyz, hpr,
+ xyz := vector(0,0,0)
+ hpr := vector(0,0,0)
+ dsGetViewpoint(xyz, hpr)
+ dsSetViewpoint(xyz, hpr)
+ )
+ a := Number clone
+ step := method(paused,
+ DS_WOOD := 1
+ DS_NONE := 0
+ pi := Number constants pi
+ if(paused==0, a = a + 0.02)
+ if(a > 2*pi, a = a - 2*pi)
+ ca := a cos
+ sa := a sin
+ dsSetTexture(DS_WOOD)
+
+ b := if(a > pi, 2*(a-pi), a*2)
+ pos := vector(-0.3,0, (0.1*(2*pi*b-b*b)+0.65))
+ R := Vector clone setSize(12)
+ R atPut(0,ca); R atPut(1,0); R atPut(2,-sa)
+ R atPut(4,0 ); R atPut(5,1); R atPut(6, 0)
+ R atPut(8,sa); R atPut(9,0); R atPut(10,ca)
+ dsSetColor(1.0,0.8,0.6)
+ dsDrawSphere(pos,R,0.3)
+ dsSetTexture(DS_WOOD)
+
+ // draw the box
+ pos := vector(-0.2, 0.8, 0.4)
+ sides := vector(0.1,0.4,0.8)
+ // define the rotation matrix
+ R atPut(0,ca); R atPut(1,-sa); R atPut(2, 0)
+ R atPut(4,sa); R atPut(5, ca); R atPut(6, 0)
+ R atPut(8, 0); R atPut(9, 0); R atPut(10,1)
+ dsSetColor(0.6,0.6,1);
+ dsDrawBox(pos, R, sides)
+
+ // draw the cylinder
+ r := 0.3
+ d := (a*2) cos * 0.4;
+ cd := (-d/r) cos
+ sd := (-d/r) sin
+ pos := vector(-0.2,-1+d,0.3)
+ R atPut(0, 0); R atPut(1, 0); R atPut(2,-1)
+ R atPut(4,-sd); R atPut(5,cd); R atPut(6, 0)
+ R atPut(8, cd); R atPut(9,sd); R atPut(10,0)
+ dsSetColor(0.4,1,1)
+ dsDrawCylinder(pos,R, 0.8,r)
+
+ // draw capsule
+ pos := vector(0,0,0.2)
+ R atPut(0,0); R atPut(1,sa); R atPut(2,-ca)
+ R atPut(4,0); R atPut(5,ca); R atPut(6, sa)
+ R atPut(8,1); R atPut(9, 0); R atPut(10, 0)
+ dsSetColor(1,0.9,0.2)
+ dsDrawCapsule(pos,R,0.8, 0.2)
+
+ )
+
+ run := method(
+ eventTarget(self)
+ self dsSimulationLoop(400,400)
+ )
+)
+
+DrawStuffApp clone run
+
@@ -0,0 +1,32 @@
+#!/usr/bin/env io
+
+
+ODE
+DrawStuff
+
+DrawStuffSampleApp := DrawStuff clone do(
+appendProto(ODE)
+
+step := method(paused,
+ radius := 0.4
+ dsSetColor(1.0,0.0,0.0)
+ pos := vector(0.0,0.0,0.6)
+ R := Vector clone setSize(12)
+ R atPut(0,1); R atPut(5,1); R atPut(10,1);
+ dsDrawSphere(pos,R,radius)
+)
+
+start := method(
+ xyz := vector(0.0,-3.0,1.0)
+ hpr := vector(90.0,0.0,0.0)
+ dsSetViewpoint(xyz, hpr)
+)
+
+run := method(
+ eventTarget(self)
+ dsSimulationLoop(352,288)
+)
+)
+
+DrawStuffSampleApp run
+
@@ -0,0 +1,67 @@
+#!/usr/bin/env io
+
+# Port of http://pyode.sourceforge.net/tutorials/tutorial2.html
+// (C) ∃teslos 2013
+// Based on tutorial2.io
+// Based on glballs.io - A simple program (C) 2002 Mike Austin
+ODE
+DrawStuff
+
+# Create a world object
+world := ODEWorld clone
+world setGravity(0,0, -9.81)
+
+# Create two bodies
+body1 := world Body clone
+body1 setMass(ODEMass clone setSphereMass(1, 0.05))
+body1 setPosition(0, 1, 2)
+
+body2 := world Body clone
+body2 setMass(ODEMass clone setSphereMass(1, 0.05))
+body2 setPosition(0, 2, 2)
+
+# Connect body1 with the static environment
+jg := world JointGroup clone
+j1 := jg Ball clone
+j1 attach(body1)
+j1 setAnchor(0, 0, 2)
+
+# Connect body2 with body1
+j2 := jg Ball clone
+j2 attach(body1, body2)
+j2 setAnchor(0, 2, 2)
+
+
+# DrawStuff events object
+Screen := DrawStuff clone do(
+ appendProto(DrawStuff)
+ width ::= 512
+ height ::= 512
+
+ start := method(xyz, hpr,
+ xyz := vector(0,0,0)
+ hpr := vector(0,0,0)
+ dsGetViewpoint(xyz, hpr)
+ dsSetViewpoint(xyz, hpr)
+ )
+
+ step := method(paused,
+ world step(0.01)
+ DS_WOOD := 1
+ dsSetTexture(DS_WOOD)
+ R := Vector clone setSize(12)
+ R atPut(0,1); R atPut(5,1); R atPut(10,1)
+ dsSetColor(1.0,0.8,0.6)
+ pos1 := body1 position + vector(0.0, 0, 1)
+ pos2 := body2 position + vector(0.0, 0, 1)
+ dsDrawSphere(pos1, R, 0.3 )
+ dsDrawSphere(pos2, R, 0.3 )
+ )
+
+ run := method(
+ eventTarget(self)
+ self dsSimulationLoop(width, height)
+ )
+)
+
+Screen run
Oops, something went wrong.

0 comments on commit 5fde867

Please sign in to comment.