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 #if defined(__EMSCRIPTEN__) || defined(__ANDROID__)
29 anchor = { 0, 0, 0, 0 };
31 clientSize = { 640, 480 };
32 hasMaximize = true, hasMinimize = true, hasClose = true;
33 borderStyle = sizable;
35 background = slateGray;
37 // BitmapResource bg { ":ecere.bmp", window = this };
41 RandomSeed((uint)(((uint64)(GetTime() * 1000)) & MAXDWORD));
42 pbox.position = { GetRandom(0,500), 110 };
43 spring.link(MekanoPoint { fix, type = center }, pbox.getCertainPoint(topPoint));
58 simulation.resetForces();
60 simulation.exertForces();
61 simulation.stepDelta();
63 if(!buttondown) dragging = false;
65 for(object : simulation.objectList)
67 ObjectAttributes attributes=object.attributes;
68 if(attributes.selected)
70 object.position = { mouse.x, mouse.y };
72 attributes.selected = false;
73 attributes.steady = false;
75 if(object.isInside({ mouse.x, mouse.y }))
77 attributes.highlighted = true;
81 attributes.selected = true;
82 attributes.steady = true;
87 attributes.selected = false;
88 attributes.highlighted = false;
90 object.attributes = attributes;
98 void OnRedraw(Surface surface)
100 //surface.Tile(bg.bitmap, 0, 0, clientSize.w, clientSize.h);
101 display.surface = surface;
102 simulation.render(display);
105 bool OnRightButtonDown(int x, int y, Modifiers mods)
108 fix = MekanoObjectFixed { simulation, position = { x, y } };
109 spring = { simulation, length = 30; restitution = 2; };
111 spring.link(MekanoPoint { fix, type = center }, pbox.centerPoint);
114 //int c; for(c = 0; c<400; c++) {
130 spring.link(lastbox.getCertainPoint(bottomPoint), pbox.getCertainPoint(topPoint));
136 bool OnLeftButtonUp(int x, int y, Modifiers mods)
143 bool OnLeftButtonDown(int x, int y, Modifiers mods)
150 bool OnMouseMove(int x, int y, Modifiers mods)
156 bool OnKeyDown(Key key, unichar ch)
160 case escape: Destroy(0); return false;
161 case f: ((GuiApplication)__thisModule.application).fullScreen ^= true; return false;