Beispiel #1
0
 public void SetVector(Vector3D vector)
 {
     X = vector.X;
     Y = vector.Y;
     Z = vector.Z;
     W = vector.W;
 }
Beispiel #2
0
 public Vector3D TransformConstant(Matrix3D matrix, Vector3D vector_out)
 {
     vector_out.X = X * matrix.XX + Y * matrix.YX + Z * matrix.ZX + W * matrix.WX;
     vector_out.Y = Y * matrix.XY + Y * matrix.YY + Z * matrix.ZY + W * matrix.WY;
     vector_out.Z = Z * matrix.XZ + Y * matrix.YZ + Z * matrix.ZZ + W * matrix.WZ;
     vector_out.W = Z * matrix.XW + Y * matrix.YW + Z * matrix.ZW + W * matrix.WW;
     return vector_out;
 }
Beispiel #3
0
        protected void UpdateGroundShadows(IAddCommand seq)
        {
            seq.AddCommand(new RSCommand("element_set_attribute",
                    "element_name", Viewport.Scene.OptionsName,
                    "attribute_name", "environment_dome_ground",
                    "attribute_type", "Boolean",
                    "attribute_value", Enabled,
                    "create", true
            ));
        
            if (Enabled)
            {
                Vector3D position = new Vector3D(0, Viewport.Scene.BBoxMin.Y);
                if (!AutoCalculateGroundHeight)
                {
                    position.Y = GroundHeight;
                }

                seq.AddCommand(new RSCommand("element_set_attribute",
                        "element_name", Viewport.Scene.OptionsName,
                        "attribute_name", "environment_dome_ground_position",
                        "attribute_type", "Float32<3>",
                        "attribute_value", position.GetVectorForRS(),
                        "create", true
                ));
                
                Vector3D axis = new Vector3D(0, 0, 1);
                if (Viewport.SceneYUp)
                {
                    axis.Y = 1;
                    axis.Z = 0;
                }

                seq.AddCommand(new RSCommand("element_set_attribute",
                        "element_name", Viewport.Scene.OptionsName,
                        "attribute_name", "environment_dome_rotation_axis",
                        "attribute_type", "Float32<3>",
                        "attribute_value", axis.GetVectorForRS(),
                        "create", true
                ));
            }
        }
Beispiel #4
0
 public void SetLookAt(Vector3D position, Vector3D direction, Vector3D up)
 {
     location = position;
     if (direction != null && up != null && direction.IsNotColinear(up))
     {
         direction.Normalize();
         up.Normalize();
         this.direction = direction.clone();
         this.up = up.clone();
         CalcRU();
         DeriveMatrix();
     }
 }
Beispiel #5
0
 public void SetLookAtPoint(Vector3D position, Vector3D target, Vector3D up)
 {
     Vector3D direction = target.clone().Sub(position);
     if (direction != null && up != null && direction.IsNotColinear(up))
     {
         this.location = position;
         this.target = target;
         direction.Normalize();
         up.Normalize();
         this.direction = direction.clone();
         this.up = up.clone();
         CalcRU();
         DeriveMatrix();
     }
 }
Beispiel #6
0
        public void DeriveVectors() {
            Matrix3D m = world_to_object.Clone();
            m.Invert();

            double d = target.Sub(location).Length();
            if (d <= 0)
                d = 10;

            location.SetVector(new Vector3D(0, 0, 0));
            location.TransformTranspose(m);
            
            direction.SetVector(new Vector3D(0, 0, -1));
            direction.RotateTranspose(m);
            direction.Normalize();

            up.SetVector(new Vector3D(0, 1, 0));
            up.RotateTranspose(m);
            up.Normalize();

            right.SetVector(new Vector3D(1, 0, 0));
            right.RotateTranspose(m);
            right.Normalize();

            target = location.clone().Add(direction.clone().Scale(d));
        }
Beispiel #7
0
        public void DeriveMatrix()
        {
            world_to_object.Identity();
            world_to_object.XX = right.X;
            world_to_object.YX = right.Y;
            world_to_object.ZX = right.Z;

            world_to_object.XY = up.X;
            world_to_object.YY = up.Y;
            world_to_object.ZY = up.Z;

            world_to_object.XZ = -direction.X;
            world_to_object.YZ = -direction.Y;
            world_to_object.ZZ = -direction.Z;

            Vector3D v = new Vector3D();
            for (int i = 0; i < 3; i++)
            {
                v.SetVector(new Vector3D(world_to_object.raw[0, i], world_to_object.raw[1, i], world_to_object.raw[2, i]));
                world_to_object.raw[3, i] = -1 * location.Dot(v);
            }
        }
Beispiel #8
0
        /**
         * Handle the bounding box response.
         */
        protected void OnSceneGetBoundingBox(RSResponse resp)
        {
            if (resp.IsErrorResponse)
            {
                Logger.Log("error", "Error getting scene bounding box: " + resp.ErrorMessage);
                Status("error", "Error importing scene");
                return;
            }

            Hashtable bbox = resp.Result as Hashtable;
            if (bbox == null)
            {
                Logger.Log("error", "Scene bounding box result was not an object: " + resp.Result.GetType());
                Status("error", "Error importing scene");
                return;
            }
            
            BBoxMax = new Vector3D(
                Convert.ToDouble(bbox["max_x"]),
                Convert.ToDouble(bbox["max_y"]),
                Convert.ToDouble(bbox["max_z"]));
        
            BBoxMin = new Vector3D(
                Convert.ToDouble(bbox["min_x"]),
                Convert.ToDouble(bbox["min_y"]),
                Convert.ToDouble(bbox["min_z"]));
        }
Beispiel #9
0
 public double Dot(Vector3D vector)
 {
     return X * vector.X + Y * vector.Y + Z * vector.Z;
 }
Beispiel #10
0
 public void MoveTo(Vector3D loc)
 {
     location.SetVector(location);
     LookAtTargetPoint();
 }
Beispiel #11
0
 public double DistanceTo(Vector3D vector)
 {
     double x = vector.X - X;
     double y = vector.Y - Y;
     double z = vector.Z - Z;
     return Math.Sqrt(x * x + y * y + z * z);
 }
Beispiel #12
0
        public void Rotate(Vector3D axis, double angle)
        {
            Identity();
            double cos_angle = Math.Cos(angle);
            double sin_angle = Math.Sin(angle);

            XX = (1 - cos_angle) * axis.X * axis.X + cos_angle;
            XY = (1 - cos_angle) * axis.X * axis.Y + (sin_angle * axis.Y);
            XZ = (1 - cos_angle) * axis.X * axis.Z - (sin_angle * axis.Z);

            YX = (1 - cos_angle) * axis.X * axis.Y - (sin_angle * axis.Y);
            YY = (1 - cos_angle) * axis.Y * axis.Y + cos_angle;
            YZ = (1 - cos_angle) * axis.Y * axis.Z + (sin_angle * axis.X);

            ZX = (1 - cos_angle) * axis.X * axis.Z + (sin_angle * axis.Y);
            ZY = (1 - cos_angle) * axis.Y * axis.Z - (sin_angle * axis.X);
            ZZ = (1 - cos_angle) * axis.Z * axis.Z + cos_angle;
        }
Beispiel #13
0
		public Matrix3D Scale(Vector3D scale)
		{
			XX /= scale.X;
			YX /= scale.X;
			ZX /= scale.X;
			WX /= scale.X;
			XY /= scale.Y;
			YY/= scale.Y;
			ZY /= scale.Y;
			WY/= scale.Y;
			XZ /= scale.Z;
			YZ /= scale.Z;
			ZZ /= scale.Z;
			WZ /= scale.Z;
			return this;
		}
Beispiel #14
0
 public bool IsNotColinear(Vector3D vector)
 {
     //Vector3D cross = Cross(vector);
     if (vector.X < 0 && vector.Y < 0 && vector.Z < 0)
         return false;
     else
         return true;
 }
Beispiel #15
0
 public Vector3D Sub(Vector3D vector)
 {
     X = X - vector.X;
     Y = Y - vector.Y;
     Z = Z - vector.Z;
     return this;
 }
Beispiel #16
0
 public Vector3D Add(Vector3D vector)
 {
     X = X + vector.X;
     Y = Y + vector.Y;
     Z = Z + vector.Z;
     return this;
 }
Beispiel #17
0
 public void Move(Vector3D distance)
 {
     location.Add(distance);
     LookAtTargetPoint();
 }
Beispiel #18
0
 public Vector3D TransformTransposeConst(Matrix3D matrix, Vector3D vector_out)
 {
     vector_out.X = X * matrix.XX + Y * matrix.XY + Z * matrix.XZ + W * matrix.XW;
     vector_out.Y = Y * matrix.YX + Y * matrix.YY + Z * matrix.YZ + W * matrix.YW;
     vector_out.Z = Z * matrix.ZX + Y * matrix.ZY + Z * matrix.ZZ + W * matrix.ZW;
     vector_out.W = Z * matrix.ZW + Y * matrix.WY + Z * matrix.WZ + W * matrix.WW;
     return vector_out;
 }
Beispiel #19
0
 public void Move(Vector3D distance, bool moveTargetPoint)
 {
     location.Add(distance);
     target.Add(distance);
     LookAtTargetPoint();
 }
Beispiel #20
0
 public Vector3D Cross(Vector3D vector)
 {
     Vector3D crossProduct = new Vector3D();
     crossProduct.X = Y * vector.Z - Z * vector.Y;
     crossProduct.Y = Z * vector.X - X * vector.Z;
     crossProduct.Z = X * vector.Y - Y * vector.X;
     return crossProduct;
 }
Beispiel #21
0
 public void MoveTo(Vector3D loc, bool shiftTarget) {
     Vector3D previousLocation = location;
     location.SetVector(loc);
     target.Add(loc.Sub(previousLocation));
 }
Beispiel #22
0
        public Transform3D()
        {
            world_to_object = new Matrix3D();
            coord_system = COORD_Z_UP;
            ref_dir = Z_DIR;
            ref_up = Z_UP;
            ref_right = Z_RIGHT;

            location = new Vector3D();
            direction = ref_dir.clone();
            up = ref_up.clone();
            right = ref_right.clone();
            target = new Vector3D();
        }
Beispiel #23
0
        public void UpdateCamera()
        {
            if (RenderCamera == null || Viewport.Camera == null)
            {
                return;
            }

            Transform camTrans = RenderCamera.transform;
            Vector3 camPos = camTrans.position;
            Vector3 camForward = camTrans.forward;

            // Negate the x position and direction as Unity is left handed while RS is right handed.
            Vector3D pos = new Vector3D(-camPos.x, camPos.y, camPos.z);
            Vector3D forward = new Vector3D(-camForward.x, camForward.y, camForward.z);
            Vector3D up = new Vector3D(0, 1, 0);
            Transform3D trans = new Transform3D();
            trans.SetLookAt(pos, forward, up);

            Viewport.Camera.TransformMatrix = trans.world_to_object;
        }
Beispiel #24
0
 public void UpdateRefDirs()
 {
     if (coord_system == COORD_Y_UP)
     {
         ref_dir = Y_DIR;
         ref_right = Y_RIGHT;
         ref_up = Y_UP;
     }
     else
     {
         ref_dir = Z_DIR;
         ref_up = Z_UP;
         ref_right = Z_RIGHT;
     }
 }