public Torus(GraphicsDevice device, float diameter, float thickness, int tessellation, float circlePercent = 1f, Vector3 translation = default (Vector3), Angles3 rotation = default (Angles3)) : base(translation: translation, rotation: rotation) { if (tessellation < 3) { throw new ArgumentOutOfRangeException ("cylinder tessellation"); } circlePercent = MathHelper.Clamp (circlePercent, 0f, 1f); for (int i = 0; i < tessellation; i++) { float outerAngle = i * MathHelper.TwoPi * circlePercent / (tessellation-1); float textureU = (float)i / (float)(tessellation - 1); if (circlePercent < 1f) { textureU = MathHelper.Clamp (textureU, 0.25f, 0.75f); } Matrix transform = Matrix.CreateTranslation (diameter / 2, 0, 0) * Matrix.CreateRotationY (outerAngle); // Now we loop along the other axis, around the side of the tube. for (int j = 0; j < tessellation; j++) { float innerAngle = j * MathHelper.TwoPi / tessellation; float textureV = 0;//(float)j / (float)tessellation; float dx = (float)System.Math.Cos (innerAngle); float dy = (float)System.Math.Sin (innerAngle); // Create a vertex. Vector3 normal = new Vector3 (dx, dy, 0); Vector3 position = normal * thickness / 2; position = Vector3.Transform (position, transform); normal = Vector3.TransformNormal (normal, transform); AddVertex (position: position, normal: normal, texCoord: new Vector2 (textureU, textureV)); // And create indices for two triangles. if (i + 1 < tessellation || circlePercent == 1f) { int nextI = (i + 1) % tessellation; int nextJ = (j + 1) % tessellation; if (nextI < tessellation) { AddIndex (i * tessellation + j); AddIndex (i * tessellation + nextJ); AddIndex (nextI * tessellation + j); AddIndex (i * tessellation + nextJ); AddIndex (nextI * tessellation + nextJ); AddIndex (nextI * tessellation + j); } } } } InitializePrimitive (device); }
public GameObject(Vector3 position = default (Vector3), Angles3 rotation = default (Angles3), Vector3 scale = default (Vector3), bool isVisible = true, bool isSelectable = false, bool isMovable = false) { Position = position; Scale = scale.Length () != 0 ? scale : Vector3.One; IsVisible = isVisible; IsSelectable = isSelectable; IsMovable = isMovable; Bounds = new BoundingSphere [0]; UniqueKey = GetType ().Name; IsLightingEnabled = true; IsSkyObject = false; Coloring = new SingleColor (Color.Transparent); }
public GameObject(Vector3 position = default(Vector3), Angles3 rotation = default(Angles3), Vector3 scale = default(Vector3), bool isVisible = true, bool isSelectable = false, bool isMovable = false) { Position = position; Scale = scale.Length() != 0 ? scale : Vector3.One; IsVisible = isVisible; IsSelectable = isSelectable; IsMovable = isMovable; Bounds = new BoundingSphere [0]; UniqueKey = GetType().Name; IsLightingEnabled = true; IsSkyObject = false; Coloring = new SingleColor(Color.Transparent); }
public void TestNativeManagedEqualityAngles3() { //managed Angles3 angles = new Angles3(1f, 2f, 3f); Quaternion managedQuaternion = new Quaternion(angles); //native Ang3 angles2 = angles; Quat nativeQuaternion = Quat.CreateIdentity(); nativeQuaternion.SetRotationXYZ(angles2); Assert.IsTrue(managedQuaternion == nativeQuaternion); }
private void UpdatePrecomputed(bool overrideValues = false) { if (overrideValues || Scale != _scale || Rotation != _rotation || Position != _position) { Matrix rotationMatrix = _rotationQuaternion.HasValue ? Matrix.CreateFromQuaternion(_rotationQuaternion.Value) : Matrix.CreateFromYawPitchRoll(Rotation.Y, Rotation.X, Rotation.Z); // world matrix _worldMatrix = Matrix.CreateScale(Scale) * rotationMatrix * Matrix.CreateTranslation(Position); _worldMatrixInverseTranspose = Matrix.Transpose(Matrix.Invert(_worldMatrix)); // attrs _scale = Scale; _rotation = Rotation; _position = Position; } }
public Primitive(Vector3 translation, Angles3 rotation) { vertexTransform = Matrix.CreateTranslation (translation) * Matrix.CreateFromYawPitchRoll (rotation.Y, rotation.X, rotation.Z); }
public Torus(GraphicsDevice device, float diameter, float thickness, int tessellation, float circlePercent = 1f, Vector3 translation = default(Vector3), Angles3 rotation = default(Angles3)) : base(translation: translation, rotation: rotation) { if (tessellation < 3) { throw new ArgumentOutOfRangeException("cylinder tessellation"); } circlePercent = MathHelper.Clamp(circlePercent, 0f, 1f); for (int i = 0; i < tessellation; i++) { float outerAngle = i * MathHelper.TwoPi * circlePercent / (tessellation - 1); float textureU = (float)i / (float)(tessellation - 1); if (circlePercent < 1f) { textureU = MathHelper.Clamp(textureU, 0.25f, 0.75f); } Matrix transform = Matrix.CreateTranslation(diameter / 2, 0, 0) * Matrix.CreateRotationY(outerAngle); // Now we loop along the other axis, around the side of the tube. for (int j = 0; j < tessellation; j++) { float innerAngle = j * MathHelper.TwoPi / tessellation; float textureV = 0;//(float)j / (float)tessellation; float dx = (float)System.Math.Cos(innerAngle); float dy = (float)System.Math.Sin(innerAngle); // Create a vertex. Vector3 normal = new Vector3(dx, dy, 0); Vector3 position = normal * thickness / 2; position = Vector3.Transform(position, transform); normal = Vector3.TransformNormal(normal, transform); AddVertex(position: position, normal: normal, texCoord: new Vector2(textureU, textureV)); // And create indices for two triangles. if (i + 1 < tessellation || circlePercent == 1f) { int nextI = (i + 1) % tessellation; int nextJ = (j + 1) % tessellation; if (nextI < tessellation) { AddIndex(i * tessellation + j); AddIndex(i * tessellation + nextJ); AddIndex(nextI * tessellation + j); AddIndex(i * tessellation + nextJ); AddIndex(nextI * tessellation + nextJ); AddIndex(nextI * tessellation + j); } } } } InitializePrimitive(device); }
private void UpdatePrecomputed(bool overrideValues = false) { if (overrideValues || Scale != _scale || Rotation != _rotation || Position != _position) { Matrix rotationMatrix = _rotationQuaternion.HasValue ? Matrix.CreateFromQuaternion (_rotationQuaternion.Value) : Matrix.CreateFromYawPitchRoll (Rotation.Y, Rotation.X, Rotation.Z); // world matrix _worldMatrix = Matrix.CreateScale (Scale) * rotationMatrix * Matrix.CreateTranslation (Position); _worldMatrixInverseTranspose = Matrix.Transpose (Matrix.Invert (_worldMatrix)); // attrs _scale = Scale; _rotation = Rotation; _position = Position; } }
public Primitive(Vector3 translation, Angles3 rotation) { vertexTransform = Matrix.CreateTranslation(translation) * Matrix.CreateFromYawPitchRoll(rotation.Y, rotation.X, rotation.Z); }
public static BoundingSphere Rotate(this BoundingSphere sphere, Angles3 rotation) { return(new BoundingSphere(Vector3.Transform(sphere.Center, Matrix.CreateFromYawPitchRoll(rotation.Y, rotation.X, rotation.Z)), sphere.Radius)); }
public void Angles3_Operator_Test() { Angles3 angle2 = new Angles3 (1, 2, 3); Angles3 angle4 = new Angles3 (3, 2, 1); Angles3 sum = angle2 + angle4; Assert.AreEqual (sum, new Angles3 (4, 4, 4)); Angles3 neg = -angle2; Assert.AreEqual (neg, new Angles3 (-1, -2, -3)); Angles3 diff = angle2 - angle4; Assert.AreEqual (diff, new Angles3 (-2, 0, 2)); Angles3 prod = angle2 * angle4; Assert.AreEqual (prod, new Angles3 (3, 4, 3)); Angles3 scale1 = angle2 * scaleFactor; Angles3 scale2 = scaleFactor * angle2; Assert.AreEqual (scale1, new Angles3 (2.5f, 5, 7.5f)); Assert.AreEqual (scale2, new Angles3 (2.5f, 5, 7.5f)); Angles3 quot1 = angle2 / angle4; Assert.AreEqual (quot1, new Angles3 (0.33333333333f, 1, 3)); Angles3 quot2 = angle2 / divider; Assert.AreEqual (quot2, angle2); Assert.AreEqual (angle2, angle2); Assert.AreNotEqual (angle2, angle4); Assert.IsTrue (angle1 != angle2); }
public void Angles3_FromDegrees_Test() { angle2 = Angles3.FromDegrees (X, Y, Z); Assert.AreEqual (angle1, angle2); }
public void Init() { X = 120; Y = 50; Z = 280; rX = 2.0943951023931953f; rY = 0.8726646259971648f; rZ = 4.886921905584122f; redianX = X * ((float)System.Math.PI / 180); redianY = Y * ((float)System.Math.PI / 180); redianZ = Z * ((float)System.Math.PI / 180); redian = new Vector3 (redianX, redianY, redianZ); angle1 = new Angles3 (redian); angle3 = new Angles3 (rX, rY, rZ); obj = angle1; scaleFactor = 2.5f; divider = 1; }
public GameModelInfo(string modelname) { Modelname = modelname; Rotation = Angles3.Zero; Scale = Vector3.One; }
private void UpdatePrecomputed() { if (Info.Scale != _scale || Info.Rotation != _rotation || Info.Position != _position) { // world matrix _worldMatrix = Matrix.CreateScale (Info.Scale) * Matrix.CreateFromYawPitchRoll (Info.Rotation.Y, Info.Rotation.X, Info.Rotation.Z) * Matrix.CreateTranslation (Info.Position); // bounding spheres _bounds = Model.Bounds ().ToArray (); for (int i = 0; i < _bounds.Length; ++i) { _bounds [i] = _bounds [i].Scale (Info.Scale).Rotate(Info.Rotation).Translate ((Vector3)Info.Position); } // attrs _scale = Info.Scale; _rotation = Info.Rotation; _position = Info.Position; } }