public Explosion(long _uniqueId, Vector3 _position, Quaternion _rotation) : base(_uniqueId, _position, _rotation, "Models/explosion") { Scale = 1; Active = true; explosion = ContentLoadManager.loadModel("Models/explosion"); Random random = new Random((int)(_position.X + _position.Y + _position.Z)); float x = random.Next() * spinRate; if (random.Next() % 2 == 0) { x *= -1; } else { } float y = random.Next() * spinRate; if (random.Next() % 2 == 0) { y *= -1; } else { } float z = random.Next() * spinRate; if (random.Next() % 2 == 0) { z *= -1; } else { } spinDirection = new Vector3(x, y, z); x = random.Next() * outerspinRate; if (random.Next() % 2 == 0) { x *= -1; } else { } y = random.Next() * outerspinRate; if (random.Next() % 2 == 0) { y *= -1; } else { } z = random.Next() * outerspinRate; if (random.Next() % 2 == 0) { z *= -1; } else { } outerSpinDirection = new Vector3(x, y, z); float r = (float)random.NextDouble() * MAX_SCALE_RESCALE; if (random.Next() % 2 == 0) { x *= -1; } else { } MAX_SCALE += r; r = (float)random.NextDouble() * SCALE_RATE_RESCALE; if (random.Next() % 2 == 0) { x *= -1; } else { } SCALE_RATE += r; generator = new ExplosionParticleGenerator(_position); }
public static void LookAtLockRotation(Vector3 target, float speed, Vector3 position, ref Quaternion rotation, Vector3 fwd, Vector3 lockedRots) { LookAt(target, speed, position, ref rotation, fwd); LockRotation(ref rotation, lockedRots); }
public static void ClientEntityCreationMessage(NetConnection c, ushort id, Vector3 position, Quaternion orientation, int nose, int core, int tail, int[] weapons, long ownerID) { var msg = Network.Server.CreateMessage(); msg.Write((byte)NetMsgType.CreateOnClient); msg.Write((byte)NetEntityType.Ship); msg.Write(id); msg.Write(position.X); msg.Write(position.Y); msg.Write(position.Z); msg.Write(orientation.X); msg.Write(orientation.Y); msg.Write(orientation.Z); msg.Write(orientation.W); msg.Write(nose); msg.Write(core); msg.Write(tail); if (weapons != null && weapons.Length > 0) { msg.Write(weapons.Length); for (int i = 0; i < weapons.Length; i++) msg.Write(weapons[i]); } else { msg.Write((int)0); } msg.Write(ownerID); if (c != null) Network.Server.SendMessage(msg, c, NetDeliveryMethod.ReliableOrdered); else Network.Server.SendToAll(msg, NetDeliveryMethod.ReliableOrdered); }
internal static void ConvertQuaternion(ref XNA.Quaternion q, out Quaternion result) { result.X = q.X; result.Y = q.Y; result.Z = q.Z; result.W = q.W; }
public void Transform() { // STANDART OVERLOADS TEST var expectedResult1 = new Vector3(51, 58, 65); var expectedResult2 = new Vector3(33, -14, -1); var v1 = new Vector3(1, 2, 3); var m1 = new Matrix(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16); var v2 = new Vector3(1, 2, 3); var q1 = new Quaternion(2, 3, 4, 5); Vector3 result1; Vector3 result2; Assert.That(expectedResult1, Is.EqualTo(Vector3.Transform(v1, m1)).Using(Vector3Comparer.Epsilon)); Assert.That(expectedResult2, Is.EqualTo(Vector3.Transform(v2, q1)).Using(Vector3Comparer.Epsilon)); // OUTPUT OVERLOADS TEST Vector3.Transform(ref v1, ref m1, out result1); Vector3.Transform(ref v2, ref q1, out result2); Assert.That(expectedResult1, Is.EqualTo(result1).Using(Vector3Comparer.Epsilon)); Assert.That(expectedResult2, Is.EqualTo(result2).Using(Vector3Comparer.Epsilon)); }
public EnemyDalek() : base() { current = Quaternion.Identity; from = Quaternion.Identity; to = Quaternion.Identity; }
public static void DrawWireframe(PrimitiveDrawer primitiveDrawer, Vector3 cameraPosition, Matrix cameraView, Matrix cameraProjection, Vector3 center, float radius, Quaternion rotation, Color color) { // Draw three orthogonal discs. Disc.DrawWireframe(primitiveDrawer, cameraPosition, cameraView, cameraProjection, center, Vector3.Normalize(Vector3.Transform(Vector3.Up, rotation)), radius, color, true); Disc.DrawWireframe(primitiveDrawer, cameraPosition, cameraView, cameraProjection, center, Vector3.Normalize(Vector3.Transform(Vector3.Forward, rotation)), radius, color, true); Disc.DrawWireframe(primitiveDrawer, cameraPosition, cameraView, cameraProjection, center, Vector3.Normalize(Vector3.Transform(Vector3.Left, rotation)), radius, color, true); // Draw disc aligned with camera. To do this, first calculate the largest visible cross section using // the technique described here: http://www.quantimegroup.com/solutions/pages/Article/Article.html // Solve for dy. Vector3 cameraToCenter = center - cameraPosition; float distanceToCenter = cameraToCenter.Length(); float radius2 = radius * radius; float dy = radius2 / distanceToCenter; float r = MathUtility.Sqrt(radius2 - (dy * dy)); Vector3 directionToCenter = Vector3.Normalize(cameraToCenter); Vector3 newCenter = cameraPosition + directionToCenter * (distanceToCenter - dy); // Disc aligned with camera Disc.DrawWireframe(primitiveDrawer, cameraPosition, cameraView, cameraProjection, newCenter, directionToCenter, r, Color.White, false); }
public void Write(Quaternion Value) { base.Write(Value.X); base.Write(Value.Y); base.Write(Value.Z); base.Write(Value.W); }
public static void Convert(ref Microsoft.Xna.Framework.Quaternion quaternion, out Quaternion bepuQuaternion) { bepuQuaternion.X = quaternion.X; bepuQuaternion.Y = quaternion.Y; bepuQuaternion.Z = quaternion.Z; bepuQuaternion.W = quaternion.W; }
public static void Convert(ref Quaternion bepuQuaternion, out Microsoft.Xna.Framework.Quaternion quaternion) { quaternion.X = bepuQuaternion.X; quaternion.Y = bepuQuaternion.Y; quaternion.Z = bepuQuaternion.Z; quaternion.W = bepuQuaternion.W; }
public HalkAssaultFighter(long _uniqueId, Vector3 _position, Quaternion _rotation, SpawnShip _home) : base(_uniqueId, _position, _rotation, Team.Halk, _home) { laserOffsets = new Vector3[] { new Vector3(-3.382f, -2.532f, 59.654f), new Vector3(3.382f, -2.532f, 59.654f) }; SECONDARY_RANGE = 8000000f; MAX_SECONDARY_AMMO = 9; SecondaryAmmo = MaxSecondaryAmmo; secondaryAttackPositions = new Vector3[] { new Vector3(0, -4.275f, 11.3f), }; secondaryAttackForward = new Quaternion[] { Quaternion.CreateFromAxisAngle(Vector3.Forward, 0f) }; trailGenerators.Add(new HEngineTrailGenerator(this, new Vector3(-3.004f, 1.722f, -22.46f))); // -12.46f trailGenerators.Add(new HEngineTrailGenerator(this, new Vector3(-0.475f, 1.413f, -22.46f))); trailGenerators.Add(new HEngineTrailGenerator(this, new Vector3(-0.992f, 3.3987f, -22.46f))); trailGenerators.Add(new HEngineTrailGenerator(this, new Vector3(1.229f, 4.355f, -22.46f))); trailGenerators.Add(new HEngineTrailGenerator(this, new Vector3(2.429f, 2.204f, -22.46f))); setCloseModelByString("Models/Ships/Halk_Assault"); setFarModelByString("Models/Ships/Halk_Assault"); }
/// <summary> /// Gets the quaternion as an XNA quaternion. /// </summary> /// <param name="q">The quaternion to receive the data.</param> public void Get(out Quaternion q) { q = new Quaternion((float)X / (float)Constants.MAX_VAL, (float)Y / (float)Constants.MAX_VAL, (float)Z / (float)Constants.MAX_VAL, (float)W / (float)Constants.MAX_VAL); }
public static void GetRotationAndTranslationComponents(this Matrix worldMatrix, out Quaternion rotation, out Vector3 translation) { worldMatrix.Decompose(out _scale, out _rotation, out _translation); rotation = _rotation; translation = _translation; }
/// <summary> /// Sets the quaternion from an XNA quaternion. /// </summary> /// <param name="q">The quaternion to set this to.</param> public void Set(Quaternion q) { X = (short)(q.X * (float)Constants.MAX_VAL); Y = (short)(q.Y * (float)Constants.MAX_VAL); Z = (short)(q.Z * (float)Constants.MAX_VAL); W = (short)(q.W * (float)Constants.MAX_VAL); }
public static void Write(this ContentWriter contentWriter, Quaternion value) { contentWriter.Write(value.X); contentWriter.Write(value.Y); contentWriter.Write(value.Z); contentWriter.Write(value.W); }
public Interceptor(long _uniqueId, Vector3 _position, Quaternion _rotation, Team _team, SpawnShip _home) : base(_uniqueId, _position, _rotation, _team, _home) { maxZSpeed = 10000.0f; minZSpeed = 300.0f; normalZSpeed = 500.0f; ZSpeed = NormalZSpeed; MAX_HEALTH = 3; Health = MaxHealth; MAX_SHIELDS = 1; Shields = MaxShields; SHIELD_RECOVER_RATE = 0.2f; rollAccel = 10.0f; rollBreak = 5.0f; rollCap = 2.5f; pitchAccel = 7.5f; pitchBreak = 5.0f; pitchCap = 1.5f; yawAccel = 7.5f; yawBreak = 5.0f; yawCap = 1.5f; baseHeat = 0.55f; heat = 0; overheatHeat = 1.5f; heatingRate = 1.5f; coolingRate = 0.25f; heatDamageRate = 0.1f; heatWarningThreshold = 1.2f; heatDamageThreshold = 1.4f; accelerationRate = 25000.0f; FIRE_RATE = 0.1f; fireTimer = FireRate; SPECIAL_RATE = 0.5f; specialTimer = SpecialRate; PRIMARY_RANGE = 100000000f; CollisionBase = new CollisionSphere(_position, 10); CollisionBase.Parent = this; CollisionBase.addCollisionEvent(collisionEvent); if (ShipTeam == Team.Esxolus) { ((Sphere)CollisionBase.getPhysicsCollider()).CollisionInformation.CollisionRules.Group = EsxolusShipGroup; } else { ((Sphere)CollisionBase.getPhysicsCollider()).CollisionInformation.CollisionRules.Group = HalkShipGroup; } }
/// <summary> /// Constructs a new GoalPoint. /// </summary> /// <param name="position">The position.</param> /// <param name="orientation">The orientation.</param> /// <param name="scale">The amount to scale by.</param> /// <param name="nextLevel"> /// The name of the next level to load. /// An invalid name will return to the Main menu. /// </param> /// <param name="partType">The part required to pass the level.</param> public GoalPoint(Vector3 position, Quaternion orientation, Vector3 scale, string nextLevel, Type partType) : base(new ScrollingTransparentModel("tractorBeam", new Vector2(0.1f, 0.0f)), new Cylinder(position, 1f, scale.Length() * 7.0f)) { mNextLevel = nextLevel; PartType = partType; Scale = new Vector3(1.0f, 5.0f, 1.0f); }
///<summary> /// Constructs a new compound shape entry using the volume of the shape as a weight. ///</summary> ///<param name="shape">Shape to use.</param> ///<param name="orientation">Local orientation of the shape.</param> ///<param name="weight">Weight of the entry. This defines how much the entry contributes to its owner /// for the purposes of center of rotation computation.</param> public CompoundShapeEntry(EntityShape shape, Quaternion orientation, float weight) { orientation.Validate(); LocalTransform = new RigidTransform(orientation); Shape = shape; Weight = weight; }
public Rocket(RocketData data, Vector3 position, Quaternion orientation) : base(new Sphere(position, data.HitboxRadius, 5),data.ModelID) { Data = data; float x = (float)(ProjectileData.pRandom.NextDouble() - 0.5f) * data.BulletSpread; float y = (float)(ProjectileData.pRandom.NextDouble() - 0.5f) * data.BulletSpread; Quaternion random = Quaternion.CreateFromYawPitchRoll(MathHelper.ToRadians(x), MathHelper.ToRadians(y), 0); orientation = random * orientation; Vector3 velocity = Vector3.Transform(new Vector3(0,0,-Data.MuzzleVel), orientation); Entity.LinearVelocity = velocity; forwardVel = Data.MuzzleVel; Entity.Orientation = orientation; currentFuel = Data.Fuel; currentLife = Data.Lifetime; rocketMotor = new SingleEntityLinearMotor(Entity, Entity.Position); rocketMotor.Settings.Mode = MotorMode.VelocityMotor; Sector.Redria.Space.Add(rocketMotor); trackingMotor = new SingleEntityAngularMotor(Entity); trackingMotor.Settings.Mode = MotorMode.Servomechanism; trackingMotor.Settings.Servo.MaxCorrectiveVelocity = 1.5f; trackingMotor.Settings.Servo.Goal = orientation; Sector.Redria.Space.Add(trackingMotor); Entity.CollisionInformation.Events.InitialCollisionDetected += Events_InitialCollisionDetected; }
/// <summary> /// Normalizing lerp from a to b, shortest path/non constant velocity /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="t"></param> /// <param name="result"></param> /// <returns></returns> public static void Nlerp(this Quaternion a, ref Quaternion b, float t, out Quaternion result) { //return Quaternion.Normalize(Quaternion.Lerp(a, b, t)); Quaternion.Lerp(ref a, ref b, t, out result); Quaternion.Normalize(ref result, out result); }
private Quaternion GetRotation(Vector3 src, Vector3 dest) { src.Normalize(); dest.Normalize(); float d = Vector3.Dot(src, dest); if (d >= 1f) { return Quaternion.Identity; } else if (d < (1e-6f - 1.0f)) { Vector3 axis = Vector3.Cross(Vector3.UnitX, src); if (axis.LengthSquared() == 0) { axis = Vector3.Cross(Vector3.UnitY, src); } axis.Normalize(); return Quaternion.CreateFromAxisAngle(axis, MathHelper.Pi); } else { float s = (float)Math.Sqrt((1 + d) * 2); float invS = 1 / s; Vector3 c = Vector3.Cross(src, dest); Quaternion q = new Quaternion(invS * c, 0.5f * s); q.Normalize(); return q; } }
/// <summary> /// Creates a camera with vertical field of view of 45 degrees, 1.0f near clipping plane and /// 1000f far clipping plane. /// </summary> public Camera() { translation = new Vector3(); rotation = Quaternion.Identity; view = Matrix.Identity; projection = Matrix.Identity; cameraTransformation = Matrix.Identity; Vector3 location = translation; Vector3 target = -Vector3.UnitZ; Vector3.Transform(ref target, ref cameraTransformation, out target); Vector3 up = Vector3.UnitY; Vector3.Transform(ref up, ref cameraTransformation, out up); Vector3.Subtract(ref up, ref location, out up); Matrix.CreateLookAt(ref location, ref target, ref up, out view); fieldOfView = MathHelper.PiOver4; aspectRatio = State.Width / (float)State.Height; zNearPlane = 1.0f; zFarPlane = 1000.0f; Matrix.CreatePerspectiveFieldOfView(fieldOfView, aspectRatio, zNearPlane, zFarPlane, out projection); modifyView = false; modifyProjection = false; }
public Spaceship(ContentManager content) { model = XNAUtils.LoadModelWithBoundingSphere(ref transforms, ResourceNames.Spaceship, content); spacecraftPosition = new Vector3(-1, 1, 5); spacecraftRotation = Quaternion.Identity; velocity = 0; }
/// <summary> /// Constructor de la clase camara, se inicializan las matrices y se añaden al effect. /// </summary> /// <param name="effect">Effecto que se usa para dibujar.</param> /// <param name="device">El device actual.</param> public Camera(BasicEffect effect, GraphicsDevice device) { this.effect = effect; this.device = device; //Angulos inciales de la camara angleXZ = MathHelper.Pi / 4; angleYZ = MathHelper.Pi / 6; yaw = 0; pitch = 0; roll = 0; rotation = Quaternion.Identity; //Posicicón y destino inicial de la camara posicion.Y = 20 * (float)Math.Sin(angleYZ); posicion.X = 20 * (float)Math.Cos(angleYZ) * (float)Math.Sin(angleXZ); posicion.Z = 20 * (float)Math.Cos(angleYZ) * (float)Math.Cos(angleXZ); destino = new Vector3(0, 0, 0); //Se definen las matrices setCamera(); worldMatrix = Matrix.Identity; projection = Matrix.CreateOrthographic(device.Viewport.Width / 8, device.Viewport.Height / 8, -200.0f, 200.0f); //projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, device.Viewport.AspectRatio, 1.0f, 200.0f); //Se añaden al effect effect.World = worldMatrix; effect.View = viewMatrix; effect.Projection = projection; }
public EnemyFrigate(BasicModel model, CollidableType type, float boundingRadius, Vector3 shipPosition, Quaternion shipRotation, float minShipSpeed, float maxShipSpeed, float turningSpeed, float distanceThresholdEnemy, float distanceThresholdFriend, int life, List<WeaponSystem2D> weaponSystemList) { ShipPosition = shipPosition; ShipWorld = Matrix.CreateTranslation(shipPosition); ShipRotation = shipRotation; ShipSpeed = 1f; MinShipSpeed = minShipSpeed; MaxShipSpeed = maxShipSpeed; TurningSpeed = turningSpeed; DistanceThresholdEnemy = distanceThresholdEnemy; DistanceThresholdFriend = distanceThresholdFriend; this.CollidableType = type; this.BoundingSphereRadius = boundingRadius; IsFrigate = true; Life = life; _model = model; _momentum = 0f; _shipStopped = true; _weaponsList = weaponSystemList; _randomVar = new Random(); }
public OBB(Vector3 halfDim, Vector3 pos, Quaternion ori) { ori_ = ori; Pos = pos; HalfDim = halfDim; CalcMatrix(); }
public CapitalShip(long _uniqueId, Vector3 _position, Quaternion _rotation, Team _team) : base(_uniqueId, _position, _rotation, _team) { BOMBERS = 3; // 3; ASSAULT_FIGHTERS = 3; // 3; INTERCEPTORS = 3; // 3; INITIAL_BOMBERS = 9; // 9; INITIAL_ASSAULT_FIGHTERS = 9; // 9; INITIAL_INTERCEPTORS = 9; // 9; MAX_BOMBERS = 96; MAX_ASSAULT_FIGHTERS = 96; MAX_INTERCEPTORS = 96; launchedBombers = 0; launchedAssaultFighters = 0; launchedInterceptors = 0; WAVES_TO_LAUNCH = 30; wavesLaunched = 0; MAX_HEALTH = 1000; Health = MaxHealth; MAX_SHIELDS = 1000; Shields = MaxShields; MAX_ATTACKERS = 5; Attackable = true; }
public Bone(FileReader Reader, int Index) { BoneIndex = Index; Reader.ReadUInt32(); //Unknown Name = Reader.ReadPascalString(); ParentName = Reader.ReadPascalString(); HasPropertyList = (Reader.ReadByte() != 0) ? true : false; if(HasPropertyList) { uint PropertyCount = Reader.ReadUInt32(); for (int i = 0; i < PropertyCount; i++) PropertyList.Add(new Property(Reader)); } Translation = new Vector3(Reader.ReadFloat(), Reader.ReadFloat(), Reader.ReadFloat()); Rotation = new Quaternion(Reader.ReadFloat(), -Reader.ReadFloat(), -Reader.ReadFloat(), Reader.ReadFloat()); CanTranslate = (Reader.ReadUInt32() != 0) ? true : false; CanRotate = (Reader.ReadUInt32() != 0) ? true : false; CanBlend = (Reader.ReadUInt32() != 0) ? true : false; //Don Hopkins says the Wiggle parameters are left over from an attempt to use Perlin noise //introduce some randomness into the animations, so that an animation would look a little different //each time it was run. Reader.ReadFloat(); Reader.ReadFloat(); }
public Bullet(Vector3 initPos, Quaternion initQRot) { age = 0; position = initPos; qRotation = initQRot; velocity = new Vector3(0, 0, 400); }
public LevelPiece(Game game, GameplayScreen host, String assetName) : base(game, host) { // TODO: Construct any child components here modelName = assetName; position = new Vector3(0f, 0f, 0f); // DO NOT ADJUST SCALE IN A CONSTRUCTOR //scale = 50; m_rotX = 0; m_rotZ = 0; //quat = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), (float)Math.PI / 2); quat = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), 0); originalRot = quat; m_rotationOffset = Vector3.Zero; //effect.TextureEnabled = true; m_localRotation = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), 0); m_fScaleX = 1.0f; m_fScaleY = 1.0f; m_fScaleZ = 1.0f; enableCelShading = true; mixCelWithTexture = false; celLightColor = Color.SkyBlue.ToVector4(); outlineThickness = 0.000f; layerTwoSharp = 0.3f; layerTwoContrib = 0.08f; }
public FirstPersonCamera(Game game) : base(game) { UpdateOrder = 1; // Initialize camera state. accumHeadingDegrees = 0.0f; accumPitchDegrees = 0.0f; eye = Vector3.Zero; target = Vector3.Zero; targetYAxis = Vector3.UnitY; xAxis = Vector3.UnitX; yAxis = Vector3.UnitY; zAxis = Vector3.UnitZ; viewDir = Vector3.Forward; acceleration = new Vector3(DEFAULT_ACCELERATION_X, DEFAULT_ACCELERATION_Y, DEFAULT_ACCELERATION_Z); velocityWalking = new Vector3(DEFAULT_VELOCITY_X, DEFAULT_VELOCITY_Y, DEFAULT_VELOCITY_Z); velocityRunning = velocityWalking * DEFAULT_RUNNING_MULTIPLIER; velocity = velocityWalking; orientation = Quaternion.Identity; viewMatrix = Matrix.Identity; rotationSpeed = 0.2f; PCinput = new SystemInput.PCinput(); // Setup perspective projection matrix. clientBounds = game.Window.ClientBounds; float aspect = (float)clientBounds.Width / (float)clientBounds.Height; Perspective(DEFAULT_FOVX, aspect, DEFAULT_ZNEAR, DEFAULT_ZFAR); direction = new Vector3(); smoothedMouseMovement = new Vector2(); }
public GameCamera(Scene _currentScene, Vector3 _position, Quaternion _rotation, float _aspectRatio) { currentScene = _currentScene; position = _position; rotation = _rotation; aspectRatio = _aspectRatio; up = new Vector3(0, 1, 0); target = new Vector3(); viewMatrix = Matrix.CreateLookAt(position, target, up); projectionMatrix = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(45.0f), aspectRatio, 0.1f, VIEW_DEPTH); viewPort = Space394Game.GameInstance.GraphicsDevice.Viewport; fourthPort = new Viewport( Space394Game.GameInstance.DefaultViewPort.Width / 2 + 1, Space394Game.GameInstance.DefaultViewPort.Height / 2 + 1, Space394Game.GameInstance.DefaultViewPort.Width / 2 - 1, Space394Game.GameInstance.DefaultViewPort.Height / 2 - 1); splitScreen2 = new AutoTexture2D(Space394Game.GameInstance.Content.Load<Texture2D>("Textures\\splitScreen2"), Vector2.Zero); splitScreen3 = new AutoTexture2D(Space394Game.GameInstance.Content.Load<Texture2D>("Textures\\splitScreen3"), Vector2.Zero); splitScreen4 = new AutoTexture2D(Space394Game.GameInstance.Content.Load<Texture2D>("Textures\\splitScreen4"), Vector2.Zero); blackTexture = new AutoTexture2D(Space394Game.GameInstance.Content.Load<Texture2D>("Textures\\blackTexture"), Vector2.Zero); blackTexture.Width = fourthPort.Width; blackTexture.Height = fourthPort.Height; pausedTexture = new AutoTexture2D(Space394Game.GameInstance.Content.Load<Texture2D>("Textures\\pausedTexture"), Vector2.Zero); }
public Turret(long _uniqueId, Vector3 _position, Quaternion _rotation, String _modelFile, Vector3 _fireConeNormal, float _fireConeAngle, Battleship _parent) : base(_uniqueId, _position, _rotation, _modelFile) { Health = MAX_HEALTH; fireConeNormalVector = _fireConeNormal; fireConeNormalVector.Normalize(); // Just in case fireConeAngle = MathHelper.ToRadians(_fireConeAngle); parent = _parent; assignedPhase = nextAssignedPhase; switch (nextAssignedPhase) { case activationPhase.first: nextAssignedPhase = activationPhase.second; break; case activationPhase.second: nextAssignedPhase = activationPhase.third; break; case activationPhase.third: nextAssignedPhase = activationPhase.first; break; } MAX_SLERP = SLERP_SPEED; Rotation = AdjustRotationNoLimit(Vector3.Backward, fireConeNormalVector, Vector3.Up); fireTimer = FIRE_TIMER; detectionSphere = new CollisionSphere(_position, FIRE_RANGE); detectionSphere.Active = true; }
/// <summary> /// Gets the value of the parameter as a quaternion. /// </summary> /// <returns> /// The quaternion value /// </returns> public Quaternion GetValueQuaternion() { XNA.Quaternion xq = _param.GetValueQuaternion(); Quaternion q; XNAHelper.ConvertQuaternion(ref xq, out q); return(q); }
public Camera() { this.cameraRotation = new MXF.Quaternion(); this.cameraPosition = MXF.Vector3.Zero; this.yaw = 0; this.pitch = 0; this.roll = 0; }
public static Quaternion Convert(Microsoft.Xna.Framework.Quaternion quaternion) { Quaternion toReturn; toReturn.X = quaternion.X; toReturn.Y = quaternion.Y; toReturn.Z = quaternion.Z; toReturn.W = quaternion.W; return(toReturn); }
public void Rotate(float xRotation, float yRotation, float zRotation) { this.yaw += xRotation; this.pitch += yRotation; this.roll += zRotation; MXF.Quaternion q1 = MXF.Quaternion.CreateFromAxisAngle(new MXF.Vector3(0, 1, 0), this.yaw); MXF.Quaternion q2 = MXF.Quaternion.CreateFromAxisAngle(new MXF.Vector3(1, 0, 0), this.pitch); MXF.Quaternion q3 = MXF.Quaternion.CreateFromAxisAngle(new MXF.Vector3(0, 0, 1), this.roll); this.cameraRotation = q1 * q2 * q3; }
/// <summary> /// The constructor for the VRPN tracker /// </summary> public VRPNTracker() { identifier = "VRPNTracker"; trackerName = "Tracker 1"; ipAddress = "localhost"; tracker = new TrackerRemote(trackerName + "@" + ipAddress); isAvailable = true; _orientation = Microsoft.Xna.Framework.Quaternion.Identity; _yaw = 0; _pitch = 0; _roll = 0; _position = Microsoft.Xna.Framework.Vector3.One; _xpos = 0; _ypos = 0; _zpos = 0; }
/// <summary> /// Updates the VRPN tracker whenever it changes position /// </summary> /// <param name="sender"></param> /// <param name="e"> Information about the object tracked</param> private void PositionChanged(object sender, TrackerChangeEventArgs e) { //We convert movement to millimeters. _position = new Microsoft.Xna.Framework.Vector3((float)e.Position.X, (float)e.Position.Y, (float)e.Position.Z); _xpos = (float)e.Position.X; _ypos = (float)e.Position.Y; _zpos = (float)e.Position.Z; // tools inverts e.Orientation.Z for packetizing/sending, so invert it back _orientation = new Microsoft.Xna.Framework.Quaternion((float)e.Orientation.X, (float)e.Orientation.Y, (float)e.Orientation.Z, (float)e.Orientation.W); Vector3Helper.QuaternionToEuler(e.Orientation.X, e.Orientation.Y, e.Orientation.Z, e.Orientation.W, out _yaw, out _pitch, out _roll); _pitch *= -1; Matrix.CreateFromQuaternion(ref _orientation, out worldTransform); worldTransform.Translation = _position; }
public void SetLookRotation(Vector3 view, Vector3 up) { if (view == up) { quaternion = new Microsoft.Xna.Framework.Quaternion(-0.7f, 0, 0, 0.7f); return; } if (view == -up) { quaternion = new Microsoft.Xna.Framework.Quaternion(0.7f, 0, 0, 0.7f); return; } Matrix m = Matrix.CreateWorld(Vector3.zero, view, up); Microsoft.Xna.Framework.Vector3 scale; Microsoft.Xna.Framework.Vector3 pos; if (!m.Decompose(out scale, out quaternion, out pos) || float.IsNaN(quaternion.W)) { quaternion = Quaternion.identity; } }
public static void Transform(Vector4[] sourceArray, ref Quaternion rotation, Vector4[] destinationArray) { throw new NotImplementedException(); }
public void GetSRT(Microsoft.Xna.Framework.Matrix m) { Microsoft.Xna.Framework.Vector3 scale = Microsoft.Xna.Framework.Vector3.Zero; Microsoft.Xna.Framework.Vector3 translate = Microsoft.Xna.Framework.Vector3.Zero; Microsoft.Xna.Framework.Quaternion q = Microsoft.Xna.Framework.Quaternion.Identity; m.Decompose(out scale, out q, out translate); this.tX = translate.X; this.tY = translate.Y; this.tZ = translate.Z; this.sX = scale.X; this.sY = scale.Y; this.sZ = scale.Z; float Singularity = 0.499f; float ww = q.W * q.W; float xx = q.X * q.X; float yy = q.Y * q.Y; float zz = q.Z * q.Z; float lengthSqd = xx + yy + zz + ww; float singularityTest = q.Y * q.W - q.X * q.Z; float singularityValue = Singularity * lengthSqd; if (singularityTest > singularityValue) { this.rX = (-2f * (float)Math.Atan2(q.Z, q.W)); this.rY = (90.0f) * (float)(Math.PI / 180); this.rZ = (0f) * (float)(Math.PI / 180); } else { if (singularityTest < -singularityValue) { this.rX = (2 * (float)Math.Atan2(q.Z, q.W)); this.rY = (-90.0f) * (float)(Math.PI / 180); this.rZ = (0f) * (float)(Math.PI / 180); } else { this.rX = ((float)Math.Atan2(2.0f * (q.Y * q.Z + q.X * q.W), 1.0f - 2.0f * (xx + yy))); this.rY = ((float)Math.Asin(2.0f * singularityTest / lengthSqd)); this.rZ = ((float)Math.Atan2(2.0f * (q.X * q.Y + q.Z * q.W), 1.0f - 2.0f * (yy + zz))); } } while (this.rX > Math.PI) { this.rX -= (float)(2 * Math.PI); } while (this.rX < -Math.PI) { this.rX += (float)(2 * Math.PI); } while (this.rY > Math.PI) { this.rY -= (float)(2 * Math.PI); } while (this.rY < -Math.PI) { this.rY += (float)(2 * Math.PI); } while (this.rZ > Math.PI) { this.rZ -= (float)(2 * Math.PI); } while (this.rZ < -Math.PI) { this.rZ += (float)(2 * Math.PI); } }
public static Vector4 Transform(Vector4 value, Quaternion rotation) { throw new NotImplementedException(); }
/// <summary> /// Imports an FBX animation, storing the transformations that apply to each bone at each time. /// </summary> /// <param name="name"> /// The name of the animation. /// </param> /// <param name="assimpAnimation"> /// The AssImp animation to apply to the scene. /// </param> /// <returns> /// The <see cref="IAnimation"/> representing the imported animation. /// </returns> private IAnimation ImportAnimation(string name, Assimp.Animation assimpAnimation) { var translation = new Dictionary <string, IDictionary <double, Vector3> >(); var rotation = new Dictionary <string, IDictionary <double, Quaternion> >(); var scale = new Dictionary <string, IDictionary <double, Vector3> >(); foreach (var animChannel in assimpAnimation.NodeAnimationChannels) { if (animChannel.HasPositionKeys) { if (!translation.ContainsKey(animChannel.NodeName)) { translation[animChannel.NodeName] = new Dictionary <double, Vector3>(); } foreach (var positionKey in animChannel.PositionKeys) { var vector = new Vector3(positionKey.Value.X, positionKey.Value.Y, positionKey.Value.Z); translation[animChannel.NodeName].Add(positionKey.Time, vector); } } if (animChannel.HasRotationKeys) { if (!rotation.ContainsKey(animChannel.NodeName)) { rotation[animChannel.NodeName] = new Dictionary <double, Quaternion>(); } foreach (var rotationKey in animChannel.RotationKeys) { var quaternion = new Quaternion( rotationKey.Value.X, rotationKey.Value.Y, rotationKey.Value.Z, rotationKey.Value.W); rotation[animChannel.NodeName].Add(rotationKey.Time, quaternion); } } if (animChannel.HasScalingKeys) { if (!scale.ContainsKey(animChannel.NodeName)) { scale[animChannel.NodeName] = new Dictionary <double, Vector3>(); } foreach (var scaleKey in animChannel.ScalingKeys) { var vector = new Vector3(scaleKey.Value.X, scaleKey.Value.Y, scaleKey.Value.Z); scale[animChannel.NodeName].Add(scaleKey.Time, vector); } } } return(new Animation( name, assimpAnimation.TicksPerSecond, assimpAnimation.DurationInTicks, translation, rotation, scale)); }
protected override void Execute(List <CommandEntity> entities) { foreach (var e in entities) { var playerEntities = m_contexts.game.GetEntitiesWithPlayerId(e.commandOwner.value); if (playerEntities.Count == 0) { continue; } var playerEntity = playerEntities.SingleEntity(); if (e.moveCommand.value.LengthSquared() > 0.1f) { float angularSpeed = playerEntity.angularSpeed.value; Vector3 dir = playerEntity.direction.value; Vector3 targetDir = e.moveCommand.value; // dot(dir, rot90CCW(targetDir)) float angle = 0f; float dot = dir.X * -targetDir.Y + dir.Y * targetDir.X; // parallel/antiparallel if (Math.Abs(dot) <= ANGLE_TOLERANCE) { Services.Get <ILogService>().LogInfo("parallel/antiparallel"); if (Vector3.Dot(dir, targetDir) < 0f) { angle = angularSpeed * m_timeService.FrameInterval; } } // targetDir is in right of dir, else if (dot > float.Epsilon) { Services.Get <ILogService>().LogInfo("targetDir is in right of dir " + dot.ToString()); angle = -angularSpeed * m_timeService.FrameInterval; float d = MathHelper.ToDegrees((float)Math.Acos(dot)) - 90f; // over rotation if (Math.Abs(angle) > Math.Abs(d)) { angle = d; } } // targetDir is in left of dir else { Services.Get <ILogService>().LogInfo("targetDir is in left of dir" + dot.ToString()); angle = angularSpeed * m_timeService.FrameInterval; float d = MathHelper.ToDegrees((float)Math.Acos(dot)) - 90f; // over rotate if (Math.Abs(angle) > Math.Abs(d)) { angle = d; } } var quat = Quaternion.CreateFromAxisAngle(Vector3.Backward, MathHelper.ToRadians(angle)); var targetQuat = Quaternion.Multiply(playerEntity.rotation.value, quat); playerEntity.ReplaceRotation(targetQuat); playerEntity.ReplaceDirection(Vector3.Normalize(Vector3.Transform(Vector3.Right, targetQuat))); playerEntity.ReplaceSpeed(playerEntity.speed.maxValue, playerEntity.speed.maxValue); } else { playerEntity.ReplaceSpeed(0f, playerEntity.speed.maxValue); } } }
public static System.Numerics.Quaternion ToCS(this Microsoft.Xna.Framework.Quaternion quaternion) { return(new System.Numerics.Quaternion(quaternion.X, quaternion.Y, quaternion.Z, quaternion.W)); }
public Quaternion(float x, float y, float z, float w) { quaternion = new Microsoft.Xna.Framework.Quaternion(x, y, z, w); }
public Quaternion(Microsoft.Xna.Framework.Quaternion q) { quaternion = q; }
public static void Transform(ref Vector4 value, ref Quaternion rotation, out Vector4 result) { throw new NotImplementedException(); }
public static void Transform(Vector4[] sourceArray, int sourceIndex, ref Quaternion rotation, Vector4[] destinationArray, int destinationIndex, int length) { throw new NotImplementedException(); }