Example #1
0
		public Line(float[] start_0, float[] end_1):base() {
			
			this.loc = new Vector2f(0, 0);
			this.closest = new Vector2f(0, 0);
			this.type = ShapeType.LINE_SHAPE;
			Set(start_0, end_1);
		}
Example #2
0
		public static Vector2f ElasticForce(Vector2f displacement,
				float forceConstant) {
			float forceX = -forceConstant * displacement.GetX();
			float forceY = -forceConstant * displacement.GetY();
			Vector2f theForce = new Vector2f(forceX, forceY);
			return theForce;
		}
		public PConcavePolygonShape(float[] xvers, float[] yvers, float density) {
			fig = new PFigure();
			tri = new PTriangulator();
			poly = new PPolygonizer();
			numVertices = xvers.Length;
			localVers = new Vector2f[numVertices];
			vers = new Vector2f[numVertices];
			_dens = density;
			for (int i = 0; i < numVertices; i++) {
				localVers[i] = new Vector2f(xvers[i], yvers[i]);
				vers[i] = new Vector2f(xvers[i], yvers[i]);
			}
	
			fig.Figure(localVers, numVertices);
			numVertices = fig.numVertices;
			localVers = new Vector2f[numVertices];
			vers = new Vector2f[numVertices];
			for (int i_0 = 0; i_0 < numVertices; i_0++) {
				localVers[i_0] = new Vector2f(fig.done[i_0].x, fig.done[i_0].y);
				vers[i_0] = new Vector2f(fig.done[i_0].x, fig.done[i_0].y);
			}
			tri.Triangulate(fig.done, fig.numVertices);
			poly.Polygonize(tri.triangles, tri.numTriangles);
			convexes = new PConvexPolygonShape[1024];
			for (int i_1 = 0; i_1 < poly.numPolygons; i_1++) {
				convexes[i_1] = new PConvexPolygonShape(poly.polygons[i_1].xs,
						poly.polygons[i_1].ys, _dens);
			}
			numConvexes = poly.numPolygons;
			CalcMassData();
			_type = PShapeType.CONCAVE_SHAPE;
		}
Example #4
0
        public Line(Vector2f start_0, Vector2f end_1)
            : base()
        {
			this.loc = new Vector2f(0, 0);
			this.closest = new Vector2f(0, 0);
			Set(start_0, end_1);
		}
Example #5
0
		public static LNScaleTo Action(float duration, Vector2f s) {
			LNScaleTo to = new LNScaleTo();
			to._duration = duration;
			to._endX = s.x;
			to._endY = s.y;
			return to;
		}
Example #6
0
		public PPhysManager(float s, float gx, float gy) {
			this.world = new PPhysWorld();
			this.gravity = new Vector2f(gx, gy);
			this.start = false;
			this.enableGravity = true;
			this.scale = s;
		}
		private PPolygonPolygonCollider.PWContactedVertex [] ClipEdge(PPolygonPolygonCollider.PWContactedVertex [] clips,
				Vector2f normal, float dist) {
			PPolygonPolygonCollider.PWContactedVertex [] line = new PPolygonPolygonCollider.PWContactedVertex [2];
			int numClips = 0;
			float dist0 = normal.Dot(clips[0].v) - dist;
			float dist1 = normal.Dot(clips[1].v) - dist;
			if (dist0 < 0.0F) {
				line[numClips] = clips[0];
				numClips++;
			}
			if (dist1 < 0.0F) {
				line[numClips] = clips[1];
				numClips++;
			}
			if (numClips == 0)
				return null;
			if (numClips == 2)
				return line;
			int c = 0;
			if (dist0 < 0.0F && dist1 > 0.0F)
				c = 1;
			float d = dist0 / (dist0 - dist1);
			line[1] = new PPolygonPolygonCollider.PWContactedVertex ();
			line[1].v = clips[1].v.Sub(clips[0].v).Clone();
			line[1].v.MulLocal(d);
			line[1].v.AddLocal(clips[0].v);
			line[1].data = clips[c].data;
			return line;
		}
 public LObjectCamera(RectBox r, object f, int width, int height,
         int horBorderPixel_0, int vertBorderPixel_1, Vector2f maxSpeed_2)
 {
     this.cameraX = 0;
     this.cameraY = 0;
     this.renderWidth = width;
     this.renderHeight = height;
     this.follow = new Bind(f);
     this.horBorderPixel = horBorderPixel_0;
     this.vertBorderPixel = vertBorderPixel_1;
     this.maxSpeed = maxSpeed_2;
     if (follow != null)
     {
         this.cameraX = follow.GetX() - (this.renderWidth / 2);
         this.cameraY = follow.GetY() - (this.renderHeight / 2);
     }
     this.cameraRect = r;
     this.visibleRect = new RectBox(cameraX - horBorderPixel_0, cameraY
             - vertBorderPixel_1, renderWidth + horBorderPixel_0, renderHeight
             + vertBorderPixel_1);
     this.moveRect = new RectBox(cameraX - horBorderPixel_0, cameraY
             - vertBorderPixel_1, renderWidth + horBorderPixel_0, renderHeight
             + vertBorderPixel_1);
     this.UpdateCamera();
 }
Example #9
0
		internal override void Update() {
			relAnchor = b.mAng.Mul(localAnchor);
			anchor.Set(relAnchor.x + b.pos.x, relAnchor.y + b.pos.y);
			if (b.rem || b.fix) {
				rem = true;
			}
		}
Example #10
0
		public override void SetTarget(LNNode node) {
			base._firstTick = true;
			base._isEnd = false;
			base._target = node;
			this._orgPos = node.GetPosition();
			this._diff = this._pos.Sub(this._orgPos);
		}
Example #11
0
		public static Vector2f GetVelocity(Vector2f velocity, Vector2f force,
				float mass) {
			Vector2f acceleration = new Vector2f(force.GetX() / mass, force.GetY()
					/ mass);
			velocity.Add(acceleration);
			return velocity;
		}
Example #12
0
		private static Vector2f CreateOrigin(LObject o, Origin origin) {
			Vector2f v = new Vector2f(o.X(), o.Y());
			switch (origin) {
			case Origin.CENTER:
				v.Set(o.GetWidth() / 2f, o.GetHeight() / 2f);
				return v;
			case Origin.TOP_LEFT:
				v.Set(0.0f, o.GetHeight());
				return v;
			case Origin.TOP_RIGHT:
				v.Set(o.GetWidth(), o.GetHeight());
				return v;
			case Origin.BOTTOM_LEFT:
				v.Set(0.0f, 0.0f);
				return v;
			case Origin.BOTTOM_RIGHT:
				v.Set(o.GetWidth(), 0.0f);
				return v;
			case Origin.LEFT_CENTER:
				v.Set(0.0f, o.GetHeight() / 2f);
				return v;
			case Origin.TOP_CENTER:
				v.Set(o.GetWidth() / 2f, o.GetHeight());
				return v;
			case Origin.BOTTOM_CENTER:
				v.Set(o.GetWidth() / 2f, 0.0f);
				return v;
			case Origin.RIGHT_CENTER:
				v.Set(o.GetWidth(), o.GetHeight() / 2f);
				return v;
			default:
				return v;
			}
		}
Example #13
0
 public Line(Vector2f start_0, Vector2f end_1)
     : base()
 {
     this.loc = new Vector2f(0, 0);
     this.closest = new Vector2f(0, 0);
     this.type = Loon.Core.Geom.ShapeType.LINE_SHAPE;
     Set(start_0, end_1);
 }
Example #14
0
		public static LNJumpParabolaBy Action(float duration, Vector2f position,
				Vector2f refPoint) {
			LNJumpParabolaBy by = new LNJumpParabolaBy();
			by._delta = position;
			by._duration = duration;
			by._refPoint = refPoint;
			return by;
		}
Example #15
0
		public static Vector2f CalculateVector(float angle, float magnitude) {
			Vector2f v = new Vector2f();
			v.x = MathUtils.Sin(MathUtils.ToRadians(angle));
			v.x *= magnitude;
			v.y = -MathUtils.Cos(MathUtils.ToRadians(angle));
			v.y *= magnitude;
			return v;
		}
Example #16
0
 public static Vector2f GetVelocity(Vector2f velocity, List<Vector2f> forces)
 {
     foreach (Vector2f v in forces)
     {
         velocity.Add(v);
     }
     return velocity;
 }
Example #17
0
        new public static LNMoveBy Action(float duration, Vector2f pos)
        {
			LNMoveBy by = new LNMoveBy();
			by._diff = pos;
			by._duration = duration;
			by._lastTime = 0f;
			return by;
		}
Example #18
0
		public static LNJumpBy Action(float duration, Vector2f delta, float height,
				int jumps) {
			LNJumpBy by = new LNJumpBy();
			by._duration = duration;
			by._delta = delta;
			by._height = height;
			by._jumps = jumps;
			return by;
		}
Example #19
0
        new public static LNJumpTo Action(float duration, Vector2f delta, float height,
				int jumps) {
			LNJumpTo to = new LNJumpTo();
			to._duration = duration;
			to._delta = delta;
			to._height = height;
			to._jumps = jumps;
			return to;
		}
Example #20
0
		public PPolygon(Vector2f[] vertices) {
			numVertices = vertices.Length;
			xs = new float[numVertices];
			ys = new float[numVertices];
			for (int i = 0; i < numVertices; i++) {
				xs[i] = vertices[i].x;
				ys[i] = vertices[i].y;
			}
		}
Example #21
0
 public Vector2f GetOrigin(string text)
 {
     Vector2f result = (Vector2f)CollectionUtils.Get(fontSizes, text);
     if (result == null)
     {
         result = new Vector2f(StringWidth(text) / 2f, GetHeight() / 2f);
     }
     return result;
 }
Example #22
0
 public static float AngleTo(Vector2f vectorA)
 {
     float angle = MathUtils.Atan2(vectorA.y, vectorA.x)
             * MathUtils.RAD_TO_DEG;
     if (angle < 0) {
         angle += 360;
     }
     return angle;
 }
Example #23
0
        public static Vector2f Cpy(Vector2f vectorA)
        {
            Vector2f newSVector2 = new Vector2f();

            newSVector2.x = vectorA.x;
            newSVector2.y = vectorA.y;

            return newSVector2;
        }
Example #24
0
		public PPhysWorld() {
			this.iterations = 10;
			this.gravity = new Vector2f(0.0F, 9.80665F);
			this.bodies = new PBody[1024];
			this.joints = new PJoint[1024];
			this.shapes = new PShape[1024];
			this.solvers = new PSolver[1024];
			this.sap = new PSweepAndPrune();
		}
Example #25
0
		public void Draw(int idx, SpriteBatch batch, Vector2f absPos,
				float rotation, Vector2f scale, LColor color) {
			RectBox rect = this._rectList[idx];
			batch.SetColor(color);
			batch.Draw(_texture, absPos.x, absPos.y, anchor.x, anchor.y,
					rect.width, rect.height, scale.x, scale.y,
					MathUtils.ToDegrees(rotation), rect.x, rect.y, rect.width,
					rect.height, false, false);
			batch.ResetColor();
		}
Example #26
0
		public PDragJoint(PBody b_0, float px, float py) {
			this.b = b_0;
			dragPoint = new Vector2f(px, py);
			localAnchor = new Vector2f(px - b_0.pos.x, py - b_0.pos.y);
			b_0.mAng.Transpose().MulEqual(localAnchor);
			anchor = b_0.mAng.Mul(localAnchor);
			anchor.AddLocal(b_0.pos);
			type = Physics.PJointType.DRAG_JOINT;
			mass = new PTransformer();
		}
Example #27
0
 internal DefImage(string uid, string name, Vector2f p, Vector2f o, Vector2f a, Vector2f pl)
 {
     this.uniqueID = uid;
     this.pos = p;
     this.orig = o;
     this.anchor = a;
     this.place = pl;
     this.fileName = name;
     LNDataCache.SetImage(this, this.uniqueID);
 }
Example #28
0
		public static Vector2f RotateVector(Vector2f v, Vector2f center, float angle) {
			Vector2f result = new Vector2f();
			float x = v.x - center.x;
			float y = v.y - center.y;
			result.x = MathUtils.Cos(angle) * x - MathUtils.Sin(angle) * y
					+ center.x;
			result.y = MathUtils.Sin(angle) * x + MathUtils.Cos(angle) * y
					+ center.y;
			return result;
		}
Example #29
0
 public Print(string context, LFont f, Vector2f v, int w,
         int h)
 {
     this.SetMessage(context, f);
     this.vector = v;
     this.width = w;
     this.height = h;
     this.wait = 0;
     this.isWait = false;
 }
Example #30
0
		public Print(string context, LFont font, Vector2f vector, int width,
				int height) {
                    this.messageBuffer = new StringBuilder(messageLength);
			this.SetMessage(context, font);
			this.vector = vector;
			this.width = width;
			this.height = height;
			this.wait = 0;
			this.isWait = false;
		}
Example #31
0
 public float Distance(Vector2f point)
 {
     return(MathUtils.Sqrt(DistanceSquared(point)));
 }
Example #32
0
 public static float Area(Vector2f a, Vector2f b, Vector2f c)
 {
     return(Area(a.x, a.y, b.x, b.y, c.x, c.y));
 }
Example #33
0
        public bool On(Vector2f point)
        {
            GetClosestPoint(point, closest);

            return(point.Equals(closest));
        }