Exemplo n.º 1
0
 public void SetWorldViewIT(Camera3D camera, Basic3DObject Object)
 {
     if (WorldViewIT != null)
     {
         WorldViewIT.SetValue(Matrix.Transpose(Matrix.Invert(Object.WorldMatrix * camera.ViewMatrix)));
     }
 }
        public override bool TriggerEvent(EventType Event, string[] args)
        {
            switch (Event)
            {
            case EventType.AddObject:
                GameObject o = ParentLevel.FindObject(args[0]);
                if (o != null && o.GetType().IsSubclassOf(typeof(Basic3DObject)))
                {
                    Basic3DObject b = (Basic3DObject)o;

                    if (ObjectCount == 0)
                    {
                        AddTag(GameObjectTag.Update);
                    }

                    if (arySize == ObjectCount)
                    {
                        if (arySize == 0)
                        {
                            PathObjects  = new GameObject[4];
                            PathSpeed    = new float[4];
                            PathPosition = new float[4];
                        }
                        else
                        {
                            arySize *= 2;
                            GameObject[] NewPathObjects  = new GameObject[arySize];
                            float[]      NewPathSpeed    = new float[arySize];
                            float[]      NewPathPosition = new float[arySize];

                            for (int i = 0; i < ObjectCount; i++)
                            {
                                NewPathObjects[i]  = PathObjects[i];
                                NewPathSpeed[i]    = PathSpeed[i];
                                NewPathPosition[i] = PathPosition[i];
                            }

                            PathObjects  = NewPathObjects;
                            PathPosition = NewPathPosition;
                            NewPathSpeed = PathSpeed;
                        }
                    }

                    PathObjects[ObjectCount]  = b;
                    PathPosition[ObjectCount] = Logic.ParseF(args[1]);
                    float f = Logic.ParseF(args[2]);
                    PathSpeed[ObjectCount] = f != 0 ? f : TravelSpeed.get();
                    ObjectCount++;
                }
                return(true);
            }

            return(base.TriggerEvent(Event, args));
        }
 public void MoveSelected(Vector3 Force)
 {
     foreach (GameObject g in SelectedGameObjects)
     {
         if (g.GetType().IsSubclassOf(typeof(Basic3DObject)))
         {
             Basic3DObject b = (Basic3DObject)g;
             b.ApplyMove(Force, false);
         }
     }
 }
 public void Center(Button button)
 {
     if (editorCamera != null)
     {
         bool    Success = false;
         Vector3 Result  = Vector3.Zero;
         Basic3DObject.GetAveragePosition(ParentScene.SelectedGameObjects, ref Result, ref Success);
         if (Success)
         {
             editorCamera.Position.set(Result);
         }
     }
 }
Exemplo n.º 5
0
        public void Draw3D(Camera3D camera)
        {
            Camera3DObject c = (Camera3DObject)ParentScene.MyCamera.get();

            if (c != null)
            {
                Vector3 Result  = Vector3.Zero;
                bool    Success = false;
                Basic3DObject.GetAveragePosition(ParentScene.SelectedGameObjects, ref Result, ref Success);

                WorldMatrix = c.ScaleMatrix * Matrix.CreateTranslation(Result);
                ColorEffectHolder.SetWorld(WorldMatrix);
                ColorEffectHolder.SetFromCamera(camera);

                foreach (EffectPass pass in ColorEffectHolder.MyEffect.CurrentTechnique.Passes)
                {
                    pass.Apply();


                    Game1.graphics.GraphicsDevice.DrawUserIndexedPrimitives <VertexPositionColor>(
                        PrimitiveType.LineList,
                        PointList,
                        0,             // vertex buffer offset to add to each element of the index buffer
                        PointCount,    // number of vertices in pointList
                        Indicies,      // the index buffer
                        0,             // first index element to read
                        PointCount / 2 // number of primitives to draw
                        );
                }


                ColorSetEffectHolder.Collection["Color"].SetValue(Color.LightGray.ToVector4());
                ColorSetEffectHolder.SetFromCamera(camera);
                ColorSetEffectHolder.SetWorld(WorldMatrix);
                Render.DrawModel(CubeModel, ColorSetEffectHolder.MyEffect);
                Vector3 ScreenPos = WorldViewer.self.MyViewport.Project(Vector3.Zero, camera.ProjectionMatrix, camera.ViewMatrix, WorldMatrix);
                ScreenPositions[3] = new Vector2(ScreenPos.X, ScreenPos.Y);


                Model EndModel = controlMode == ControlMode.Move ? ArrowModel :
                                 controlMode == ControlMode.Rotate ? BallModel : CubeModel;
                for (int i = 0; i < 3; i++)
                {
                    ColorSetEffectHolder.Collection["Color"].SetValue(PointColors[i].ToVector4());
                    ColorSetEffectHolder.SetWorld(ModelMatricies[i] * WorldMatrix);
                    Render.DrawModel(EndModel, ColorSetEffectHolder.MyEffect);
                    ScreenPos          = WorldViewer.self.MyViewport.Project(Vector3.Zero, camera.ProjectionMatrix, camera.ViewMatrix, ModelMatricies[i] * WorldMatrix);
                    ScreenPositions[i] = new Vector2(ScreenPos.X, ScreenPos.Y);
                }
            }
        }
 public void SetFromObject(Basic3DObject g)
 {
     if (World != null)
     {
         World.SetValue(g.WorldMatrix);
     }
     if (Rotation != null)
     {
         Rotation.SetValue(g.RotationMatrix);
     }
     if (Time != null)
     {
         Time.SetValue(Level.Time);
     }
 }
        public void RotateSelected(Vector3 Force, Vector3 Origin)
        {
            Vector3 Result  = Vector3.Zero;
            bool    Success = false;

            Basic3DObject.GetAveragePosition(SelectedGameObjects, ref Result, ref Success);

            foreach (GameObject g in SelectedGameObjects)
            {
                if (g.GetType().IsSubclassOf(typeof(Basic3DObject)))
                {
                    Basic3DObject b = (Basic3DObject)g;
                    b.ApplyRotate(Force, Result, false);
                }
            }
        }
        public void ApplyRotate(Vector3 Force, Vector3 Origin, bool ApplyToChildren)
        {
            Rotation.add(Force);

            if (ApplyToChildren)
            {
                foreach (GameObject g in HierarchyChildren)
#if EDITOR && WINDOWS
                    if (!ParentLevel.LevelForEditing || !g.EditorSelected)
#endif
                    if (g.GetType().IsSubclassOf(typeof(Basic3DObject)))
                    {
                        Basic3DObject b = (Basic3DObject)g;
                        b.ApplyRotate(Force, Origin, true);
                    }
}
            }
        public void ApplyScale(Vector3 Force, Vector3 Origin, bool ApplyToChildren)
        {
            Scale.mult(Force);
            Position.set(Origin + (Position.get() - Origin) * Force);

            if (ApplyToChildren)
            {
                foreach (GameObject g in HierarchyChildren)
#if EDITOR && WINDOWS
                { if (!ParentLevel.LevelForEditing || !g.EditorSelected)
#endif
                    if (g.GetType().IsSubclassOf(typeof(Basic3DObject)))
                    {
                        Basic3DObject b = (Basic3DObject)g;
                        b.ApplyScale(Force, Origin, true);
                    }
}
            }
        }
        public static void GetAveragePosition(LinkedList <GameObject> SelectObjects, ref Vector3 Result, ref bool Success)
        {
            Vector3 val   = Vector3.Zero;
            int     Count = 0;

            Success = false;

            foreach (GameObject g in SelectObjects)
            {
                if (g.GetType().IsSubclassOf(typeof(Basic3DObject)))
                {
                    Success = true;
                    Basic3DObject b = (Basic3DObject)g;
                    val += b.GetPosition();
                    Count++;
                }
            }

            Result = val / Count;
        }
 public bool TestCollision(Basic3DObject other)
 {
     return(CollisionShape.Intersects(other.CollisionShape));
 }
Exemplo n.º 12
0
        public override void Update(GameTime gameTime, Window Updater)
        {
            if (CurrentMode != LockMode.None)
            {
                if (MouseManager.mouseState.LeftButton == ButtonState.Pressed)
                {
                    bool    Success = false;
                    Vector3 Result  = Vector3.Zero;
                    Basic3DObject.GetAveragePosition(ParentScene.SelectedGameObjects, ref Result, ref Success);

                    Vector3 Direction = -Vector3.One;
                    if (CurrentMode == LockMode.MoveX)
                    {
                        Direction = new Vector3(1, 0, 0);
                    }
                    if (CurrentMode == LockMode.MoveY)
                    {
                        Direction = new Vector3(0, 1, 0);
                    }
                    if (CurrentMode == LockMode.MoveZ)
                    {
                        Direction = new Vector3(0, 0, 1);
                    }

                    Vector2 MouseMult = Vector2.One;

                    if (CurrentMode != LockMode.MoveAll)
                    {
                        Vector2 CenterScreenPos = ScreenPositions[3];
                        Vector2 ScreenPos2D     = ScreenPositions[CurrentMode == LockMode.MoveX ? 0 : CurrentMode == LockMode.MoveY ? 1 : 2];
                        MouseMult = Vector2.Normalize(ScreenPos2D - CenterScreenPos);
                    }

                    Vector2        MouseForce = new Vector2(MouseManager.MousePosition.X - MouseLockPosition.X, MouseManager.MousePosition.Y - MouseLockPosition.Y) * MouseMult / 1000;
                    Camera3DObject c          = (Camera3DObject)ParentScene.MyCamera.get();
                    float          Value      = (MouseForce.X + MouseForce.Y) * c.ZoomDistance.get();

                    switch (controlMode)
                    {
                    case ControlMode.Move:
                        ParentScene.MoveSelected(Value * Direction);
                        break;

                    case ControlMode.Rotate:
                        ParentScene.RotateSelected(Value * Direction, Result);
                        break;

                    case ControlMode.Scale:
                        ParentScene.ScaleSelected(Vector3.One + Value / 300 * Direction, Result);
                        break;
                    }
                }
                else
                {
                    Game1.self.IsMouseVisible = true;
                    CurrentMode = LockMode.None;
                }
                Mouse.SetPosition((int)MouseLockPosition.X, (int)MouseLockPosition.Y);
            }

            base.Update(gameTime, Updater);
        }
Exemplo n.º 13
0
 public static void DrawModel(ModelValue model, EffectValue effect, Camera3D camera, Basic3DObject obj)
 {
     DrawModel(model.get(), effect, camera, obj);
 }
Exemplo n.º 14
0
 public static void DrawModel(Model model, EffectValue effect, Camera3D camera, Basic3DObject obj)
 {
     if (model != null && effect.get() != null)
     {
         _3DEffect effect3D = (_3DEffect)effect.Holder;
         effect3D.SetFromObject(obj);
         effect3D.SetFromCamera(camera);
         DrawModel(model, effect3D.MyEffect);
     }
 }