public override List<RenderInfo> Render(SETItem item, Device dev, EditorCamera camera, MatrixStack transform)
 {
     List<RenderInfo> result = new List<RenderInfo>();
     transform.Push();
     transform.NJTranslate(item.Position);
     transform.NJRotateY(item.Rotation.Y);
     result.AddRange(ballmodel.DrawModelTree(dev, transform, ObjectHelper.GetTextures("OBJ_REGULAR"), ballmeshes));
     if (item.Selected)
         result.AddRange(ballmodel.DrawModelTreeInvert(dev, transform, ballmeshes));
     transform.Pop();
     double v24 = item.Scale.X * 0.05000000074505806;
     transform.Push();
     double v22 = item.Scale.X * 0.5 + item.Position.Y;
     transform.NJTranslate(item.Position.X, (float)v22, item.Position.Z);
     transform.NJScale(1.0f, (float)v24, 1.0f);
     result.AddRange(cylindermodel.DrawModelTree(dev, transform, null, cylindermeshes));
     if (item.Selected)
         result.AddRange(cylindermodel.DrawModelTreeInvert(dev, transform, cylindermeshes));
     transform.Pop();
     transform.Push();
     transform.NJTranslate(item.Position.X, item.Position.Y + item.Scale.Z, item.Position.Z);
     result.AddRange(spheremodel.DrawModelTree(dev, transform, null, spheremeshes));
     if (item.Selected)
         result.AddRange(spheremodel.DrawModelTreeInvert(dev, transform, spheremeshes));
     transform.Pop();
     return result;
 }
Exemple #2
0
        public static void Draw(IEnumerable<RenderInfo> items, Device device, EditorCamera camera)
        {
            List<KeyValuePair<float, RenderInfo>> drawList = new List<KeyValuePair<float, RenderInfo>>();
            foreach (RenderInfo item in items)
            {
                float dist = Extensions.Distance(camera.Position, item.Bounds.Center.ToVector3()) + item.Bounds.Radius;
                if (dist > camera.DrawDistance) continue;

                if (item.Material != null && item.Material.UseAlpha)
                {
                    bool ins = false;
                    for (int i = 0; i < drawList.Count; i++)
                    {
                        if (drawList[i].Key < dist)
                        {
                            drawList.Insert(i, new KeyValuePair<float, RenderInfo>(dist, item));
                            ins = true;
                            break;
                        }
                    }
                    if (!ins)
                        drawList.Add(new KeyValuePair<float, RenderInfo>(dist, item));
                }
                else
                    drawList.Insert(0, new KeyValuePair<float, RenderInfo>(float.MaxValue, item));
            }
            foreach (KeyValuePair<float, RenderInfo> item in drawList)
                item.Value.Draw(device);
        }
Exemple #3
0
        public override List<RenderInfo> Render(SETItem item, Device dev, EditorCamera camera, MatrixStack transform)
        {
            List<RenderInfo> result = new List<RenderInfo>();
            transform.Push();
            transform.NJTranslate(item.Position);
            transform.NJRotateY(item.Rotation.Y - 0x5772);
            transform.NJScale((item.Scale.X), (item.Scale.Y), (item.Scale.Z));

            float largestScale = item.Scale.X;
            if (item.Scale.Y > largestScale) largestScale = item.Scale.Y;
            if (item.Scale.Z > largestScale) largestScale = item.Scale.Z;

            BoundingSphere boxSphere = new BoundingSphere() { Center = new Vertex(item.Position.X, item.Position.Y, item.Position.Z), Radius = (1.5f * largestScale) };

            RenderInfo outputInfo = new RenderInfo(mesh, 0, transform.Top, material, texture, FillMode.Solid, boxSphere);
            result.Add(outputInfo);

            if (item.Selected)
            {
                RenderInfo highlightInfo = new RenderInfo(mesh, 0, transform.Top, material, texture, FillMode.WireFrame, boxSphere);
                result.Add(highlightInfo);
            }

            transform.Pop();
            return result;
        }
Exemple #4
0
 public override List<RenderInfo> Render(SETItem item, Device dev, EditorCamera camera, MatrixStack transform)
 {
     List<RenderInfo> result = new List<RenderInfo>();
     int rows = (int)Math.Max(item.Scale.X, 1);
     int cols = (int)Math.Max(item.Scale.Z, 1);
     transform.Push();
     transform.NJTranslate(item.Position);
     transform.NJRotateObject(item.Rotation.X & 0xC000, item.Rotation.Y, 0);
     transform.NJTranslate((1 - rows) * 7.5f, 0, (1 - cols) * 7.5f);
     for (int i = 0; i < rows; ++i)
     {
         transform.Push();
         for (int j = 0; j < cols; ++j)
         {
             result.AddRange(model.DrawModelTree(dev, transform, ObjectHelper.GetTextures("OBJ_REGULAR"), meshes));
             if (item.Selected)
                 result.AddRange(model.DrawModelTreeInvert(dev, transform, meshes));
             transform.NJTranslate(0, 0, 15);
         }
         transform.Pop();
         transform.NJTranslate(15, 0, 0);
     }
     transform.Pop();
     return result;
 }
Exemple #5
0
 public override void Render(Device dev, EditorCamera cam)
 {
     List<RenderInfo> result = new List<RenderInfo>();
     MatrixStack transform = new MatrixStack();
     Texture[] texs = ObjectHelper.GetTextures("SHOOTING0");
     result.AddRange(carriermdl.DrawModelTree(dev, transform, texs, carriermesh));
     RenderInfo.Draw(result, dev, cam);
 }
Exemple #6
0
 public override void Render(Device dev, EditorCamera cam)
 {
     if (NoRender) return;
     MatrixStack transform = new MatrixStack();
     transform.Push();
     transform.NJTranslate(cam.Position);
     transform.NJScale(Skybox_Scale);
     RenderInfo.Draw(model.DrawModelTree(dev, transform, ObjectHelper.GetTextures("BG_SHAREOBJ"), meshes), dev, cam);
     transform.Pop();
 }
 public EditorOptionsEditor(EditorCamera camera)
 {
     InitializeComponent();
     this.camera = camera;
     drawDistSlider.Value = (int)EditorOptions.RenderDrawDistance;
     fillModeDropDown.SelectedIndex = (int)EditorOptions.RenderFillMode - 1;
     cullModeDropdown.SelectedIndex = (int)EditorOptions.RenderCullMode - 1;
     drawDistLabel.Text = String.Format("Draw Distance: {0}", drawDistSlider.Value);
     toolTip.SetToolTip(fullBrightCheck, "If the scene's lighting is making it hard to work, use this to temporarily set the lighting to flat-white.");
     fullBrightCheck.Checked = EditorOptions.OverrideLighting;
 }
 public override void Render(Device dev, EditorCamera cam)
 {
     List<RenderInfo> result = new List<RenderInfo>();
     MatrixStack transform = new MatrixStack();
     transform.Push();
     Texture[] texs = ObjectHelper.GetTextures("WINDY_BACK2");
     for (int i = 0; i < 3; i++)
         result.AddRange(models[i].DrawModelTree(dev, transform, texs, meshes[i]));
     transform.Pop();
     RenderInfo.Draw(result, dev, cam);
 }
Exemple #9
0
 public override List<RenderInfo> Render(SETItem item, Device dev, EditorCamera camera, MatrixStack transform)
 {
     List<RenderInfo> result = new List<RenderInfo>();
     transform.Push();
     transform.NJTranslate(item.Position);
     transform.NJRotateObject(item.Rotation.X, item.Rotation.Y - 0x8000, item.Rotation.Z);
     result.AddRange(model.DrawModelTree(dev, transform, ObjectHelper.GetTextures("OBJ_REGULAR"), meshes));
     if (item.Selected)
         result.AddRange(model.DrawModelTreeInvert(dev, transform, meshes));
     transform.Pop();
     return result;
 }
Exemple #10
0
 public override List<RenderInfo> Render(SETItem item, Device dev, EditorCamera camera, MatrixStack transform)
 {
     List<RenderInfo> result = new List<RenderInfo>();
     transform.Push();
     transform.NJTranslate(item.Position);
     transform.NJRotateY(item.Rotation.Y);
     transform.NJScale((item.Scale.X + 10) / 5f, (item.Scale.Y + 10) / 5f, (item.Scale.Z + 10) / 5f);
     result.AddRange(model.DrawModelTree(dev, transform, null, meshes));
     if (item.Selected)
         result.AddRange(model.DrawModelTreeInvert(dev, transform, meshes));
     transform.Pop();
     return result;
 }
Exemple #11
0
 public override void Render(Device dev, EditorCamera cam)
 {
     List<RenderInfo> result = new List<RenderInfo>();
     MatrixStack transform = new MatrixStack();
     transform.Push();
     transform.NJTranslate(cam.Position.X, 0, cam.Position.Z);
     transform.NJScale(Skybox_Scale);
     Texture[] texs = ObjectHelper.GetTextures("BG_BEACH");
     result.AddRange(model1.DrawModelTree(dev, transform, texs, mesh1));
     result.AddRange(model2.DrawModelTree(dev, transform, texs, mesh2));
     transform.Pop();
     RenderInfo.Draw(result, dev, cam);
 }
 public override List<RenderInfo> Render(SETItem item, Device dev, EditorCamera camera, MatrixStack transform)
 {
     List<RenderInfo> result = new List<RenderInfo>();
     transform.Push();
     transform.NJTranslate(xpos ?? item.Position.X, ypos ?? item.Position.Y, zpos ?? item.Position.Z);
     transform.NJRotateXYZ(xrot ?? item.Rotation.X, yrot ?? item.Rotation.Y, zrot ?? item.Rotation.Z);
     if (model == null)
         result.AddRange(ObjectHelper.RenderSprite(dev, transform, null, item.Position.ToVector3(), item.Selected));
     else
     {
         transform.NJScale(xscl ?? item.Scale.X, yscl ?? item.Scale.Y, zscl ?? item.Scale.Z);
         result.AddRange(model.DrawModelTree(dev, transform, ObjectHelper.GetTextures(texture), meshes));
         if (item.Selected)
             result.AddRange(model.DrawModelTreeInvert(dev, transform, meshes));
     }
     transform.Pop();
     return result;
 }
Exemple #13
0
        public static void Draw(IEnumerable <RenderInfo> items, Device device, EditorCamera camera)
        {
            List <KeyValuePair <float, RenderInfo> > drawList = new List <KeyValuePair <float, RenderInfo> >();

            foreach (RenderInfo item in items)
            {
                float dist = Extensions.Distance(camera.Position, item.Bounds.Center.ToVector3()) + item.Bounds.Radius;
                if (dist > camera.DrawDistance)
                {
                    continue;
                }

                if (item.Material != null && item.Material.UseAlpha)
                {
                    bool ins = false;
                    for (int i = 0; i < drawList.Count; i++)
                    {
                        if (drawList[i].Key < dist)
                        {
                            drawList.Insert(i, new KeyValuePair <float, RenderInfo>(dist, item));
                            ins = true;
                            break;
                        }
                    }
                    if (!ins)
                    {
                        drawList.Add(new KeyValuePair <float, RenderInfo>(dist, item));
                    }
                }
                else
                {
                    drawList.Insert(0, new KeyValuePair <float, RenderInfo>(float.MaxValue, item));
                }
            }
            foreach (KeyValuePair <float, RenderInfo> item in drawList)
            {
                item.Value.Draw(device);
            }
        }
Exemple #14
0
 public override List<RenderInfo> Render(SETItem item, Device dev, EditorCamera camera, MatrixStack transform)
 {
     List<RenderInfo> result = new List<RenderInfo>();
     transform.Push();
     transform.NJTranslate(item.Position.ToVector3());
     transform.NJRotateY(item.Rotation.Y);
     transform.Push();
     transform.NJTranslate(0, 0, 10);
     transform.NJScale(0.1000000014901161f, 0.1000000014901161f, 2);
     result.AddRange(model.DrawModelTree(dev, transform, null, meshes));
     if (item.Selected)
         result.AddRange(model.DrawModelTreeInvert(dev, transform, meshes));
     transform.Pop();
     transform.Push();
     transform.NJTranslate(0, 0, 20);
     transform.NJRotateX(0x2000);
     transform.NJTranslate(0, 0, -3);
     transform.NJScale(0.1000000014901161f, 0.1000000014901161f, 0.699999988079071f);
     result.AddRange(model.DrawModelTree(dev, transform, null, meshes));
     if (item.Selected)
         result.AddRange(model.DrawModelTreeInvert(dev, transform, meshes));
     transform.Pop();
     transform.Push();
     transform.NJTranslate(0, 0, 20);
     transform.NJRotateX(0xE000);
     transform.NJTranslate(0, 0, -3);
     transform.NJScale(0.1000000014901161f, 0.1000000014901161f, 0.699999988079071f);
     result.AddRange(model.DrawModelTree(dev, transform, null, meshes));
     if (item.Selected)
         result.AddRange(model.DrawModelTreeInvert(dev, transform, meshes));
     transform.Pop();
     transform.NJScale((item.Scale.X + 10) / 5f, (item.Scale.Y + 10) / 5f, 0.1000000014901161f);
     result.AddRange(model.DrawModelTree(dev, transform, null, meshes));
     if (item.Selected)
         result.AddRange(model.DrawModelTreeInvert(dev, transform, meshes));
     transform.Pop();
     return result;
 }
Exemple #15
0
        public void DrawBox(Device d3ddevice, EditorCamera cam)
        {
            if (!enabled || !drawCube)
                return;

            BoundingSphere gizmoSphere = new BoundingSphere() { Center = new Vertex(affectedPoint.X, affectedPoint.Y, affectedPoint.Z), Radius = handleSize };

            MatrixStack transform = new MatrixStack();

            transform.Push();
            transform.TranslateLocal(affectedPoint.X, affectedPoint.Y, affectedPoint.Z);
            transform.ScaleLocal(handleSize, handleSize, handleSize);
            RenderInfo boxRenderInfo = new RenderInfo(Gizmo.BoxMesh, 0, transform.Top, Gizmo.StandardMaterial, BoxTexture, FillMode.Solid, gizmoSphere);

            RenderInfo.Draw(new List<RenderInfo>() { boxRenderInfo }, d3ddevice, cam);
            transform.Pop();
        }
Exemple #16
0
        public override List<RenderInfo> Render(Device dev, EditorCamera camera, MatrixStack transform)
        {
            float dist = Direct3D.Extensions.Distance(camera.Position, Position.ToVector3());
            if (dist > camera.DrawDistance) return EmptyRenderInfo;

            List<RenderInfo> result = new List<RenderInfo>();
            transform.Push();
            transform.NJTranslate(0, offset, 0);
            transform.NJTranslate(Position);
            transform.NJRotateY(YRotation);
            result.AddRange(Model.DrawModelTree(dev, transform, LevelData.Textures[texture], Meshes));
            if (Selected)
                result.AddRange(Model.DrawModelTreeInvert(dev, transform, Meshes));
            transform.Pop();
            return result;
        }
Exemple #17
0
        public override List<RenderInfo> Render(Device dev, EditorCamera camera, MatrixStack transform)
        {
            if (!camera.SphereInFrustum(Bounds))
                return EmptyRenderInfo;

            return LevelData.ObjDefs[ID].Render(this, dev, camera, transform);
        }
Exemple #18
0
        public override List<RenderInfo> Render(Device dev, EditorCamera camera, MatrixStack transform)
        {
            if (!camera.SphereInFrustum(Bounds))
                return EmptyRenderInfo;

            List<RenderInfo> result = new List<RenderInfo>();

            RenderInfo outputInfo = new RenderInfo(mesh, 0, Matrix.Identity, (Selected) ? SelectedMaterial : UnSelectedMaterial, null, EditorOptions.RenderFillMode, Bounds);
            result.Add(outputInfo);

            textSprite.Begin(SpriteFlags.AlphaBlend);

            Matrix view = camera.ToMatrix();
            Matrix projection = Matrix.PerspectiveFovRH(camera.FOV, camera.Aspect, 1, camera.DrawDistance);

            if (Selected)
            {
                for (int vIndx = 0; vIndx < splineData.Path.Count(); vIndx++)
                {
                    #region Draw Vertex IDs
                    Vector3 screenCoordinates = Vector3.Project(new Vector3(splineData.Path[vIndx].Position.X, splineData.Path[vIndx].Position.Y, splineData.Path[vIndx].Position.Z),
                        dev.Viewport, projection, view, Matrix.Identity);
                    Vector3 altScrCoord = Vector3.Project(new Vector3(splineData.Path[vIndx].Position.X, splineData.Path[vIndx].Position.Y, splineData.Path[vIndx].Position.Z),
                        dev.Viewport, dev.Transform.Projection, dev.Transform.View, Matrix.Identity);

                    EditorOptions.OnscreenFont.DrawText(textSprite, vIndx.ToString(), new Point((int)(screenCoordinates.X), (int)(screenCoordinates.Y)), Color.White);
                    #endregion

                    #region Draw Vertex Handles
                    transform.Push();

                    transform.Translate(splineData.Path[vIndx].Position.X, splineData.Path[vIndx].Position.Y, splineData.Path[vIndx].Position.Z);

                    result.Add(new RenderInfo(vertexHandleMesh, 0, transform.Top, UnSelectedMaterial, null, FillMode.Solid, new BoundingSphere(splineData.Path[vIndx].Position.X,
                        splineData.Path[vIndx].Position.Y, splineData.Path[vIndx].Position.Z, 1f)));

                    if (vIndx == selectedKnot) result.Add(new RenderInfo(vertexHandleMesh, 0, transform.Top, SelectedMaterial, null, FillMode.WireFrame, new BoundingSphere(splineData.Path[vIndx].Position.X,
               splineData.Path[vIndx].Position.Y, splineData.Path[vIndx].Position.Z, 1f)));
                    transform.Pop();
                    #endregion
                }
            }

            textSprite.End();

            return result;
        }
Exemple #19
0
        public static List<Item> ImportFromFile(string filePath, Device d3ddevice, EditorCamera camera, out bool errorFlag, out string errorMsg, EditorItemSelection selectionManager)
        {
            List<Item> createdItems = new List<Item>();

            if (!File.Exists(filePath))
            {
                errorFlag = true;
                errorMsg = "File does not exist!";
                return null;
            }

            DirectoryInfo filePathInfo = new DirectoryInfo(filePath);

            bool importError = false;
            string importErrorMsg = "";

            switch (filePathInfo.Extension)
            {
                case ".obj":
                case ".objf":
                    Vector3 pos = camera.Position + (-20 * camera.Look);
                    LevelItem item = new LevelItem(d3ddevice, filePath, new Vertex(pos.X, pos.Y, pos.Z), new Rotation(), LevelItems.Count, selectionManager)
                    {
                        Visible = true
                    };

                    createdItems.Add(item);
                    break;

                case ".txt":
                    NodeTable.ImportFromFile(d3ddevice, filePath, out importError, out importErrorMsg, selectionManager);
                    break;

                default:
                    errorFlag = true;
                    errorMsg = "Invalid file format!";
                    return null;
            }

            StateChanged();

            errorFlag = importError;
            errorMsg = importErrorMsg;

            return createdItems;
        }
Exemple #20
0
 public abstract List<RenderInfo> Render(Device dev, EditorCamera camera, MatrixStack transform);
Exemple #21
0
        public override List<RenderInfo> Render(Device dev, EditorCamera camera, MatrixStack transform)
        {
            if (!camera.SphereInFrustum(Bounds))
                return EmptyRenderInfo;

            List<RenderInfo> result = new List<RenderInfo>();
            transform.Push();
            transform.NJTranslate(Position);
            transform.NJRotateY(Rotation.Y);
            transform.NJScale((Scale.X), (Scale.Y), (Scale.Z));

            RenderInfo outputInfo = new RenderInfo(VolumeMesh, 0, transform.Top, Material, null, FillMode.Solid, Bounds);

            if (Selected)
            {
                NJS_MATERIAL mat = new NJS_MATERIAL
                {
                    DiffuseColor = Color.White,
                    IgnoreLighting = true,
                    UseAlpha = false
                };
                result.Add(new RenderInfo(VolumeMesh, 0, transform.Top, mat, null, FillMode.WireFrame, Bounds));
            }

            result.Add(outputInfo);

            transform.Pop();
            return result;
        }
        // TODO: Consider returning IEnumerable<RenderInfo>
        private RenderInfo[] Render(Device dev, MatrixStack transform, EditorCamera cam)
        {
            List<RenderInfo> result = new List<RenderInfo>();

            if (!enabled)
                return result.ToArray();

            float dist = cam.Position.Distance(position) * 0.0825f;
            BoundingSphere gizmoSphere = new BoundingSphere() { Center = new Vertex(position.X, position.Y, position.Z), Radius = (1.0f * Math.Abs(dist)) };

            #region Setting Render States
            dev.SetSamplerState(0, SamplerStageStates.MinFilter, (int)TextureFilter.Point); // no fancy filtering is required because no textures are even being used
            dev.SetSamplerState(0, SamplerStageStates.MagFilter, (int)TextureFilter.Point);
            dev.SetSamplerState(0, SamplerStageStates.MipFilter, (int)TextureFilter.Point);
            dev.SetRenderState(RenderStates.Lighting, true);
            dev.SetRenderState(RenderStates.SpecularEnable, false);
            dev.SetRenderState(RenderStates.Ambient, Color.White.ToArgb());
            dev.SetRenderState(RenderStates.AlphaBlendEnable, false);
            dev.SetRenderState(RenderStates.ColorVertex, false);
            dev.Clear(ClearFlags.ZBuffer, 0, 1, 0);
            #endregion

            transform.Push();
            transform.TranslateLocal(position.X, position.Y, position.Z);
            transform.RotateXYZLocal(rotation.X, rotation.Y, rotation.Z);
            transform.ScaleLocal(Math.Abs(dist), Math.Abs(dist), Math.Abs(dist));

            #region Handling Transform Modes
            switch (mode)
            {
                case TransformMode.TRANFORM_MOVE:
                    {
                        RenderInfo xRenderInfo = new RenderInfo(Gizmo.XMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.X_AXIS) ? Gizmo.HighlightMaterial : Gizmo.XMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(xRenderInfo);
                        RenderInfo yRenderInfo = new RenderInfo(Gizmo.YMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Y_AXIS) ? Gizmo.HighlightMaterial : Gizmo.YMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(yRenderInfo);
                        RenderInfo zRenderInfo = new RenderInfo(Gizmo.ZMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Z_AXIS) ? Gizmo.HighlightMaterial : Gizmo.ZMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(zRenderInfo);

                        if (!isTransformLocal) // this is such a cop-out. I'll try to find a better solution.
                        {
                            RenderInfo xyRenderInfo = new RenderInfo(Gizmo.XYMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.XY_AXIS) ? Gizmo.HighlightMaterial : Gizmo.DoubleAxisMaterial, null, FillMode.Solid, gizmoSphere);
                            result.Add(xyRenderInfo);
                            RenderInfo zxRenderInfo = new RenderInfo(Gizmo.ZXMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.XZ_AXIS) ? Gizmo.HighlightMaterial : Gizmo.DoubleAxisMaterial, null, FillMode.Solid, gizmoSphere);
                            result.Add(zxRenderInfo);
                            RenderInfo zyRenderInfo = new RenderInfo(Gizmo.ZYMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.ZY_AXIS) ? Gizmo.HighlightMaterial : Gizmo.DoubleAxisMaterial, null, FillMode.Solid, gizmoSphere);
                            result.Add(zyRenderInfo);
                        }
                    }
                    break;
                case TransformMode.TRANSFORM_ROTATE:
                    {
                        RenderInfo xRenderInfo = new RenderInfo(Gizmo.XRotateMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.X_AXIS) ? Gizmo.HighlightMaterial : Gizmo.XMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(xRenderInfo);
                        RenderInfo yRenderInfo = new RenderInfo(Gizmo.YRotateMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Y_AXIS) ? Gizmo.HighlightMaterial : Gizmo.YMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(yRenderInfo);
                        RenderInfo zRenderInfo = new RenderInfo(Gizmo.ZRotateMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Z_AXIS) ? Gizmo.HighlightMaterial : Gizmo.ZMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(zRenderInfo);
                    }
                    break;
                case TransformMode.NONE:
                    {
                        RenderInfo xRenderInfo = new RenderInfo(Gizmo.XNullMesh, 0, transform.Top, Gizmo.XMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(xRenderInfo);
                        RenderInfo yRenderInfo = new RenderInfo(Gizmo.YNullMesh, 0, transform.Top, Gizmo.YMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(yRenderInfo);
                        RenderInfo zRenderInfo = new RenderInfo(Gizmo.ZNullMesh, 0, transform.Top, Gizmo.ZMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(zRenderInfo);
                    }
                    break;
                case TransformMode.TRANSFORM_SCALE:
                    {
                        RenderInfo xRenderInfo = new RenderInfo(Gizmo.XScaleMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.X_AXIS) ? Gizmo.HighlightMaterial : Gizmo.XMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(xRenderInfo);
                        RenderInfo yRenderInfo = new RenderInfo(Gizmo.YScaleMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Y_AXIS) ? Gizmo.HighlightMaterial : Gizmo.YMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(yRenderInfo);
                        RenderInfo zRenderInfo = new RenderInfo(Gizmo.ZScaleMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Z_AXIS) ? Gizmo.HighlightMaterial : Gizmo.ZMaterial, null, FillMode.Solid, gizmoSphere);
                        result.Add(zRenderInfo);
                    }
                    break;
            }
            #endregion

            transform.Pop();
            return result.ToArray();
        }
 public override List<RenderInfo> Render(Device dev, EditorCamera camera, MatrixStack transform)
 {
     List<RenderInfo> result = new List<RenderInfo>();
     result.AddRange(Model.DrawModel(dev, transform, LevelData.Textures[LevelData.leveltexs], Mesh, false));
     if (Selected)
         result.AddRange(Model.DrawModelInvert(dev, transform, Mesh, false));
     return result;
 }
        /// <summary>
        /// Draws the gizmo onscreen.
        /// </summary>
        /// <param name="d3ddevice"></param>
        /// <param name="cam"></param>
        public void Draw(Device d3ddevice, EditorCamera cam)
        {
            d3ddevice.RenderState.ZBufferEnable = true;
            d3ddevice.BeginScene();

            RenderInfo.Draw(Render(d3ddevice, new MatrixStack(), cam), d3ddevice, cam);

            d3ddevice.EndScene(); //all drawings before this line
        }
        /// <summary>
        /// Transforms the Items that belong to this Gizmo.
        /// </summary>
        /// <param name="xChange">Input for x axis.</param>
        /// <param name="yChange">Input for y axis.</param>
        public void TransformAffected(float xChange, float yChange, EditorCamera cam)
        {
            // don't operate with an invalid axis seleciton, or invalid mode
            if (!enabled)
                return;
            if ((selectedAxes == GizmoSelectedAxes.NONE) || (mode == TransformMode.NONE))
                return;

            float yFlip = -1; // I don't think we'll ever need to mess with this
            float xFlip = 1;
            float axisDot = 0;

            for (int i = 0; i < affectedItems.Count; i++) // loop through operands
            {
                Item currentItem = affectedItems[i];
                switch (mode)
                {
                    case TransformMode.TRANFORM_MOVE:
                        if (isTransformLocal) // then check operant space.
                        {
                            Vector3 Up = new Vector3(), Look = new Vector3(), Right = new Vector3();
                            affectedItems[i].GetLocalAxes(out Up, out Right, out Look);

                            Vector3 currentPosition = currentItem.Position.ToVector3();
                            Vector3 destination = new Vector3();

                            switch (selectedAxes)
                            {
                                case GizmoSelectedAxes.X_AXIS:
                                    axisDot = Vector3.Dot(cam.Look, Right);
                                    xFlip = (axisDot > 0) ? 1 : -1;
                                    destination = (currentPosition + Right * ((Math.Abs(xChange) > Math.Abs(yChange)) ? xChange * xFlip : yChange));
                                    break;
                                case GizmoSelectedAxes.Y_AXIS:
                                    destination = (currentPosition + Up * ((Math.Abs(xChange) > Math.Abs(yChange)) ? xChange : yChange * yFlip));
                                    break;
                                case GizmoSelectedAxes.Z_AXIS:
                                    axisDot = Vector3.Dot(cam.Look, Right);
                                    xFlip = (axisDot > 0) ? -1 : 1;
                                    destination = (currentPosition + Look * ((Math.Abs(xChange) > Math.Abs(yChange)) ? xChange * xFlip : yChange));
                                    break;
                            }

                            currentItem.Position = destination.ToVertex();
                        }
                        else
                        {
                            float xOff = 0.0f, yOff = 0.0f, zOff = 0.0f;
                            Vector3 axisDirection = new Vector3();

                            switch (selectedAxes)
                            {
                                case GizmoSelectedAxes.X_AXIS:
                                    axisDirection = new Vector3(1, 0, 0);
                                    axisDot = Vector3.Dot(cam.Look, axisDirection);
                                    xFlip = (axisDot > 0) ? 1 : -1;
                                    xOff = xChange * xFlip;
                                    break;
                                case GizmoSelectedAxes.Y_AXIS:
                                    axisDirection = new Vector3(0, 1, 0);
                                    axisDot = Vector3.Dot(cam.Look, axisDirection);
                                    yOff = yChange * yFlip;
                                    break;
                                case GizmoSelectedAxes.Z_AXIS:
                                    axisDirection = new Vector3(0, 0, 1);
                                    axisDot = Vector3.Dot(cam.Look, axisDirection);
                                    xFlip = (axisDot > 0) ? -1 : 1;
                                    zOff = xChange * xFlip;
                                    break;
                                case GizmoSelectedAxes.XY_AXIS:
                                    xOff = xChange; yOff = yChange * yFlip;
                                    break;
                                case GizmoSelectedAxes.XZ_AXIS:
                                    xOff = xChange; zOff = yChange;
                                    break;
                                case GizmoSelectedAxes.ZY_AXIS:
                                    zOff = xChange; yOff = yChange * yFlip;
                                    break;
                            }

                            currentItem.Position = new Vertex(currentItem.Position.X + xOff, currentItem.Position.Y + yOff, currentItem.Position.Z + zOff);
                        }

                        if (currentItem is LevelItem)
                        {
                            LevelItem levelItem = (LevelItem)currentItem;
                            levelItem.Save();
                        }
                        break;

                    case TransformMode.TRANSFORM_ROTATE:
                        if (currentItem is StartPosItem)
                        {
                            currentItem.Rotation.Y += (int)xChange;
                            continue;
                        }
                        if (currentItem is CAMItem)
                        {
                            currentItem.Rotation.Y += (int)xChange * 2;
                            continue;
                        }

                        if (isTransformLocal) // then check operant space.
                        {
                            try
                            {
                                switch (selectedAxes)
                                {
                                    case GizmoSelectedAxes.X_AXIS:
                                        currentItem.Rotation.XDeg += (int)xChange;
                                        break;
                                    case GizmoSelectedAxes.Y_AXIS:
                                        currentItem.Rotation.ZDeg += (int)xChange;
                                        break;
                                    case GizmoSelectedAxes.Z_AXIS:
                                        currentItem.Rotation.YDeg += (int)xChange;
                                        break;
                                }
                            }
                            catch (NotSupportedException)
                            {
                                Console.WriteLine("Certain Item types don't support rotations. This can be ignored.");
                            }
                        }
                        else
                        {
                            // This code doesn't work - we need to find another way to do global rotations
                            //int xOff = 0, yOff = 0, zOff = 0;
                            MatrixStack objTransform = new MatrixStack();

                            /*
                            switch (selectedAxes)
                            {
                                case GizmoSelectedAxes.X_AXIS:
                                    xOff = (int)xChange;
                                    break;

                                case GizmoSelectedAxes.Y_AXIS:
                                    yOff = (int)xChange;
                                    break;

                                case GizmoSelectedAxes.Z_AXIS:
                                    zOff = (int)xChange;
                                    break;
                            }
                            */

                            objTransform.Push();
                            //objTransform.RotateXYZLocal(xOff, yOff, zOff);
                            objTransform.RotateXYZLocal(currentItem.Rotation.X, currentItem.Rotation.Y, currentItem.Rotation.Z);

                            //Rotation oldRotation = currentItem.Rotation;
                            //Rotation newRotation = SAModel.Direct3D.Extensions.FromMatrix(objTransform.Top);

                            // todo: Fix Matrix->Euler conversion, then uncomment the line with the rotatexyz call. Then uncomment the call below and the gizmo should work.
                            //currentItem.Rotation = newRotation;
                        }
                        break;

                    case TransformMode.TRANSFORM_SCALE:
                        if (currentItem is LevelItem)
                        {
                            LevelItem levelItem = (LevelItem)currentItem;
                            switch (selectedAxes)
                            {
                                case GizmoSelectedAxes.X_AXIS:
                                    levelItem.CollisionData.Model.Scale = new Vertex(levelItem.CollisionData.Model.Scale.X + xChange, levelItem.CollisionData.Model.Scale.Y, levelItem.CollisionData.Model.Scale.Z);
                                    break;
                                case GizmoSelectedAxes.Y_AXIS:
                                    levelItem.CollisionData.Model.Scale = new Vertex(levelItem.CollisionData.Model.Scale.X, levelItem.CollisionData.Model.Scale.Y + yChange, levelItem.CollisionData.Model.Scale.Z);
                                    break;
                                case GizmoSelectedAxes.Z_AXIS:
                                    levelItem.CollisionData.Model.Scale = new Vertex(levelItem.CollisionData.Model.Scale.X, levelItem.CollisionData.Model.Scale.Y, levelItem.CollisionData.Model.Scale.Z + xChange);
                                    break;
                            }
                        }
                        else if (currentItem is CAMItem)
                        {
                            CAMItem camItem = (CAMItem)currentItem;
                            switch (selectedAxes)
                            {
                                case GizmoSelectedAxes.X_AXIS:
                                    camItem.Scale = new Vertex(MathHelper.Clamp(camItem.Scale.X + xChange, 1, float.MaxValue), MathHelper.Clamp(camItem.Scale.Y, 1, float.MaxValue), MathHelper.Clamp(camItem.Scale.Z, 1, float.MaxValue)); // Clamping is to prevent invalid scale valeus (0 or less)
                                    break;
                                case GizmoSelectedAxes.Y_AXIS:
                                    camItem.Scale = new Vertex(MathHelper.Clamp(camItem.Scale.X, 1, float.MaxValue), MathHelper.Clamp(camItem.Scale.Y + yChange, 1, float.MaxValue), MathHelper.Clamp(camItem.Scale.Z, 1, float.MaxValue));
                                    break;
                                case GizmoSelectedAxes.Z_AXIS:
                                    camItem.Scale = new Vertex(MathHelper.Clamp(camItem.Scale.X, 1, float.MaxValue), MathHelper.Clamp(camItem.Scale.Y, 1, float.MaxValue), MathHelper.Clamp(camItem.Scale.Z + xChange, 1, float.MaxValue)); // I just realized that Math.Min would work for these. Oh well, gave me an excuse to write a clamp function
                                    break;
                            }
                        }
                        break;
                }
            }

            SetGizmo();
        }
        /// <summary>
        /// Determines which axes have been selected by a hovering mouse.
        /// </summary>
        /// <param name="Near"></param>
        /// <param name="Far"></param>
        /// <param name="Viewport"></param>
        /// <param name="Projection"></param>
        /// <param name="View"></param>
        /// <param name="cam">viewport camera</param>
        /// <returns></returns>
        public GizmoSelectedAxes CheckHit(Vector3 Near, Vector3 Far, Viewport Viewport, Matrix Projection, Matrix View, EditorCamera cam)
        {
            if (!enabled)
                return GizmoSelectedAxes.NONE;

            MatrixStack transform = new MatrixStack();
            transform.Push();

            float dist = Direct3D.Extensions.Distance(cam.Position, position) * 0.0825f;

            transform.TranslateLocal(position.X, position.Y, position.Z);
            transform.RotateXYZLocal(rotation.X, rotation.Y, rotation.Z);
            transform.ScaleLocal(Math.Abs(dist), Math.Abs(dist), Math.Abs(dist));

            Vector3 pos = Vector3.Unproject(Near, Viewport, Projection, View, transform.Top);
            Vector3 dir = Vector3.Subtract(pos, Vector3.Unproject(Far, Viewport, Projection, View, transform.Top));
            IntersectInformation info;

            switch (mode)
            {
                case (TransformMode.TRANFORM_MOVE):
                    if (Gizmo.XMoveMesh.Intersect(pos, dir, out info))
                        return GizmoSelectedAxes.X_AXIS;
                    if (Gizmo.YMoveMesh.Intersect(pos, dir, out info))
                        return GizmoSelectedAxes.Y_AXIS;
                    if (Gizmo.ZMoveMesh.Intersect(pos, dir, out info))
                        return GizmoSelectedAxes.Z_AXIS;

                    if (!isTransformLocal) // don't even look for these if the transform is local.
                    {
                        if (Gizmo.XYMoveMesh.Intersect(pos, dir, out info))
                            return GizmoSelectedAxes.XY_AXIS;
                        if (Gizmo.ZXMoveMesh.Intersect(pos, dir, out info))
                            return GizmoSelectedAxes.XZ_AXIS;
                        if (Gizmo.ZYMoveMesh.Intersect(pos, dir, out info))
                            return GizmoSelectedAxes.ZY_AXIS;
                    }
                    break;

                case (TransformMode.TRANSFORM_ROTATE):
                    if (Gizmo.XRotateMesh.Intersect(pos, dir, out info))
                        return GizmoSelectedAxes.X_AXIS;
                    if (Gizmo.YRotateMesh.Intersect(pos, dir, out info))
                        return GizmoSelectedAxes.Y_AXIS;
                    if (Gizmo.ZRotateMesh.Intersect(pos, dir, out info))
                        return GizmoSelectedAxes.Z_AXIS;
                    break;

                case (TransformMode.TRANSFORM_SCALE):
                    if (Gizmo.XScaleMesh.Intersect(pos, dir, out info))
                        return GizmoSelectedAxes.X_AXIS;
                    if (Gizmo.YScaleMesh.Intersect(pos, dir, out info))
                        return GizmoSelectedAxes.Y_AXIS;
                    if (Gizmo.ZScaleMesh.Intersect(pos, dir, out info))
                        return GizmoSelectedAxes.Z_AXIS;
                    break;

                default:
                    selectedAxes = GizmoSelectedAxes.NONE;
                    break;
            }

            return GizmoSelectedAxes.NONE;
        }
Exemple #27
0
        private RenderInfo[] Render(Device dev, MatrixStack transform, EditorCamera cam)
        {
            List<RenderInfo> result = new List<RenderInfo>();

            if (!enabled)
                return result.ToArray();

            float dist = cam.Position.Distance(affectedPoint.ToVector3()) * 0.0825f;
            BoundingSphere gizmoSphere = new BoundingSphere() { Center = new Vertex(affectedPoint.X, affectedPoint.Y, affectedPoint.Z), Radius = (1.0f * Math.Abs(dist)) };

            #region Setting Render States
            dev.SetSamplerState(0, SamplerStageStates.MinFilter, (int)TextureFilter.Point); // no fancy filtering is required because no textures are even being used
            dev.SetSamplerState(0, SamplerStageStates.MagFilter, (int)TextureFilter.Point);
            dev.SetSamplerState(0, SamplerStageStates.MipFilter, (int)TextureFilter.Point);
            dev.SetRenderState(RenderStates.Lighting, true);
            dev.SetRenderState(RenderStates.SpecularEnable, false);
            dev.SetRenderState(RenderStates.Ambient, Color.White.ToArgb());
            dev.SetRenderState(RenderStates.AlphaBlendEnable, false);
            dev.SetRenderState(RenderStates.ColorVertex, false);
            dev.Clear(ClearFlags.ZBuffer, 0, 1, 0);
            #endregion

            transform.Push();
            transform.TranslateLocal(affectedPoint.X, affectedPoint.Y, affectedPoint.Z);
            if (scaleHandlesToCam) transform.ScaleLocal(Math.Abs(dist), Math.Abs(dist), Math.Abs(dist));
            else transform.ScaleLocal(handleSize, handleSize, handleSize);

            #region Creating Render Info
            RenderInfo xRenderInfo = new RenderInfo(Gizmo.XMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.X_AXIS) ? Gizmo.HighlightMaterial : Gizmo.XMaterial, null, FillMode.Solid, gizmoSphere);
            result.Add(xRenderInfo);
            RenderInfo yRenderInfo = new RenderInfo(Gizmo.YMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Y_AXIS) ? Gizmo.HighlightMaterial : Gizmo.YMaterial, null, FillMode.Solid, gizmoSphere);
            result.Add(yRenderInfo);
            RenderInfo zRenderInfo = new RenderInfo(Gizmo.ZMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.Z_AXIS) ? Gizmo.HighlightMaterial : Gizmo.ZMaterial, null, FillMode.Solid, gizmoSphere);
            result.Add(zRenderInfo);
            RenderInfo xyRenderInfo = new RenderInfo(Gizmo.XYMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.XY_AXIS) ? Gizmo.HighlightMaterial : Gizmo.DoubleAxisMaterial, null, FillMode.Solid, gizmoSphere);
            result.Add(xyRenderInfo);
            RenderInfo zxRenderInfo = new RenderInfo(Gizmo.ZXMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.XZ_AXIS) ? Gizmo.HighlightMaterial : Gizmo.DoubleAxisMaterial, null, FillMode.Solid, gizmoSphere);
            result.Add(zxRenderInfo);
            RenderInfo zyRenderInfo = new RenderInfo(Gizmo.ZYMoveMesh, 0, transform.Top, (selectedAxes == GizmoSelectedAxes.ZY_AXIS) ? Gizmo.HighlightMaterial : Gizmo.DoubleAxisMaterial, null, FillMode.Solid, gizmoSphere);
            result.Add(zyRenderInfo);
            #endregion

            transform.Pop();
            return result.ToArray();
        }
Exemple #28
0
        /// <summary>
        /// Determines which axes have been selected by a hovering mouse.
        /// </summary>
        /// <param name="Near"></param>
        /// <param name="Far"></param>
        /// <param name="Viewport"></param>
        /// <param name="Projection"></param>
        /// <param name="View"></param>
        /// <param name="cam">viewport camera</param>
        /// <returns></returns>
        public GizmoSelectedAxes CheckHit(Vector3 Near, Vector3 Far, Viewport Viewport, Matrix Projection, Matrix View, EditorCamera cam)
        {
            if (!enabled) return GizmoSelectedAxes.NONE;

            MatrixStack transform = new MatrixStack();
            transform.Push();

            float dist = cam.Position.Distance(affectedPoint.ToVector3()) * 0.0825f;

            transform.TranslateLocal(affectedPoint.X, affectedPoint.Y, affectedPoint.Z);
            if (scaleHandlesToCam)
                transform.ScaleLocal(Math.Abs(dist), Math.Abs(dist), Math.Abs(dist));
            else
                transform.ScaleLocal(handleSize, handleSize, handleSize);

            Vector3 pos = Vector3.Unproject(Near, Viewport, Projection, View, transform.Top);
            Vector3 dir = Vector3.Subtract(pos, Vector3.Unproject(Far, Viewport, Projection, View, transform.Top));
            IntersectInformation info;

            if (Gizmo.XMoveMesh.Intersect(pos, dir, out info)) return GizmoSelectedAxes.X_AXIS;
            if (Gizmo.YMoveMesh.Intersect(pos, dir, out info)) return GizmoSelectedAxes.Y_AXIS;
            if (Gizmo.ZMoveMesh.Intersect(pos, dir, out info)) return GizmoSelectedAxes.Z_AXIS;
            if (Gizmo.XYMoveMesh.Intersect(pos, dir, out info)) return GizmoSelectedAxes.XY_AXIS;
            if (Gizmo.ZXMoveMesh.Intersect(pos, dir, out info)) return GizmoSelectedAxes.XZ_AXIS;
            if (Gizmo.ZYMoveMesh.Intersect(pos, dir, out info)) return GizmoSelectedAxes.ZY_AXIS;

            return GizmoSelectedAxes.NONE;
        }
Exemple #29
0
        private void LoadFile(string filename)
        {
            loaded = false;
            UseWaitCursor = true;
            Enabled = false;
            LevelData.leveltexs = null;
            cam = new EditorCamera(EditorOptions.RenderDrawDistance);
            if (LandTable.CheckLevelFile(filename))
                LevelData.geo = LandTable.LoadFromFile(filename);
            else
            {
                byte[] file = File.ReadAllBytes(filename);
                if (Path.GetExtension(filename).Equals(".prs", StringComparison.OrdinalIgnoreCase))
                    file = FraGag.Compression.Prs.Decompress(file);
                using (LevelFileDialog dlg = new LevelFileDialog())
                {
                    dlg.ShowDialog(this);
                    LevelData.geo = new LandTable(file, (int)dlg.NumericUpDown1.Value, (uint)dlg.numericUpDown2.Value, (LandTableFormat)dlg.comboBox2.SelectedIndex);
                }
            }
            LevelData.LevelItems = new List<LevelItem>();

            for (int i = 0; i < LevelData.geo.COL.Count; i++)
                LevelData.LevelItems.Add(new LevelItem(LevelData.geo.COL[i], d3ddevice, i, selectedItems));

            LevelData.TextureBitmaps = new Dictionary<string, BMPInfo[]>();
            LevelData.Textures = new Dictionary<string, Texture[]>();
            using (OpenFileDialog a = new OpenFileDialog() { DefaultExt = "pvm", Filter = "Texture Files|*.pvm;*.gvm;*.prs" })
            {
                if (!string.IsNullOrEmpty(LevelData.geo.TextureFileName))
                    a.FileName = LevelData.geo.TextureFileName + ".pvm";
                else
                    a.FileName = string.Empty;
                if (a.ShowDialog(this) == DialogResult.OK)
                {
                    BMPInfo[] TexBmps = TextureArchive.GetTextures(a.FileName);
                    Texture[] texs = new Texture[TexBmps.Length];
                    for (int j = 0; j < TexBmps.Length; j++)
                        texs[j] = new Texture(d3ddevice, TexBmps[j].Image, Usage.None, Pool.Managed);
                    string texname = Path.GetFileNameWithoutExtension(a.FileName);
                    if (!LevelData.TextureBitmaps.ContainsKey(texname))
                        LevelData.TextureBitmaps.Add(texname, TexBmps);
                    if (!LevelData.Textures.ContainsKey(texname))
                        LevelData.Textures.Add(texname, texs);
                    LevelData.leveltexs = texname;
                }
            }
            loaded = true;
            transformGizmo = new TransformGizmo();
            gizmoSpaceComboBox.Enabled = false;
            gizmoSpaceComboBox.SelectedIndex = 0;

            clearLevelToolStripMenuItem.Enabled = LevelData.geo != null;
            statsToolStripMenuItem.Enabled = LevelData.geo != null;
            selectedItems.SelectionChanged += SelectionChanged;
            UseWaitCursor = false;
            Enabled = editInfoToolStripMenuItem.Enabled = saveToolStripMenuItem.Enabled = exportToolStripMenuItem.Enabled = importToolStripMenuItem.Enabled = true;

            DrawLevel();
        }
Exemple #30
0
        /// <summary>
        /// Draws the gizmo onscreen.
        /// </summary>
        /// <param name="d3ddevice"></param>
        /// <param name="cam"></param>
        public void Draw(Device d3ddevice, EditorCamera cam)
        {
            if ((affectedPoint == null) || (!enabled))
                return;

            d3ddevice.RenderState.ZBufferEnable = true;
            d3ddevice.BeginScene();

            RenderInfo.Draw(Render(d3ddevice, new MatrixStack(), cam), d3ddevice, cam);

            d3ddevice.EndScene(); //all drawings before this line
        }
        public static void Draw(IEnumerable <RenderInfo> items, Device device, EditorCamera camera, bool useOldSorting = false)
        {
            if (useOldSorting)
            {
                List <KeyValuePair <float, RenderInfo> > drawList = new List <KeyValuePair <float, RenderInfo> >();
                foreach (RenderInfo item in items)
                {
                    float dist = Extensions.Distance(camera.Position, item.Bounds.Center.ToVector3()) + item.Bounds.Radius;
                    if (dist > camera.DrawDistance)
                    {
                        continue;
                    }

                    if (item.Material != null && item.Material.UseAlpha)
                    {
                        bool ins = false;
                        for (int i = 0; i < drawList.Count; i++)
                        {
                            if (drawList[i].Key < dist)
                            {
                                drawList.Insert(i, new KeyValuePair <float, RenderInfo>(dist, item));
                                ins = true;
                                break;
                            }
                        }
                        if (!ins)
                        {
                            drawList.Add(new KeyValuePair <float, RenderInfo>(dist, item));
                        }
                    }
                    else
                    {
                        drawList.Insert(0, new KeyValuePair <float, RenderInfo>(float.MaxValue, item));
                    }
                }
                foreach (KeyValuePair <float, RenderInfo> item in drawList)
                {
                    item.Value.Draw(device);
                }
            }
            else
            {
                List <KeyValuePair <float, RenderInfo> > drawListTransparent = new List <KeyValuePair <float, RenderInfo> >();
                List <RenderInfo> drawListOpaque = new List <RenderInfo>();
                foreach (RenderInfo item in items)
                {
                    // Don't draw if too far
                    float dist = Extensions.Distance(camera.Position, item.Bounds.Center.ToVector3()) - item.Bounds.Radius;
                    if (dist > camera.DrawDistance)
                    {
                        continue;
                    }

                    // Split into transparent and opaque lists
                    if (item.Material != null && item.Material.UseAlpha)
                    {
                        drawListTransparent.Add(new KeyValuePair <float, RenderInfo>(dist, item));
                    }
                    else
                    {
                        drawListOpaque.Add(item);
                    }
                }

                // Sort transparent meshes
                drawListTransparent.Sort((y, x) => x.Key.CompareTo(y.Key));

                // Draw opaque meshes
                for (int i = drawListOpaque.Count - 1; i >= 0; i--)
                {
                    drawListOpaque[i].Draw(device);
                }

                // Draw transparent meshes
                foreach (KeyValuePair <float, RenderInfo> item in drawListTransparent)
                {
                    item.Value.Draw(device);
                }
            }
        }
Exemple #32
0
        /// <summary>
        /// Transforms the Items that belong to this Gizmo.
        /// </summary>
        /// <param name="xChange">Input for x axis.</param>
        /// <param name="yChange">Input for y axis.</param>
        /// <returns>TRUE if an operation was performed, FALSE if nothing was done.</returns>
        public bool TransformAffected(float xChange, float yChange, EditorCamera cam)
        {
            // don't operate with an invalid axis seleciton, or invalid mode
            if ((selectedAxes == GizmoSelectedAxes.NONE) || (!enabled))
                return false;

            if ((xChange == 0) && (yChange == 0)) return false;

            float yFlip = -1; // I don't think we'll ever need to mess with this
            float xFlip = 1;

            float xOff = 0.0f, yOff = 0.0f, zOff = 0.0f, axisDot = 0.0f;

            Vector3 axisDirection = new Vector3();

            switch (selectedAxes)
            {
                case GizmoSelectedAxes.X_AXIS:
                    axisDirection = new Vector3(1, 0, 0);
                    axisDot = Vector3.Dot(cam.Look, axisDirection);
                    xFlip = (axisDot > 0) ? 1 : -1;
                    xOff = xChange * xFlip;
                    break;
                case GizmoSelectedAxes.Y_AXIS:
                    axisDirection = new Vector3(0, 1, 0);
                    axisDot = Vector3.Dot(cam.Look, axisDirection);
                    yOff = yChange * yFlip;
                    break;
                case GizmoSelectedAxes.Z_AXIS:
                    axisDirection = new Vector3(0, 0, 1);
                    axisDot = Vector3.Dot(cam.Look, axisDirection);
                    xFlip = (axisDot > 0) ? -1 : 1;
                    zOff = xChange * xFlip;
                    break;
                case GizmoSelectedAxes.XY_AXIS:
                    xOff = xChange; yOff = yChange * yFlip;
                    break;
                case GizmoSelectedAxes.XZ_AXIS:
                    xOff = xChange; zOff = yChange;
                    break;
                case GizmoSelectedAxes.ZY_AXIS:
                    zOff = xChange; yOff = yChange * yFlip;
                    break;
            }

            affectedPoint.X += xOff;
            affectedPoint.Y += yOff;
            affectedPoint.Z += zOff;

            if (PointChanged != null) PointChanged(this);

            return true;
        }