1 import "mekanoobjectfixed"
2 import "mekanoobjectspring"
3 import "mekanopolygonalbox"
4 import "mekanoobjectgravity"
6 class MekanoWnd : Window
10 MekanoDisplay display { };
11 MekanoSimulation simulation { timeMultiplier = 4.0f };
13 MekanoObjectFixed fix;
14 fix = { simulation, position = { 300, 50 } };
15 MekanoPolygonalBox pbox;
16 pbox = { simulation, size = 20, mass = 10, inertiaMoment = 200 };
17 MekanoObjectSpring spring;
18 spring = { simulation, length = 60, restitution = 30 };
20 MekanoObjectGravity gravity { gravity = { 0, 10 } };
22 MekanoPolygonalBox lastbox;
23 bool selected, dragging, buttondown;
28 hasMaximize = true, hasMinimize = true, hasClose = true;
29 borderStyle = sizable;
30 clientSize = { 640, 480 };
31 background = slateGray;
33 BitmapResource bg { ":ecere.bmp", window = this };
37 RandomSeed((uint)(((uint64)(GetTime() * 1000)) & MAXDWORD));
38 pbox.position = { GetRandom(0,500), 110 };
39 spring.link(MekanoPoint { fix, type = center }, pbox.getCertainPoint(topPoint));
54 simulation.resetForces();
56 simulation.exertForces();
57 simulation.stepDelta();
59 if(!buttondown) dragging = false;
61 for(object : simulation.objectList)
63 ObjectAttributes attributes=object.attributes;
64 if(attributes.selected)
66 object.position = { mouse.x, mouse.y };
68 attributes.selected = false;
69 attributes.steady = false;
71 if(object.isInside({ mouse.x, mouse.y }))
73 attributes.highlighted = true;
77 attributes.selected = true;
78 attributes.steady = true;
83 attributes.selected = false;
84 attributes.highlighted = false;
86 object.attributes = attributes;
94 void OnRedraw(Surface surface)
96 //surface.Tile(bg.bitmap, 0, 0, clientSize.w, clientSize.h);
97 display.surface = surface;
98 simulation.render(display);
101 bool OnRightButtonDown(int x, int y, Modifiers mods)
104 fix = MekanoObjectFixed { simulation, position = { x, y } };
105 spring = { simulation, length = 30; restitution = 2; };
107 spring.link(MekanoPoint { fix, type = center }, pbox.centerPoint);
110 //int c; for(c = 0; c<400; c++) {
126 spring.link(lastbox.getCertainPoint(bottomPoint), pbox.getCertainPoint(topPoint));
132 bool OnLeftButtonUp(int x, int y, Modifiers mods)
139 bool OnLeftButtonDown(int x, int y, Modifiers mods)
146 bool OnMouseMove(int x, int y, Modifiers mods)
152 bool OnKeyDown(Key key, unichar ch)
156 case escape: Destroy(0); return false;
157 case f: ((GuiApplication)__thisModule.application).fullScreen ^= true; return false;