public Gun(string texture, float xPos, float yPos) { gunTexture = LoadTexture(texture); localTransform = new Matrix3(); localTransform.m3 = xPos - gunTexture.width / 2; localTransform.m6 = yPos; }
public void UpdateAllTransforms(Matrix3 _globalTransform) { // globalTransform = _globalTransform * localTransform; SetRotation(_globalTransform); foreach (GameObject child in children) { child.UpdateAllTransforms(); } }
// works out the objects rotation Matrix and then sets the rotation. // finally it calls UpdateAllTransforms for this and all child objects, public void Rotate(float radians) { Matrix3 m = new Matrix3(); m.SetRotateZ(radians); SetRotation(localTransform * m); UpdateAllTransforms(); }
// Sets rotation by ensuring vales are correct in the objects local transform public void SetRotation(Matrix3 m) { localTransform.m1 = m.m1; localTransform.m2 = m.m2; localTransform.m3 = m.m3; localTransform.m4 = m.m4; localTransform.m5 = m.m5; localTransform.m6 = m.m6; localTransform.m7 = m.m7; localTransform.m8 = m.m8; localTransform.m9 = m.m9; }
// If the child has a parent this funciton will offset their global Position to that of the parent. // Then it calls this function on each child to ensure all objects move as a group in correct positions public void UpdateAllTransforms() { if (parent != null) { globalTransform = parent.globalTransform * localTransform; } else { globalTransform = localTransform; } foreach (GameObject child in children) { child.UpdateAllTransforms(); } }
public void UpdateTransform(Matrix3 _transform) { transform = _transform * localTransform; }
public void Set(Matrix3 m) { m1 = m.m1; m2 = m.m2; m3 = m.m3; m4 = m.m4; m5 = m.m5; m6 = m.m6; m7 = m.m7; m8 = m.m8; m9 = m.m9; }
public Matrix3(Matrix3 other) { }
public void Set(Matrix3 scaled) { m11 = scaled.m11; m12 = scaled.m12; m13 = scaled.m13; m21 = scaled.m21; m22 = scaled.m22; m23 = scaled.m23; m31 = scaled.m31; m32 = scaled.m32; m33 = scaled.m33; }
// public void Rotate(float rotate, float speed, float deltaTime) public void Rotate(float radians) { Matrix3 m = new Matrix3(); m.SetRotateZ(radians); setRotation(localTransform * m); /* float rotate = GetRotation(); * * tankTranslation = new Matrix3(1.0f, 0.0f, transform.m3, * 0.0f, 1.0f, transform.m6, * 0.0f, 0.0f, 1.0f); * tankRotation = new Matrix3(); * Console.WriteLine("delta \n" + deltaTime + "\nrotate\n" + rotate); * tankRotation.SetRotateZ(deltaTime); * * * Matrix3 tankRotationTwo = new Matrix3(); * Console.WriteLine("delta \n" + deltaTime + "\nrotate\n" + rotate); * tankRotationTwo.SetRotateZ(rotate); * tankRotation = tankRotationTwo * tankRotation; * * Matrix3 mat = transform * tankRotation; * mat.m3 = transform.m3; * mat.m6 = transform.m6; * mat.m9 = 1; * transform = mat; * * UpdateGunTransform();*/ /*rotation += (rotate * DEG2RAD); * * tankTranslation = new Matrix3(1.0f, 0.0f, position.x, * 0.0f, 1.0f, position.y, * 0.0f, 0.0f, 1.0f); * tankRotation = new Matrix3(); * tankRotation.SetRotateZ(rotation * DEG2RAD); * * Console.WriteLine("tankRotation"); * Console.WriteLine(tankRotation.ToString()); * * Matrix3 mat = tankTranslation * tankRotation; * Vector3 newPos = mat * new Vector3(0, 0, 1) * speed * deltaTime; * * position = position + newPos; */ // Vector3 newPosGun = mat * new Vector3(0, 0, 1) * speed * deltaTime; // gunPosition = gunPosition + newPosGun; // gunPosition = gunPosition + gunPositionOffset; //Console.WriteLine("Rotation: " + rotation); //tankTranslation = new Matrix3(1.0f, 0.0f, position.x, // 0.0f, 1.0f, position.x, // 0.0f, 0.0f, position.z); //tankRotation = new Matrix3(); //tankRotation.SetRotateZ(rotation*DEG2RAD); // tankMatrix = tankTranslation * tankRotation; //position = position + movement * speed * deltaTime; //Matrix3 rotateMatrix = new Matrix3(); //rotateMatrix.SetRotateZ(rotate*speed*deltaTime); //tankMatrix = tankMatrix * rotateMatrix; //Vector3 newVec = new Vector3(tankMatrix.m3, tankMatrix.m6, tankMatrix.m9); //position = position.Cross(newVec);//* tankMatrix ; //Console.WriteLine("Matrix"); //Console.WriteLine(tankMatrix.ToString()); //Console.WriteLine("position"); //Console.WriteLine(position.ToString()); //gunPositionOffset = gunPositionOffset + movement * speed * deltaTime; }
//public Vector3 GetPosition() //{ // return new Vector3(transform.m3, transform.m6, transform.m9); //} // public void UpdateGunTransform() public void UpdateTransform() { globalTransform = localTransform; //topGun.UpdateTransform(globalTransform); }