public void SetTranslation(Vector3f pos)
 {
     if (body != null)
     {
         tmpJVec.Set(pos.x, pos.y, pos.z);
         body.Position = tmpJVec;
         // origin.SubtractStore(boundingBox.Center);
         origin.Set(GameObject.GetUpdatedWorldTranslation());
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Uses the supportMapping to calculate the bounding box. Should be overidden
        /// to make this faster.
        /// </summary>
        /// <param name="orientation">The orientation of the shape.</param>
        /// <param name="box">The resulting axis aligned bounding box.</param>
        public virtual void GetBoundingBox(ref JMatrix orientation, out JBBox box)
        {
            // I don't think that this can be done faster.
            // 6 is the minimum number of SupportMap calls.

            JVector vec = JVector.Zero;

            vec.Set(orientation.M11, orientation.M21, orientation.M31);
            SupportMapping(ref vec, out vec);
            box.Max.X = orientation.M11 * vec.X + orientation.M21 * vec.Y + orientation.M31 * vec.Z;

            vec.Set(orientation.M12, orientation.M22, orientation.M32);
            SupportMapping(ref vec, out vec);
            box.Max.Y = orientation.M12 * vec.X + orientation.M22 * vec.Y + orientation.M32 * vec.Z;

            vec.Set(orientation.M13, orientation.M23, orientation.M33);
            SupportMapping(ref vec, out vec);
            box.Max.Z = orientation.M13 * vec.X + orientation.M23 * vec.Y + orientation.M33 * vec.Z;

            vec.Set(-orientation.M11, -orientation.M21, -orientation.M31);
            SupportMapping(ref vec, out vec);
            box.Min.X = orientation.M11 * vec.X + orientation.M21 * vec.Y + orientation.M31 * vec.Z;

            vec.Set(-orientation.M12, -orientation.M22, -orientation.M32);
            SupportMapping(ref vec, out vec);
            box.Min.Y = orientation.M12 * vec.X + orientation.M22 * vec.Y + orientation.M32 * vec.Z;

            vec.Set(-orientation.M13, -orientation.M23, -orientation.M33);
            SupportMapping(ref vec, out vec);
            box.Min.Z = orientation.M13 * vec.X + orientation.M23 * vec.Y + orientation.M33 * vec.Z;
        }
Esempio n. 3
0
        /// <summary>
        /// Uses the supportMapping to calculate the bounding box. Should be overidden
        /// to make this faster.
        /// </summary>
        /// <param name="orientation">The orientation of the shape.</param>
        /// <param name="box">The resulting axis aligned bounding box.</param>
        public virtual void GetBoundingBox(ref float rotation, out JBBox box)
        {
            JVector vec = JVector.Zero;

            JMatrix orientation = JMatrix.CreateRotationZ(rotation);

            vec.Set(orientation.M11, orientation.M21);
            SupportMapping(ref vec, out vec);
            box.Max.X = orientation.M11 * vec.X + orientation.M21 * vec.Y;

            vec.Set(orientation.M12, orientation.M22);
            SupportMapping(ref vec, out vec);
            box.Max.Y = orientation.M12 * vec.X + orientation.M22 * vec.Y;

            vec.Set(-orientation.M11, -orientation.M21);
            SupportMapping(ref vec, out vec);
            box.Min.X = orientation.M11 * vec.X + orientation.M21 * vec.Y;

            vec.Set(-orientation.M12, -orientation.M22);
            SupportMapping(ref vec, out vec);
            box.Min.Y = orientation.M12 * vec.X + orientation.M22 * vec.Y;
        }
        public override void Update()
        {
            base.Update();

            Vector3f dir = camera.Direction;

            linv = this.Body.LinearVelocity;

            this.Body.AngularVelocity.Set(0, 0, 0);


            if (inputManager.IsKeyDown(InputManager.KeyboardKey.W))
            {
                impulse.X += dir.x * speed;
                impulse.Z += dir.z * speed;
            }
            if (inputManager.IsKeyDown(InputManager.KeyboardKey.S))
            {
                impulse.X += -dir.x * speed;
                impulse.Z += -dir.z * speed;
            }
            if (inputManager.IsKeyDown(InputManager.KeyboardKey.D))
            {
                impulse.X += -speed * (float)System.Math.Sin(MathUtil.ToRadians(camera.GetYaw() + 90));
                impulse.Z += speed * (float)System.Math.Cos(MathUtil.ToRadians(camera.GetYaw() + 90));
            }
            if (inputManager.IsKeyDown(InputManager.KeyboardKey.A))
            {
                impulse.X += -speed * (float)System.Math.Sin(MathUtil.ToRadians(camera.GetYaw() - 90));
                impulse.Z += speed * (float)System.Math.Cos(MathUtil.ToRadians(camera.GetYaw() - 90));
            }
            impulse.Y = linv.Y;
            if (inputManager.IsKeyDown(InputManager.KeyboardKey.W) ||
                inputManager.IsKeyDown(InputManager.KeyboardKey.S) ||
                inputManager.IsKeyDown(InputManager.KeyboardKey.D) ||
                inputManager.IsKeyDown(InputManager.KeyboardKey.A))
            {
                moving = true;
                Body.LinearVelocity = impulse;
                if (linv.X == 0.0f && linv.Y == 0.0f && linv.Z == 0.0f)
                {
                    this.Body.Position.Set(Body.Position.X + impulse.X * 0.01f, Body.Position.Y + impulse.Y * 0.01f, Body.Position.Z + impulse.Z * 0.01f);
                }
                impulse.Set(0, 0, 0);
            }
            else
            {
                moving = false;
            }
            camera.Translation.Set(Body.Position.X, Body.Position.Y + 3.5f, Body.Position.Z);
        }