public void DrawAabb(JVector from, JVector to, Color color) { JVector halfExtents = (to - from) * 0.5f; JVector center = (to + from) * 0.5f; JVector edgecoord = new JVector(1f, 1f, 1f), pa, pb; for (int i = 0; i < 4; i++) { for (int j = 0; j < 3; j++) { pa = new JVector(edgecoord.X * halfExtents.X, edgecoord.Y * halfExtents.Y, edgecoord.Z * halfExtents.Z); pa += center; int othercoord = j % 3; SetElement(ref edgecoord, othercoord, GetElement(edgecoord, othercoord) * -1f); pb = new JVector(edgecoord.X * halfExtents.X, edgecoord.Y * halfExtents.Y, edgecoord.Z * halfExtents.Z); pb += center; DrawLine(pa, pb, color); } edgecoord = new JVector(-1f, -1f, -1f); if (i < 3) SetElement(ref edgecoord, i, GetElement(edgecoord, i) * -1f); } }
/// <summary> /// SupportMapping. Finds the point in the shape furthest away from the given direction. /// Imagine a plane with a normal in the search direction. Now move the plane along the normal /// until the plane does not intersect the shape. The last intersection point is the result. /// </summary> /// <param name="direction">The direction.</param> /// <param name="result">The result.</param> public override void SupportMapping(ref JVector direction, out JVector result) { result = direction; result.Normalize(); JVector.Multiply(ref result, radius, out result); }
/// <summary> /// Creates a new instance of the TransformedShape struct. /// </summary> /// <param name="shape">The shape.</param> /// <param name="orientation">The orientation this shape should have.</param> /// <param name="position">The position this shape should have.</param> public TransformedShape(Shape shape, JMatrix orientation, JVector position) { this.position = position; this.orientation = orientation; JMatrix.Transpose(ref orientation, out invOrientation); this.shape = shape; }
/// <summary> /// This method handles explicit object collision logic. Is registered to physics engine CollisionDetected event handler. /// Fired on any detected collision, so must check if the collision applies to this object /// </summary> /// <param name="body1"></param> /// <param name="body2"></param> /// <param name="point1"></param> /// <param name="point2"></param> /// <param name="normal"></param> /// <param name="penetration"></param> virtual public void HandleCollision(RigidBody body1, RigidBody body2, JVector point1, JVector point2, JVector normal, float penetration) { // work out which, if any, of the collided bodies is this object, and name them semantically RigidBody other; var self = this.PhysicsDescription; if (body1 == self) other = body2; else if (body2 == self) other = body1; else return; if (other == this.flock.level.endGoal.PhysicsDescription) // we've collided with the end zone { // be careful of what you modify in this handler as it may be called during an Update() // attempting to modify any list (such as destroying game objects, etc) will cause an exception if (!ToDestroy) // incremement score once before destroy { this.game.incScore(10); } this.Destroy(true); // remove self } Collision(other); // do other collision stuff }
/// <summary> /// Initializes a new instance of the DistanceConstraint class. /// </summary> /// <param name="body1">The first body.</param> /// <param name="body2">The second body.</param> /// <param name="anchor1">The anchor point of the first body in world space. /// The distance is given by the initial distance between both anchor points.</param> /// <param name="anchor2">The anchor point of the second body in world space. /// The distance is given by the initial distance between both anchor points.</param> public PointOnPoint(RigidBody body, JVector localAnchor) : base(body, null) { localAnchor1 = localAnchor; this.anchor = body.position + JVector.Transform(localAnchor, body.orientation); }
public override void Iterate() { deltaVelocity = TargetVelocity - Body1.LinearVelocity; deltaVelocity.Y = 0.0f; // determine how 'stiff' the character follows the target velocity deltaVelocity *= 0.005f; if (deltaVelocity.LengthSquared() != 0.0f) { // activate it, in case it fall asleep :) Body1.IsActive = true; Body1.ApplyImpulse(deltaVelocity * Body1.Mass); } if (shouldIJump) { Body1.IsActive = true; Body1.ApplyImpulse(JumpVelocity * JVector.Up * Body1.Mass); System.Diagnostics.Debug.WriteLine("JUMP! " + DateTime.Now.Second.ToString()); if (!BodyWalkingOn.IsStatic) { BodyWalkingOn.IsActive = true; // apply the negative impulse to the other body BodyWalkingOn.ApplyImpulse(-1.0f * JumpVelocity * JVector.Up * Body1.Mass); } } }
public override void Iterate() { DeltaVelocity = TargetVelocity - Body1.LinearVelocity; DeltaVelocity.Y = 0.0f; var fraction = 0.02f; if (WalkingOn == null) fraction = 0.0001f; DeltaVelocity *= fraction; if (DeltaVelocity.LengthSquared() != 0.0f) { Body1.IsActive = true; Body1.ApplyImpulse(DeltaVelocity * Body1.Mass); } if (ShouldJump) { Body1.IsActive = true; Body1.ApplyImpulse(JumpVelocity * JVector.Up * Body1.Mass); if (!WalkingOn.IsStatic) { WalkingOn.IsActive = true; WalkingOn.ApplyImpulse(-1.0f * JumpVelocity * JVector.Up * Body1.Mass); } } }
public void AddCar(JVector position) { car = new CarObject(Demo); this.Demo.Components.Add(car); car.carBody.Position = position; }
public override void Iterate() { deltaVelocity = TargetVelocity - Body1.LinearVelocity; deltaVelocity.Y = 0.0f; // determine how 'stiff' the character follows the target velocity deltaVelocity *= 0.02f; if (deltaVelocity.LengthSquared() != 0.0f) { // activate it, in case it fall asleep :) Body1.IsActive = true; Body1.ApplyImpulse(deltaVelocity * Body1.Mass); } if (shouldIJump) { Body1.IsActive = true; Body1.ApplyImpulse(jumpVelocity * JVector.Up * Body1.Mass); if (!BodyWalkingOn.IsStatic) { BodyWalkingOn.IsActive = true; // apply the negative impulse to the other body BodyWalkingOn.ApplyImpulse(-1.0f * jumpVelocity * JVector.Up * Body1.Mass); } } }
protected override void Update() { base.Update(); if (form.MouseClickedHappenend) { form.MouseClickedHappenend = false; var screenPosition = new JVector( -1f + 2* (form.MouseClickPosition.x / form.ClientSize.Width), 1, -1f + 2 * ((form.MouseClickPosition.y / form.ClientSize.Height))); var projectionMatrix = Common.ProjectionMatrix; JMatrix jMatrix = new JMatrix( projectionMatrix.M11, projectionMatrix.M12, projectionMatrix.M13, projectionMatrix.M21, projectionMatrix.M22, projectionMatrix.M23, projectionMatrix.M31, projectionMatrix.M32, projectionMatrix.M33); JMatrix invertedJMatrix; JMatrix.Invert(ref jMatrix, out invertedJMatrix); var rayDirection = JVector.Transform(screenPosition, invertedJMatrix); RigidBody body; JVector normal; float fraction; Entities.world3D.CollisionSystem.Raycast(JitterDatatypes.ToJVector(Common.CameraPosition), rayDirection, null, out body, out normal, out fraction); if (body != null && !body.IsStatic) body.ApplyImpulse(rayDirection * 200); } }
public bool CanJump(RigidBody body) { Body = WorldItems[body]; Jitter.Dynamics.RigidBody resultingBody = null; JVector normal; float fraction; var positions = new JVector[] { new JVector(body.Position.X, body.Position.Y, body.Position.Z), new JVector(body.Position.X + 0.5f, body.Position.Y, body.Position.Z), new JVector(body.Position.X - 0.5f, body.Position.Y, body.Position.Z), new JVector(body.Position.X, body.Position.Y, body.Position.Z - 0.5f), new JVector(body.Position.X, body.Position.Y, body.Position.Z + 0.5f)}; for (int i = 0; i < positions.Length; i++) { bool result = World.CollisionSystem.Raycast(new JVector(positions[i].X, positions[i].Y, positions[i].Z), new JVector(0, -1, 0), RaycastCallback, out resultingBody, out normal, out fraction); if (result && fraction <= 1.3f && Body.LinearVelocity.Y < 0.5f) { return true; } } return false; }
public override void Build() { AddGround(); for (int i = 0; i < 11; i++) { RigidBody box = new RigidBody(new BoxShape(1,0.01f,1)); this.Demo.World.AddBody(box); JVector boxPos = new JVector(-15 + i * 3 + 1, 5, 0); box.Position = boxPos; box.IsStatic = true; RigidBody sphere = new RigidBody(new SphereShape(0.5f)); this.Demo.World.AddBody(sphere); sphere.Position = boxPos + JVector.Up * 30; sphere.EnableSpeculativeContacts = true; // set restitution sphere.Material.Restitution = box.Material.Restitution = 1.0f / 10.0f * i; sphere.LinearVelocity = new JVector(0, 0, 0); sphere.Damping = RigidBody.DampingType.Angular; } }
/// <summary> /// Creates a new instance of the FluidVolume class. /// </summary> /// <param name="world">The world.</param> public Buoyancy(World world) : base(world) { Density = 2.0f; Damping = 0.1f; Flow = JVector.Zero; }
public TraceResult(RigidBody body, float distance, JVector position, JVector normal) { this.Body = body; this.Distance = distance; this.Position = position; this.Normal = normal; }
public static Matrix4 ToMatrix4(JMatrix orientation, JVector position) { return new Matrix4( orientation.M11, orientation.M12, orientation.M13, 0, orientation.M21, orientation.M22, orientation.M23, 0, orientation.M31, orientation.M32, orientation.M33, 0, position.X, position.Y, position.Z, 1); }
public void DrawPoint(JVector pos) { GL.End(); GL.Begin(BeginMode.Points); GL.Vertex3(pos.X, pos.Y, pos.Z); GL.End(); GL.Begin(BeginMode.Lines); }
public static Matrix4 ToMatrix4(JMatrix m, JVector position) { return new Matrix4( m.M11, m.M12, m.M13, 0, m.M21, m.M22, m.M23, 0, m.M31, m.M32, m.M33, 0, position.X, position.Y, position.Z, 1); }
internal RigidBodyState(RigidBody _body) { body = _body; savedPosition = body.Position; savedOrientation = body.Orientation; savedLinearVelocity = body.LinearVelocity; savedAngularVelocity = body.AngularVelocity; }
public void HandleInput(GameTime gameTime) { currentTime += (float)gameTime.ElapsedGameTime.Milliseconds; KeyboardState keys = Keyboard.GetState(); if (keys.IsKeyDown(Keys.Up)) { float x = (float)Math.Sin(facing); float z = (float)Math.Cos(facing); JVector newPath = new JVector(x, 0f, z) * speed; newPath = newPath * currentTime; newPath.Normalize(); forward = newPath; body.AddForce(newPath*100f); //position = body.Position; //position += newPath; //body.Position = position; } if (keys.IsKeyDown(Keys.Left)) { facing -= 0.05f; } if (keys.IsKeyDown(Keys.Right)) { facing += 0.05f; } if (keys.IsKeyDown(Keys.Down)) { float x = (float)Math.Sin(facing); float z = (float)Math.Cos(facing); JVector newPath = new JVector(x, 0f, z) * speed; newPath = newPath * currentTime; newPath.Normalize(); body.AddForce(newPath * -100f); } if (keys.IsKeyDown(Keys.Space)) { body.AddForce(JVector.Up * 100f); } /*if (keys.IsKeyDown(Keys.A)) if (keys.IsKeyDown(Keys.S)) if (keys.IsKeyDown(Keys.W)) */ }
/// <summary> /// Initializes a new instance of the HingeJoint class. /// </summary> /// <param name="world">The world class where the constraints get added to.</param> /// <param name="body1">The first body connected to the second one.</param> /// <param name="body2">The second body connected to the first one.</param> /// <param name="position">The position in world space where both bodies get connected.</param> /// <param name="hingeAxis">The axis if the hinge.</param> public LimitedHingeJoint(World world, RigidBody body1, RigidBody body2, JVector position, JVector hingeAxis, float hingeFwdAngle, float hingeBckAngle) : base(world) { // Create the hinge first, two point constraints worldPointConstraint = new PointOnPoint[2]; hingeAxis *= 0.5f; JVector pos1 = position; JVector.Add(ref pos1, ref hingeAxis, out pos1); JVector pos2 = position; JVector.Subtract(ref pos2, ref hingeAxis, out pos2); worldPointConstraint[0] = new PointOnPoint(body1, body2, pos1); worldPointConstraint[1] = new PointOnPoint(body1, body2, pos2); // Now the limit, one max distance constraint hingeAxis.Normalize(); // choose a direction that is perpendicular to the hinge JVector perpDir = JVector.Up; if (JVector.Dot(perpDir, hingeAxis) > 0.1f) perpDir = JVector.Right; // now make it perpendicular to the hinge JVector sideAxis = JVector.Cross(hingeAxis, perpDir); perpDir = JVector.Cross(sideAxis, hingeAxis); perpDir.Normalize(); // the length of the "arm" TODO take this as a parameter? what's // the effect of changing it? float len = 10.0f * 3; // Choose a position using that dir. this will be the anchor point // for body 0. relative to hinge JVector hingeRelAnchorPos0 = perpDir * len; // anchor point for body 2 is chosen to be in the middle of the // angle range. relative to hinge float angleToMiddle = 0.5f * (hingeFwdAngle - hingeBckAngle); JVector hingeRelAnchorPos1 = JVector.Transform(hingeRelAnchorPos0, JMatrix.CreateFromAxisAngle(hingeAxis, -angleToMiddle / 360.0f * 2.0f * JMath.Pi)); // work out the "string" length float hingeHalfAngle = 0.5f * (hingeFwdAngle + hingeBckAngle); float allowedDistance = len * 2.0f * (float)System.Math.Sin(hingeHalfAngle * 0.5f / 360.0f * 2.0f * JMath.Pi); JVector hingePos = body1.Position; JVector relPos0c = hingePos + hingeRelAnchorPos0; JVector relPos1c = hingePos + hingeRelAnchorPos1; distance = new PointPointDistance(body1, body2, relPos0c, relPos1c); distance.Distance = allowedDistance; distance.Behavior = PointPointDistance.DistanceBehavior.LimitMaximumDistance; }
/// <summary> /// Initializes a new instance of the DistanceConstraint class. /// </summary> /// <param name="body1">The first body.</param> /// <param name="body2">The second body.</param> /// <param name="anchor1">The anchor point of the first body in world space. /// The distance is given by the initial distance between both anchor points.</param> /// <param name="anchor2">The anchor point of the second body in world space. /// The distance is given by the initial distance between both anchor points.</param> public PointOnPoint(RigidBody body1, RigidBody body2, JVector anchor) : base(body1, body2) { JVector.Subtract(ref anchor, ref body1.position, out localAnchor1); JVector.Subtract(ref anchor, ref body2.position, out localAnchor2); JVector.Transform(ref localAnchor1, ref body1.invOrientation, out localAnchor1); JVector.Transform(ref localAnchor2, ref body2.invOrientation, out localAnchor2); }
public void DrawTriangle(JVector pos1, JVector pos2, JVector pos3) { GL.Vertex3(pos1.X, pos1.Y, pos1.Z); GL.Vertex3(pos2.X, pos2.Y, pos2.Z); GL.Vertex3(pos2.X, pos2.Y, pos2.Z); GL.Vertex3(pos3.X, pos3.Y, pos3.Z); GL.Vertex3(pos3.X, pos3.Y, pos3.Z); GL.Vertex3(pos1.X, pos1.Y, pos1.Z); }
public static bool ClosestPoints(ISupportMappable support1, ISupportMappable support2, ref JMatrix orientation1, ref JMatrix orientation2, ref JVector position1, ref JVector position2, out JVector p1, out JVector p2, out JVector normal) { VoronoiSimplexSolver simplexSolver = simplexSolverPool.GetNew(); simplexSolver.Reset(); p1 = p2 = JVector.Zero; JVector r = position1 - position2; JVector w, v; JVector supVertexA; JVector rn,vn; rn = JVector.Negate(r); SupportMapTransformed(support1, ref orientation1, ref position1, ref rn, out supVertexA); JVector supVertexB; SupportMapTransformed(support2, ref orientation2, ref position2, ref r, out supVertexB); v = supVertexA - supVertexB; normal = JVector.Zero; int maxIter = 15; float distSq = v.LengthSquared(); float epsilon = 0.00001f; while ((distSq > epsilon) && (maxIter-- != 0)) { vn = JVector.Negate(v); SupportMapTransformed(support1, ref orientation1, ref position1, ref vn, out supVertexA); SupportMapTransformed(support2, ref orientation2, ref position2, ref v, out supVertexB); w = supVertexA - supVertexB; if (!simplexSolver.InSimplex(w)) simplexSolver.AddVertex(w, supVertexA, supVertexB); if (simplexSolver.Closest(out v)) { distSq = v.LengthSquared(); normal = v; } else distSq = 0.0f; } simplexSolver.ComputePoints(out p1, out p2); if (normal.LengthSquared() > JMath.Epsilon * JMath.Epsilon) normal.Normalize(); simplexSolverPool.GiveBack(simplexSolver); return true; }
private RigidBody AddBox(JVector position, JVector velocity, JVector size) { BoxShape shape = new BoxShape(size); RigidBody body = new RigidBody(shape); world.AddBody(body); body.Position = position; body.Material.Restitution = 0.0f; body.LinearVelocity = velocity; body.IsActive = true; return body; }
public Pickup(Engine _engine, Tracker _tracker, JVector position) : base(_engine, _tracker, false) { Shape boxShape = new BoxShape(1f, .5f, .5f); body = new RigidBody(boxShape); body.AffectedByGravity = false; body.Position = position; body.Tag = this; EnableInterfaceCalls = true; }
/// <summary> /// Initializes a new instance of the DistanceConstraint class. /// </summary> /// <param name="body1">The first body.</param> /// <param name="body2">The second body.</param> /// <param name="anchor1">The anchor point of the first body in world space. /// The distance is given by the initial distance between both anchor points.</param> /// <param name="anchor2">The anchor point of the second body in world space. /// The distance is given by the initial distance between both anchor points.</param> public PointPointDistance(RigidBody body1, RigidBody body2, JVector anchor1,JVector anchor2) : base(body1, body2) { JVector.Subtract(ref anchor1, ref body1.position, out localAnchor1); JVector.Subtract(ref anchor2, ref body2.position, out localAnchor2); JVector.Transform(ref localAnchor1, ref body1.invOrientation, out localAnchor1); JVector.Transform(ref localAnchor2, ref body2.invOrientation, out localAnchor2); distance = (anchor1 - anchor2).Length(); }
private void SetElement(ref JVector v, int index, float value) { if (index == 0) v.X = value; else if (index == 1) v.Y = value; else if (index == 2) v.Z = value; else throw new System.ArgumentOutOfRangeException("index"); }
private float GetElement(JVector v, int index) { if (index == 0) return v.X; if (index == 1) return v.Y; if (index == 2) return v.Z; throw new ArgumentOutOfRangeException("index"); }
public void DrawTriangle(JVector pos1, JVector pos2, JVector pos3) { _debugRenderer.RenderDebugTriangle( _renderContext, pos1.ToXNAVector(), pos2.ToXNAVector(), pos3.ToXNAVector(), _isRigidBodyActive ? Color.Red : Color.DarkRed, _isRigidBodyActive ? Color.Green : Color.DarkGreen, _isRigidBodyActive ? Color.Blue : Color.DarkBlue); }
public override void SupportMapping(ref JVector direction, out JVector result) { JVector temp1, temp2 = JVector.Zero; for (int i = 0; i < shapes.Count; i++) { shapes[i].SupportMapping(ref direction, out temp1); JVector.Add(ref temp1, ref temp2, out temp2); } JVector.Subtract(ref temp2, ref shifted, out result); }
public static int[] Build(List <JVector> pointCloud, Approximation factor) { var allIndices = new List <int>(); int steps = (int)factor; for (int thetaIndex = 0; thetaIndex < steps; thetaIndex++) { float theta = JMath.Pi / (steps - 1) * thetaIndex; float sinTheta = (float)Math.Sin(theta); float cosTheta = (float)Math.Cos(theta); for (int phiIndex = 0; phiIndex < steps; phiIndex++) { float phi = (2.0f * JMath.Pi / (steps - 0) * phiIndex) - JMath.Pi; float sinPhi = (float)Math.Sin(phi); float cosPhi = (float)Math.Cos(phi); var dir = new JVector(sinTheta * cosPhi, cosTheta, sinTheta * sinPhi); int index = FindExtremePoint(pointCloud, dir); allIndices.Add(index); } } allIndices.Sort(); for (int i = 1; i < allIndices.Count; i++) { if (allIndices[i - 1] == allIndices[i]) { allIndices.RemoveAt(i - 1); i--; } } return(allIndices.ToArray()); }
/// <summary> /// Creates a matrix which rotates around the given axis by the given angle. /// </summary> /// <param name="axis">The axis.</param> /// <param name="angle">The angle.</param> /// <param name="result">The resulting rotation matrix</param> #region public static void CreateFromAxisAngle(ref JVector axis, float angle, out JMatrix result) public static void CreateFromAxisAngle(ref JVector axis, float angle, out JMatrix result) { float x = axis.X; float y = axis.Y; float z = axis.Z; float num2 = (float)Math.Sin((double)angle); float num = (float)Math.Cos((double)angle); float num11 = x * x; float num10 = y * y; float num9 = z * z; float num8 = x * y; float num7 = x * z; float num6 = y * z; result.M11 = num11 + (num * (1f - num11)); result.M12 = (num8 - (num * num8)) + (num2 * z); result.M13 = (num7 - (num * num7)) - (num2 * y); result.M21 = (num8 - (num * num8)) - (num2 * z); result.M22 = num10 + (num * (1f - num10)); result.M23 = (num6 - (num * num6)) + (num2 * x); result.M31 = (num7 - (num * num7)) + (num2 * y); result.M32 = (num6 - (num * num6)) - (num2 * x); result.M33 = num9 + (num * (1f - num9)); }
/// <summary> /// Transforms the bounding box into the space given by orientation and position. /// </summary> /// <param name="position"></param> /// <param name="orientation"></param> /// <param name="result"></param> internal void InverseTransform(ref JVector position, ref JMatrix orientation) { JVector.Subtract(ref Max, ref position, out Max); JVector.Subtract(ref Min, ref position, out Min); JVector center; JVector.Add(ref Max, ref Min, out center); center.X *= 0.5f; center.Y *= 0.5f; center.Z *= 0.5f; JVector halfExtents; JVector.Subtract(ref Max, ref Min, out halfExtents); halfExtents.X *= 0.5f; halfExtents.Y *= 0.5f; halfExtents.Z *= 0.5f; JVector.TransposedTransform(ref center, ref orientation, out center); JMatrix abs; JMath.Absolute(ref orientation, out abs); JVector.TransposedTransform(ref halfExtents, ref abs, out halfExtents); JVector.Add(ref center, ref halfExtents, out Max); JVector.Subtract(ref center, ref halfExtents, out Min); }
/// <summary> /// Calculates the dot product of two vectors. /// </summary> /// <param name="value1">The first vector.</param> /// <param name="value2">The second vector.</param> /// <returns>Returns the dot product of both.</returns> #region public static float operator *(JVector value1, JVector value2) public static float operator *(JVector value1, JVector value2) { return(JVector.Dot(ref value1, ref value2)); }
/// <summary> /// Calculates the dot product of both vectors. /// </summary> /// <param name="vector1">The first vector.</param> /// <param name="vector2">The second vector.</param> /// <returns>Returns the dot product of both vectors.</returns> public static float Dot(ref JVector vector1, ref JVector vector2) { return(((vector1.X * vector2.X) + (vector1.Y * vector2.Y)) + (vector1.Z * vector2.Z)); }
/// <summary> /// Multiply a vector with a factor. /// </summary> /// <param name="value1">The vector to multiply.</param> /// <param name="scaleFactor">The scale factor.</param> /// <param name="result">Returns the multiplied vector.</param> public static void Multiply(ref JVector value1, float scaleFactor, out JVector result) { result.X = value1.X * scaleFactor; result.Y = value1.Y * scaleFactor; result.Z = value1.Z * scaleFactor; }
/// <summary> /// Transforms a vector by the transposed of the given Matrix. /// </summary> /// <param name="position">The vector to transform.</param> /// <param name="matrix">The transform matrix.</param> /// <param name="result">The transformed vector.</param> public static void TransposedTransform(ref JVector position, ref JMatrix matrix, out JVector result) { float num0 = ((position.X * matrix.M11) + (position.Y * matrix.M12)) + (position.Z * matrix.M13); float num1 = ((position.X * matrix.M21) + (position.Y * matrix.M22)) + (position.Z * matrix.M23); float num2 = ((position.X * matrix.M31) + (position.Y * matrix.M32)) + (position.Z * matrix.M33); result.X = num0; result.Y = num1; result.Z = num2; }
/// <summary> /// Calculates the dot product of two vectors. /// </summary> /// <param name="vector1">The first vector.</param> /// <param name="vector2">The second vector.</param> /// <returns>Returns the dot product of both vectors.</returns> #region public static float Dot(JVector vector1, JVector vector2) public static float Dot(JVector vector1, JVector vector2) { return(JVector.Dot(ref vector1, ref vector2)); }
/// <summary> /// The cross product of two vectors. /// </summary> /// <param name="vector1">The first vector.</param> /// <param name="vector2">The second vector.</param> /// <returns>The cross product of both vectors.</returns> #region public static JVector Cross(JVector vector1, JVector vector2) public static JVector Cross(JVector vector1, JVector vector2) { Cross(ref vector1, ref vector2, out var result); return(result); }
/// <summary> /// Checks wether a point is within a box or not. /// </summary> /// <param name="point"></param> /// <returns></returns> public ContainmentType Contains(JVector point) { return(this.Contains(ref point)); }
/// <summary> /// Adds two vectors. /// </summary> /// <param name="value1">The first vector.</param> /// <param name="value2">The second vector.</param> /// <returns>The sum of both vectors.</returns> #region public static void Add(JVector value1, JVector value2) public static JVector Add(JVector value1, JVector value2) { Add(ref value1, ref value2, out var result); return(result); }
/// <summary> /// Calculates the dot product of two vectors. /// </summary> /// <param name="vector1">The first vector.</param> /// <param name="vector2">The second vector.</param> /// <returns>Returns the dot product of both vectors.</returns> #region public static double Dot(JVector vector1, JVector vector2) public static double Dot(JVector vector1, JVector vector2) { return(JVector.Dot(ref vector1, ref vector2)); }
public bool SegmentIntersect(JVector origin, JVector direction) { return(SegmentIntersect(ref origin, ref direction)); }
/// <summary> /// Creates a matrix which rotates around the given axis by the given angle. /// </summary> /// <param name="axis">The axis.</param> /// <param name="angle">The angle.</param> /// <returns>The resulting rotation matrix</returns> public static JMatrix CreateFromAxisAngle(JVector axis, float angle) { JMatrix result; CreateFromAxisAngle(ref axis, angle, out result); return(result); }
public void AddPoint(ref JVector point) { JVector.Max(ref Max, ref point, out Max); JVector.Min(ref Min, ref point, out Min); }
public void AddPoint(JVector point) { AddPoint(ref point); }
/// <summary> /// Checks whether a point is inside, outside or intersecting /// a point. /// </summary> /// <param name="point">A point in space.</param> /// <returns>The ContainmentType of the point.</returns> public ContainmentType Contains(ref JVector point) { return(((((this.Min.X <= point.X) && (point.X <= this.Max.X)) && ((this.Min.Y <= point.Y) && (point.Y <= this.Max.Y))) && ((this.Min.Z <= point.Z) && (point.Z <= this.Max.Z))) ? ContainmentType.Contains : ContainmentType.Disjoint); }
/// <summary> /// Subtracts two vectors. /// </summary> /// <param name="value1">The first vector.</param> /// <param name="value2">The second vector.</param> /// <returns>The difference of both vectors.</returns> #region public static JVector operator -(JVector value1, JVector value2) public static JVector operator -(JVector value1, JVector value2) { JVector result; JVector.Subtract(ref value1, ref value2, out result); return(result); }
/// <summary> /// Transforms a vector by the given matrix. /// </summary> /// <param name="position">The vector to transform.</param> /// <param name="matrix">The transform matrix.</param> /// <returns>The transformed vector.</returns> #region public static JVector Transform(JVector position, JMatrix matrix) public static JVector Transform(JVector position, JMatrix matrix) { Transform(ref position, ref matrix, out var result); return(result); }
/// <summary> /// Adds two vectors. /// </summary> /// <param name="value1">The first vector.</param> /// <param name="value2">The second vector.</param> /// <returns>The sum of both vectors.</returns> #region public static JVector operator +(JVector value1, JVector value2) public static JVector operator +(JVector value1, JVector value2) { JVector result; JVector.Add(ref value1, ref value2, out result); return(result); }
/// <summary> /// Gets a vector with the maximum x,y and z values of both vectors. /// </summary> /// <param name="value1">The first value.</param> /// <param name="value2">The second value.</param> /// <param name="result">A vector with the maximum x,y and z values of both vectors.</param> public static void Max(ref JVector value1, ref JVector value2, out JVector result) { result.X = (value1.X > value2.X) ? value1.X : value2.X; result.Y = (value1.Y > value2.Y) ? value1.Y : value2.Y; result.Z = (value1.Z > value2.Z) ? value1.Z : value2.Z; }
/// <summary> /// Normalizes the given vector. /// </summary> /// <param name="value">The vector which should be normalized.</param> /// <returns>A normalized vector.</returns> #region public static JVector Normalize(JVector value) public static JVector Normalize(JVector value) { Normalize(ref value, out var result); return(result); }
public bool RayIntersect(JVector origin, JVector direction) { return(RayIntersect(ref origin, ref direction)); }
/// <summary> /// Constructor /// </summary> /// <param name="min">The minimum point of the box.</param> /// <param name="max">The maximum point of the box.</param> public JBBox(JVector min, JVector max) { this.Min = min; this.Max = max; }
/// <summary> /// Subtracts two vectors. /// </summary> /// <param name="value1">The first vector.</param> /// <param name="value2">The second vector.</param> /// <returns>The difference of both vectors.</returns> #region public static JVector Subtract(JVector value1, JVector value2) public static JVector Subtract(JVector value1, JVector value2) { Subtract(ref value1, ref value2, out var result); return(result); }
/// <summary> /// Gets a vector with the maximum x,y and z values of both vectors. /// </summary> /// <param name="value1">The first value.</param> /// <param name="value2">The second value.</param> /// <returns>A vector with the maximum x,y and z values of both vectors.</returns> #region public static JVector Max(JVector value1, JVector value2) public static JVector Max(JVector value1, JVector value2) { Max(ref value1, ref value2, out var result); return(result); }
/// <summary> /// Multiply a vector with a factor. /// </summary> /// <param name="value1">The vector to multiply.</param> /// <param name="scaleFactor">The scale factor.</param> /// <returns>Returns the multiplied vector.</returns> #region public static JVector Multiply(JVector value1, float scaleFactor) public static JVector Multiply(JVector value1, float scaleFactor) { Multiply(ref value1, scaleFactor, out var result); return(result); }