samples/guiAndGfx: eC port of JFD's Mekano
[sdk] / samples / guiAndGfx / mekano / mekanopoint.ec
diff --git a/samples/guiAndGfx/mekano/mekanopoint.ec b/samples/guiAndGfx/mekano/mekanopoint.ec
new file mode 100644 (file)
index 0000000..4861087
--- /dev/null
@@ -0,0 +1,39 @@
+import "vector"
+import "mekanoobject"
+
+public enum MekanoPointType { unknown, center, vertex };
+
+class MekanoPoint : struct // TOFIX: Container issues with this : private Vector2D
+{
+private:
+   Vector2D pt;
+   MekanoPointType m_Type;
+   MekanoObject m_pObject;
+   Vector2D m_LastLocalPosition;
+   Vector2D m_LocalPosition;
+   Vector2D m_ScreenPosition;
+
+public:
+   property MekanoObject object          { set { m_pObject = value; value.addPoint(this); } get { return m_pObject; } }
+   property MekanoPointType type         { set { m_Type = value; } get { return m_Type; } }
+   property float x                      { set { pt.x = value; } get { return pt.x; } }
+   property float y                      { set { pt.y = value; } get { return pt.y; } }
+
+   property Vector2D lastLocalPosition   { set { m_LastLocalPosition = value; } }
+   property Vector2D localPosition       { get { value = m_LocalPosition; } }
+   property Vector2D deltaLocalPosition  { get { value.subtract(m_LocalPosition, m_LastLocalPosition); } }
+   property Vector2D screenPosition      { get { value.add(m_LocalPosition, m_pObject.position); } }
+   property Vector2D deltaScreenPosition { get { value.add(deltaLocalPosition, m_pObject.deltaPosition); } }
+
+   void computeLocalPosition()
+   {
+      m_LocalPosition = { x*m_pObject.cosRotation - y * m_pObject.sinRotation, x*m_pObject.sinRotation + y*m_pObject.cosRotation };
+   }
+
+   void computeBoundingRadius()
+   {
+      float l = pt.length;
+      if(m_pObject.boundingRadius < l)
+         m_pObject.boundingRadius = l;
+   }
+};