Exemple #1
0
 public float distanceFromCameraPlain()
 {
     Vector3 currentCenter = new Vector3(center.X, center.Y, center.Z);
     currentCenter.TransformCoordinate(device.Transform.World);
     currentCenter.TransformCoordinate(device.Transform.View);
     return currentCenter.Z;
 }
Exemple #2
0
        public override void doAction(int Key)
        {
            foreach(Target ikx in cocs.allTargets){
                if(this.center.Y > 0){
                Vector3 foo = new Vector3(this.center.X,this.center.Y,center.Z);
                foo.TransformCoordinate(device.Transform.World);

                    if(ikx.distanceFromPoint(foo) < 0.5f*size_of_one_rectangle){
                        if(ikx.active){
                        cocs.toRemoveFromUniverse.Add(ikx);
                        ikx.active = false;
                        cocs.aArea[ikx.posX,ikx.posZ] = true;
                        cocs.targets++;
                        cocs.numberOfTargets--;
                        }
                    cocs.toRemoveFromUniverse.Add(this);
                    }
                }

            }
        }
        /// <summary>
        /// Renders the 2D hard-edged shadow that would be cast from this ConvexHull's polygonal
        /// geometry by a light positioned at lightPosWS.
        /// </summary>
        /// <param name="lightPosWS">The position of the light in world coordinates.</param>
        public void RenderShadow(Vector2 lightPosWS)
        {
            Vector3 UVOffset = new Vector3(0.0f, -0.5f, 0.0f);

            // Transform the light position into model space
            Vector2 lightPos = Vector2.TransformCoordinate(lightPosWS, Matrix.Invert(worldMatrix));

            List<Edge> contourEdges = new List<Edge>();

            for (int edgeIndex = 0; edgeIndex < polygonGeometry.NumEdges; ++edgeIndex)
            {
                Edge edge = polygonGeometry.GetEdge(edgeIndex);
                Vector2 edgeCenter = (edge.Vertex1Pos + edge.Vertex2Pos) * 0.5f;
                Vector2 incidentLightDir = edgeCenter - lightPos;

                // If the edge faces away from the light source
                if (Vector2.Dot(incidentLightDir, edge.Normal) >= 0.0f)
                {
                    contourEdges.Add(edge);
                }
            }

            if (contourEdges.Count < 1 || contourEdges.Count == polygonGeometry.NumEdges)
            {
                return;
            }

            const float ExtrudeMagnitude = 1000.0f;

            List<Quad> quads = new List<Quad>();

            int quadIndex = 0;
            foreach (Edge edge in contourEdges)
            {
                Vector3 lightPosVec3 = new Vector3(lightPos.X, lightPos.Y, 1.0f);

                Vector3 vertex1 = new Vector3(
                    edge.Vertex1Pos.X, edge.Vertex1Pos.Y, 1.0f);
                Vector3 vertex2 = new Vector3(
                    edge.Vertex2Pos.X, edge.Vertex2Pos.Y, 1.0f);

                // Transform the position data from model space to world space
                vertex1.TransformCoordinate(worldMatrix);
                vertex2.TransformCoordinate(worldMatrix);
                lightPosVec3.TransformCoordinate(worldMatrix);

                Quad quad = new Quad();
                Color shadowColor = Color.FromArgb((int)(1 * 255.0f), 0, 0, 0);

                quad.Vertices[2 * quadIndex + 0].Position = vertex1 + UVOffset;
                quad.Vertices[2 * quadIndex + 0].Color = shadowColor.ToArgb();

                quad.Vertices[2 * quadIndex + 1].Position = vertex1 + ExtrudeMagnitude * (vertex1 - lightPosVec3)
                    + UVOffset;
                quad.Vertices[2 * quadIndex + 1].Color = shadowColor.ToArgb();

                quad.Vertices[2 * quadIndex + 2].Position = vertex2 + UVOffset;
                quad.Vertices[2 * quadIndex + 2].Color = shadowColor.ToArgb();

                quad.Vertices[2 * quadIndex + 3].Position = vertex2 + ExtrudeMagnitude * (vertex2 - lightPosVec3)
                    + UVOffset;
                quad.Vertices[2 * quadIndex + 3].Color = shadowColor.ToArgb();

                quads.Add(quad);
            }

            renderer.Begin(effect);

            renderer.WorldMatrix = Matrix.Identity;
            effect.SetValue("world", renderer.WorldMatrix);
            effect.SetValue("worldViewProj", renderer.WorldViewProjectionMatrix);
            renderer.SetPass(3);
            renderer.Device.VertexFormat = Direct3D.CustomVertex.PositionColoredTextured.Format;

            foreach (Quad quad in quads)
            {
                renderer.Device.DrawUserPrimitives(Direct3D.PrimitiveType.TriangleStrip, 2, quad.Vertices);
            }

            renderer.End();
        }
Exemple #4
0
        private void ComputeBoundingSphere(JointFrame frame, Matrix parentMatrix)
        {
            // Give the meshes their proper relative positions within the cell
            Matrix combinedMatrix = frame.TransformationMatrix * parentMatrix;

            // If this frame contains a mesh, transform its bounding sphere and
            // combine it with the overall bounds for the cell
            if (frame.MeshContainer!=null)
            {
                Cytoplasm cyt = (Cytoplasm)frame.MeshContainer;
                float radius = cyt.BoundRadius;
                Vector3 centre = cyt.BoundCentre;
                // transform the sphere's centre
                centre.TransformCoordinate(combinedMatrix);
                // Transform the sphere's radius (to scale it - the original vertices are probably not at their final scale
                Vector3 radiusVector = new Vector3(radius, 0, 0);               // create a vector of size radius
                radiusVector.TransformCoordinate(combinedMatrix);               // transform it to rescale it
                radius = radiusVector.Length();                                 // scaled radius is the length of the transformed vector
                // Combine this sphere with the others in the cell
                RelSphere.CombineBounds(centre, radius);
            }

            // Now propagate the new combined matrix through to my siblings and children
            if (frame.Sibling != null)											// recurse through siblings
            {
                ComputeBoundingSphere(frame.Sibling, parentMatrix);
            }
            if (frame.FirstChild != null)										// recurse through children
            {
                ComputeBoundingSphere(frame.FirstChild, combinedMatrix);
            }
        }
Exemple #5
0
 protected override void world2Screen(ILPoint3Df p1_3D, ILPoint3Df p2_3D, out Point p1_2D, out Point p2_2D ) {
     Matrix mat = m_device.Transform.World;
     mat *= m_device.Transform.View;
     mat *= m_device.Transform.Projection;
     Vector3 s = new Vector3(p1_3D.X, p1_3D.Y, p1_3D.Z);
     Vector3 e = new Vector3(p2_3D.X, p2_3D.Y, p2_3D.Z);
     s.TransformCoordinate(mat);
     e.TransformCoordinate(mat);
     s.X = (s.X / 2.0f + 0.5f);
     e.X = (e.X / 2.0f + 0.5f);
     s.Y = -(s.Y / 2.0f - 0.5f);
     e.Y = -(e.Y / 2.0f - 0.5f);
     // variant with margin over viewport
     //float multMarg = (m_device.Viewport.Width / 100.0f); 
     //startX = (int)(multMarg * (100.0f - 0.0f * m_margin) * s.X + m_margin * multMarg); 
     //endX =   (int)(multMarg * (100.0f - 0.0f * m_margin) * e.X + m_margin * multMarg); 
     //multMarg = (m_device.Viewport.Height / 100.0f); 
     //startY = (int)(multMarg * (100.0f - 0.0f * m_margin) * s.Y + m_margin * multMarg); 
     //endY =   (int)(multMarg * (100.0f - 0.0f * m_margin) * e.Y + m_margin * multMarg); 
     float multMarg = (m_device.Viewport.Width);
     p1_2D = new Point ((int)(multMarg * s.X),(int)(m_device.Viewport.Height * s.Y));
     p2_2D = new Point ((int)(multMarg * e.X),(int)(m_device.Viewport.Height * e.Y));
 }
Exemple #6
0
 public float distanceFromPoint(float x, float y, float z)
 {
     Vector3 currentCenter = new Vector3(center.X, center.Y, center.Z);
     currentCenter.TransformCoordinate(device.Transform.World);
     return (float)Math.Sqrt(Math.Pow(currentCenter.X - x, 2) + Math.Pow(currentCenter.Y - y, 2) + Math.Pow(currentCenter.Z - z, 2));
 }
        private void DrawAxis()
        {
            Matrix mtxWorld = Matrix.Identity;

            if(!this.IsRoot)
                mtxWorld = Translation * this.Parent_DX.CombinedTransformationMatrix;
            else
                mtxWorld = Translation * this.CombinedTransformationMatrix;

            float fltScale = ((this.MinDimension + this.MaxDimension)/2 * 0.15f);
            if(fltScale > 0.1f) fltScale = 0.1f;

            //Draw X Axis
            m_d3dDevice.Material = m_matXAxis;
            m_d3dDevice.Transform.World = Matrix.RotationY(Geometry.DegreeToRadian(-90)) * Matrix.Translation(10 * fltScale, 0.0f, 0.0f) * mtxWorld * Device.Transform.World1;
            m_mshAxisCylinder.DrawSubset(0);
            m_d3dDevice.Transform.World = Matrix.RotationY(Geometry.DegreeToRadian(-90)) * Matrix.Translation(20 * fltScale, 0.0f, 0.0f) * mtxWorld * Device.Transform.World1;
            m_mshAxisCone.DrawSubset(0);

            //Draw Y Axis
            m_d3dDevice.Material = m_matYAxis;
            m_d3dDevice.Transform.World = Matrix.RotationX(Geometry.DegreeToRadian(-90)) * Matrix.Translation(0.0f, 10 * fltScale, 0.0f) * mtxWorld * Device.Transform.World1;
            m_mshAxisCylinder.DrawSubset(0);
            m_d3dDevice.Transform.World = Matrix.RotationX(Geometry.DegreeToRadian(90)) * Matrix.Translation(0.0f, 20 * fltScale, 0.0f) * mtxWorld * Device.Transform.World1;
            m_mshAxisCone.DrawSubset(0);

            //Draw Z Axis
            m_d3dDevice.Material = m_matZAxis;
            m_d3dDevice.Transform.World =  Matrix.Translation(0.0f, 0.0f, 10 * fltScale) * mtxWorld * Device.Transform.World1;
            m_mshAxisCylinder.DrawSubset(0);
            m_d3dDevice.Transform.World = Matrix.RotationY(Geometry.DegreeToRadian(180)) * Matrix.Translation(0.0f, 0.0f, 20 * fltScale) * mtxWorld * Device.Transform.World1;
            m_mshAxisCone.DrawSubset(0);

            //Draw X axis label
            m_d3dDevice.Transform.World = Matrix.Translation(25 * fltScale, 0.0f, 0.0f) * mtxWorld * Device.Transform.World1;
            Vector3 tmp = new Vector3();
            tmp.TransformCoordinate(m_d3dDevice.Transform.World);

            Matrix m =m_d3dDevice.Transform.View;
            m.Invert();
            m.M41 = tmp.X;
            m.M42 = tmp.Y;
            m.M43 = tmp.Z;

            m_d3dDevice.Transform.World = m;

            Device.Material = Util_DX.WhiteMaterial();
            Device.SetTexture(0,texX);
            m_mshAxisLabel.DrawSubset(0);
            Device.SetTexture(0,null);

            //Draw Y Axis Label
            m_d3dDevice.Transform.World = Matrix.Translation(0.0f, 25 * fltScale, 0.0f) * mtxWorld * Device.Transform.World1;
            tmp = new Vector3();
            tmp.TransformCoordinate(m_d3dDevice.Transform.World);

            m =m_d3dDevice.Transform.View;
            m.Invert();
            m.M41 = tmp.X;
            m.M42 = tmp.Y;
            m.M43 = tmp.Z;

            m_d3dDevice.Transform.World = m;

            Device.Material = Util_DX.WhiteMaterial();
            Device.SetTexture(0,texY);
            m_mshAxisLabel.DrawSubset(0);
            Device.SetTexture(0,null);

            //Draw Z Axis Label
            m_d3dDevice.Transform.World = Matrix.Translation(0.0f, 0.0f, 25 * fltScale) * mtxWorld * Device.Transform.World1;
            tmp = new Vector3();
            tmp.TransformCoordinate(m_d3dDevice.Transform.World);

            m =m_d3dDevice.Transform.View;
            m.Invert();
            m.M41 = tmp.X;
            m.M42 = tmp.Y;
            m.M43 = tmp.Z;

            m_d3dDevice.Transform.World = m;

            Device.Material = Util_DX.WhiteMaterial();
            Device.SetTexture(0,texZ);
            m_mshAxisLabel.DrawSubset(0);
            Device.SetTexture(0,null);
        }
Exemple #8
0
        protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
        {
            if ( !GetAsyncKeyState(ArcBall.CameraControlKey) && (e.Button == MouseButtons.Left) && selectedObjects.Count != 0 )
            {

                if (_editMode == EditMode.Rotate)
                {

                    Vector3 direction = camera.TargetPoint - camera.EyePosition;
                    Vector3 horizontal = Vector3.Cross(direction, camera.UpVector);
                    Vector3 upVector = camera.UpVector;

                    horizontal.Normalize();
                    upVector.Normalize();

                    float rotateX = (0.5f * (mouseDownX - e.X)) * upVector.X +
                        (0.5f * (e.Y - mouseDownY)) * horizontal.X + _startRotation.X;

                    float rotateY = (0.5f * (mouseDownX - e.X)) * upVector.Y +
                        (0.5f * (e.Y - mouseDownY)) * horizontal.Y + _startRotation.Y;

                    float rotateZ = (0.5f * (mouseDownX - e.X)) * upVector.Z +
                        (0.5f * (e.Y - mouseDownY)) * horizontal.Z + _startRotation.Z;

                    Midget.Events.EventFactory.Instance.GenerateTransformationRequestEvent(this,selectedObjects,
                        new AxisValue(rotateX, rotateY, rotateZ),
                        Midget.Events.Object.Transformation.Transformation.Rotate);

                    mouseDownX = e.X;
                    mouseDownY = e.Y;

                    dm.UpdateViews();
                }
                else if (_editMode == EditMode.Move)
                {
                    // our picking
                    Vector3 pickRayOrigin = new Vector3();
                    Vector3 pickRayDir = new Vector3();
                    Vector3 pickRayOriginNew = new Vector3();
                    Vector3 pickRayDirNew = new Vector3();

                    Vector3 direction = camera.TargetPoint - camera.EyePosition;
                    Vector3 horizontal = Vector3.Cross(direction, camera.UpVector);
                    Vector3 upVector = camera.UpVector;

                    horizontal.Normalize();
                    upVector.Normalize();

                    // grab the last selected object
                    IObject3D selObj = (IObject3D)selectedObjects[selectedObjects.Count - 1];

                    // original mouse position
                    camera.UnProjectCoordinates(mouseDownX, mouseDownY, this.Width,
                        this.Height, ref pickRayOrigin, ref pickRayDir);

                    // new mouse position
                    camera.UnProjectCoordinates(e.X,
                        e.Y, this.Width,
                        this.Height, ref pickRayOriginNew, ref pickRayDirNew);

                    // transform by world and object model space
                    pickRayOrigin.TransformCoordinate(Matrix.Invert(camera.WorldMatrix));
                    pickRayOriginNew.TransformCoordinate(Matrix.Invert(camera.WorldMatrix));

                    // find the movement vector
                    Vector3 result = pickRayOriginNew - pickRayOrigin;

                    // pretty crappy compensation
                    if (this.Camera is PerspectiveMidgetCamera)
                    {
                        result *= 10.0f;
                    }

                    // generate an axis value to move by
                    AxisValue axes = new AxisValue(
                        selObj.Translation.X + result.X,
                        selObj.Translation.Y + result.Y,
                        selObj.Translation.Z + result.Z);

                    Midget.Events.EventFactory.Instance.GenerateTransformationRequestEvent(this, selectedObjects,
                        axes,
                        Midget.Events.Object.Transformation.Transformation.Translate);

                    mouseDownX = e.X;
                    mouseDownY = e.Y;

                    dm.UpdateViews();
                }
                else if (_editMode == EditMode.Scale)
                {
                    float scaleX = 0.05f * (mouseDownX - e.X) + _startScaling.X;
                    float scaleY = 0.05f * (mouseDownY - e.Y) + _startScaling.Y;

                    Midget.Events.EventFactory.Instance.GenerateTransformationRequestEvent(this,selectedObjects,
                        new AxisValue(scaleY,scaleY,scaleY),
                        Midget.Events.Object.Transformation.Transformation.Scale);

                    mouseDownX = e.X;
                    mouseDownY = e.Y;

                    dm.UpdateViews();
                }
            }

            base.OnMouseMove (e);
        }
        private void DrawAxis()
        {
            //Draw X Axis
            m_d3dDevice.Material = m_matXAxis;
            m_d3dDevice.Transform.World = Matrix.RotationY(Geometry.DegreeToRadian(-90)) * Matrix.Translation(1.0f, 0.0f, 0.0f) * m_d3dDevice.Transform.World1;
            m_mshAxisCylinder.DrawSubset(0);
            m_d3dDevice.Transform.World = Matrix.RotationY(Geometry.DegreeToRadian(-90)) * Matrix.Translation(2.0f, 0.0f, 0.0f) * m_d3dDevice.Transform.World1;
            m_mshAxisCone.DrawSubset(0);

            //Draw Y Axis
            m_d3dDevice.Material = m_matYAxis;
            m_d3dDevice.Transform.World = Matrix.RotationX(Geometry.DegreeToRadian(-90)) * Matrix.Translation(0.0f, 1.0f, 0.0f) * m_d3dDevice.Transform.World1;
            m_mshAxisCylinder.DrawSubset(0);
            m_d3dDevice.Transform.World = Matrix.RotationX(Geometry.DegreeToRadian(90)) * Matrix.Translation(0.0f, 2.0f, 0.0f) * m_d3dDevice.Transform.World1;
            m_mshAxisCone.DrawSubset(0);

            //Draw Z Axis
            m_d3dDevice.Material = m_matZAxis;
            m_d3dDevice.Transform.World =  Matrix.Translation(0.0f, 0.0f, 1.0f) * m_d3dDevice.Transform.World1;
            m_mshAxisCylinder.DrawSubset(0);
            m_d3dDevice.Transform.World = Matrix.RotationY(Geometry.DegreeToRadian(180)) * Matrix.Translation(0.0f, 0.0f, 2.0f) * m_d3dDevice.Transform.World1;
            m_mshAxisCone.DrawSubset(0);

            //Draw X axis label
            m_d3dDevice.Transform.World = Matrix.Translation(2.5f, 0.0f, 0.0f) * m_d3dDevice.Transform.World1;
            Vector3 tmp = new Vector3();
            tmp.TransformCoordinate(m_d3dDevice.Transform.World);

            Matrix m =m_d3dDevice.Transform.View;
            m.Invert();
            m.M41 = tmp.X;
            m.M42 = tmp.Y;
            m.M43 = tmp.Z;

            m_d3dDevice.Transform.World = m;

            Device.Material = Util_DX.WhiteMaterial();
            Device.SetTexture(0,texX);
            m_mshAxisLabel.DrawSubset(0);
            Device.SetTexture(0,null);

            //Draw Y Axis Label
            m_d3dDevice.Transform.World = Matrix.Translation(0.0f, 2.5f, 0.0f) * m_d3dDevice.Transform.World1;
            tmp = new Vector3();
            tmp.TransformCoordinate(m_d3dDevice.Transform.World);

            m =m_d3dDevice.Transform.View;
            m.Invert();
            m.M41 = tmp.X;
            m.M42 = tmp.Y;
            m.M43 = tmp.Z;

            m_d3dDevice.Transform.World = m;

            Device.Material = Util_DX.WhiteMaterial();
            Device.SetTexture(0,texY);
            m_mshAxisLabel.DrawSubset(0);
            Device.SetTexture(0,null);

            //Draw Z Axis Label
            m_d3dDevice.Transform.World = Matrix.Translation(0.0f, 0.0f, 2.5f) * m_d3dDevice.Transform.World1;
            tmp = new Vector3();
            tmp.TransformCoordinate(m_d3dDevice.Transform.World);

            m =m_d3dDevice.Transform.View;
            m.Invert();
            m.M41 = tmp.X;
            m.M42 = tmp.Y;
            m.M43 = tmp.Z;

            m_d3dDevice.Transform.World = m;

            Device.Material = Util_DX.WhiteMaterial();
            Device.SetTexture(0,texZ);
            m_mshAxisLabel.DrawSubset(0);
            Device.SetTexture(0,null);
        }
        protected void DrawCenterSelectionBox()
        {
            //set the location of the center selection box
            Vector3 tmp = new Vector3();
            tmp.TransformCoordinate(CombinedTransformationMatrix * Device.Transform.World1);

            //get the current view matrix and invert it
            Matrix m = this.Device.Transform.View;
            m.Invert();

            //set the location of the inverted view matrix to the location of the selection box
            m.M41 = tmp.X;
            m.M42 = tmp.Y;
            m.M43 = tmp.Z;

            //set the device world matrix
            this.Device.Transform.World = m;

            //set a white material
            this.Device.Material = Util_DX.WhiteMaterial();

            //disable the z buffer
            this.Device.RenderState.ZBufferEnable = false;

            //set the texture of the selection box
            Device.SetTexture(0,texCB);

            //draw the selection box
            m_mshCB.DrawSubset(0);

            //set the texture back to null
            Device.SetTexture(0,null);

            //renable the z buffer
            this.Device.RenderState.ZBufferEnable = true;
        }
        private Vector3 getDirectionVector(int i, int u)
        {
            Vector3 directionVector = new Vector3(mirrorBallDirectionVector.X, mirrorBallDirectionVector.Y, mirrorBallDirectionVector.Z);

            directionVector.TransformCoordinate(Matrix.RotationY(mirrorBallFov * i + (mirrorBallFov - FastMath.PI) / 2));

            Vector3 xAxis = new Vector3(directionVector.X, directionVector.Y, directionVector.Z);
            xAxis.TransformCoordinate(Matrix.RotationY(FastMath.PI_HALF));

            directionVector.TransformCoordinate(Matrix.RotationAxis(xAxis, mirrorBallFov * u + (mirrorBallFov - FastMath.PI) / 2));

            return directionVector;
        }
Exemple #12
0
        /// <summary>
        /// The extract model as single mesh.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <remarks></remarks>
        public void ExtractModelAsSingleMesh(string path)
        {
            int ndex = path.LastIndexOf('\\');
            string f**k = path.Remove(ndex + 1);

            

            string texturepath = f**k + "Textures\\";
            Directory.CreateDirectory(texturepath);
            List<string> names = new List<string>();
            string mtllib = this.Name + ".mtl";
            FileStream FS = new FileStream(f**k + mtllib, FileMode.Create);
            StreamWriter SW = new StreamWriter(FS);
            Panel p = new Panel();
            Renderer r = new Renderer();
            r.CreateDevice(p);
            for (int x = 0; x < this.Shaders.Shader.Length; x++)
            {
                string[] namesplit = this.Shaders.Shader[x].shaderName.Split('\\');
                string temps = namesplit[namesplit.Length - 1];
                names.Add(temps);
                this.Shaders.Shader[x].MakeTextures(ref r.device);

                TextureLoader.Save(
                    texturepath + temps + ".dds", ImageFileFormat.Dds, this.Shaders.Shader[x].MainTexture);
                if (x > 0)
                {
                    SW.WriteLine(string.Empty);
                }

                SW.WriteLine("newmtl " + temps);
                SW.WriteLine("Ka 1.000000 1.000000 1.000000");
                SW.WriteLine("Kd 1.000000 1.000000 1.000000");
                SW.WriteLine("Ks 1.000000 1.000000 1.000000");
                SW.WriteLine("Ns 0.000000");
                SW.WriteLine(@"map_Kd .\\Textures\\" + temps + ".dds");
            }

            SW.Close();
            FS.Close();

            

            #region ExportBSPMeshes

            FS = new FileStream(path, FileMode.Create);
            SW = new StreamWriter(FS);
            SW.WriteLine("# ------------------------------------");
            SW.WriteLine("# Halo 2 BSP Mesh - Extracted with Entity");
            SW.WriteLine("# ------------------------------------");
            SW.WriteLine("mtllib " + mtllib);
            int vertcount = 0;

            for (int x = 0; x < this.BSPRawDataMetaChunks.Length; x++)
            {
                if (this.BSPRawDataMetaChunks[x].VerticeCount == 0)
                {
                    continue;
                }

                for (int y = 0; y < this.BSPRawDataMetaChunks[x].VerticeCount; y++)
                {
                    string temps = "v " + this.BSPRawDataMetaChunks[x].Vertices[y].X.ToString("R") + " " +
                                   this.BSPRawDataMetaChunks[x].Vertices[y].Y.ToString("R") + " " +
                                   this.BSPRawDataMetaChunks[x].Vertices[y].Z.ToString("R");
                    SW.WriteLine(temps);
                }

                SW.WriteLine("# " + this.BSPRawDataMetaChunks[x].Vertices.Count + " vertices");
                for (int y = 0; y < this.BSPRawDataMetaChunks[x].VerticeCount; y++)
                {
                    string temps = "vt " + this.BSPRawDataMetaChunks[x].UVs[y].X.ToString("R") + " " +
                                   (1 - this.BSPRawDataMetaChunks[x].UVs[y].Y).ToString("R");
                    SW.WriteLine(temps);
                }

                SW.WriteLine("# " + this.BSPRawDataMetaChunks[x].Vertices.Count + " texture vertices");
                for (int y = 0; y < this.BSPRawDataMetaChunks[x].VerticeCount; y++)
                {
                    string temps = "vn " + this.BSPRawDataMetaChunks[x].Normals[y].X.ToString("R") + " " +
                                   this.BSPRawDataMetaChunks[x].Normals[y].Y.ToString("R") + " " +
                                   this.BSPRawDataMetaChunks[x].Normals[y].Z.ToString("R");
                    SW.WriteLine(temps);
                }

                SW.WriteLine("# " + this.BSPRawDataMetaChunks[x].Vertices.Count + " normals");
                for (int y = 0; y < this.BSPRawDataMetaChunks[x].SubMeshInfo.Length; y++)
                {
                    SW.WriteLine("g " + x + "." + y);
                    // SW.WriteLine("s "+x.ToString()+"." + y.ToString());
                    SW.WriteLine("usemtl  " + names[this.BSPRawDataMetaChunks[x].SubMeshInfo[y].ShaderNumber]);

                    // int[] s***e = new int[100000];
                    int[] s***e = new int[this.BSPRawDataMetaChunks[x].SubMeshInfo[y].IndiceCount];
                    int s = 0;
                    if (this.BSPRawDataMetaChunks[x].FaceCount * 3 != this.BSPRawDataMetaChunks[x].IndiceCount)
                    {
                        int m = this.BSPRawDataMetaChunks[x].SubMeshInfo[y].IndiceStart;
                        bool dir = false;
                        short tempx;
                        short tempy;
                        short tempz;

                        do
                        {
                            // if (mode.EndOfIndices[x][j]>m+2){break;}
                            tempx = this.BSPRawDataMetaChunks[x].Indices[m];
                            tempy = this.BSPRawDataMetaChunks[x].Indices[m + 1];
                            tempz = this.BSPRawDataMetaChunks[x].Indices[m + 2];

                            if (tempx != tempy && tempx != tempz && tempy != tempz)
                            {
                                if (dir == false)
                                {
                                    s***e[s] = vertcount + tempx;
                                    s***e[s + 1] = vertcount + tempy;
                                    s***e[s + 2] = vertcount + tempz;
                                    s += 3;

                                    dir = true;
                                }
                                else
                                {
                                    s***e[s] = vertcount + tempx;
                                    s***e[s + 1] = vertcount + tempz;
                                    s***e[s + 2] = vertcount + tempy;
                                    s += 3;
                                    dir = false;
                                }

                                m += 1;
                            }
                            else
                            {
                                if (dir)
                                {
                                    dir = false;
                                }
                                else
                                {
                                    dir = true;
                                }

                                m += 1;
                            }
                        }
                        while (m <
                               this.BSPRawDataMetaChunks[x].SubMeshInfo[y].IndiceStart +
                               this.BSPRawDataMetaChunks[x].SubMeshInfo[y].IndiceCount - 2);
                    }
                    else
                    {
                        for (int u = 0; u < this.BSPRawDataMetaChunks[x].SubMeshInfo[y].IndiceCount; u++)
                        {
                            s***e[u] = vertcount +
                                        this.BSPRawDataMetaChunks[x].Indices[
                                            this.BSPRawDataMetaChunks[x].SubMeshInfo[y].IndiceStart + u];
                        }

                        s = this.BSPRawDataMetaChunks[x].SubMeshInfo[y].IndiceCount;
                    }

                    for (int xx = 0; xx < s; xx += 3)
                    {
                        string temps = "f " + (s***e[xx] + 1) + "/" + (s***e[xx] + 1) + "/" + (s***e[xx] + 1) + " " +
                                       (s***e[xx + 1] + 1) + "/" + (s***e[xx + 1] + 1) + "/" + (s***e[xx + 1] + 1) + " " +
                                       (s***e[xx + 2] + 1) + "/" + (s***e[xx + 2] + 1) + "/" + (s***e[xx + 2] + 1);
                        SW.WriteLine(temps);
                    }

                    SW.WriteLine("# " + (s / 3) + " elements");
                }

                vertcount += this.BSPRawDataMetaChunks[x].VerticeCount;
            }

            #endregion

            SW.Close();
            FS.Close();

            #region ExportBSPPermutationMeshes

            FS = new FileStream(path.Substring(0, path.LastIndexOf('.')) + "-permutations.obj", FileMode.Create);
            SW = new StreamWriter(FS);
            SW.WriteLine("# ------------------------------------");
            SW.WriteLine("# Halo 2 BSP Permutation Mesh");
            SW.WriteLine("# ------------------------------------");
            SW.WriteLine("mtllib " + mtllib);
            vertcount = 0;

            for (int tx = 0; tx < this.PermutationInfo.Length; tx++)
            {
                int x = this.PermutationInfo[tx].sceneryIndex;
                if ((this.BSPPermutationRawDataMetaChunks[x].RawDataChunkInfo.Length == 0) ||
                    (this.BSPPermutationRawDataMetaChunks[x].VerticeCount == 0))
                {
                    continue;
                }

                for (int y = 0; y < this.BSPPermutationRawDataMetaChunks[x].VerticeCount; y++)
                {
                    Vector3 tv3 = new Vector3(
                        this.BSPPermutationRawDataMetaChunks[x].Vertices[y].X, 
                        this.BSPPermutationRawDataMetaChunks[x].Vertices[y].Y, 
                        this.BSPPermutationRawDataMetaChunks[x].Vertices[y].Z);
                    tv3.TransformCoordinate(this.PermutationInfo[tx].mat);
                    string temps = "v " + tv3.X.ToString("R") + " " + tv3.Y.ToString("R") + " " + tv3.Z.ToString("R");
                    SW.WriteLine(temps);
                }

                SW.WriteLine("# " + this.BSPPermutationRawDataMetaChunks[x].Vertices.Count + " vertices");
                for (int y = 0; y < this.BSPPermutationRawDataMetaChunks[x].VerticeCount; y++)
                {
                    string temps = "vt " + this.BSPPermutationRawDataMetaChunks[x].UVs[y].X.ToString("R") + " " +
                                   this.BSPPermutationRawDataMetaChunks[x].UVs[y].Y.ToString("R");
                    SW.WriteLine(temps);
                }

                SW.WriteLine("# " + this.BSPPermutationRawDataMetaChunks[x].Vertices.Count + " texture vertices");
                for (int y = 0; y < this.BSPPermutationRawDataMetaChunks[x].VerticeCount; y++)
                {
                    Vector3 tv3 = new Vector3(
                        this.BSPPermutationRawDataMetaChunks[x].Normals[y].X, 
                        this.BSPPermutationRawDataMetaChunks[x].Normals[y].Y, 
                        this.BSPPermutationRawDataMetaChunks[x].Normals[y].Z);
                    tv3.TransformNormal(this.PermutationInfo[tx].mat);
                    string temps = "vn " + tv3.X.ToString("R") + " " + tv3.Y.ToString("R") + " " + tv3.Z.ToString("R");
                    /*
                    string temps = "vn " + this.BSPPermutationRawDataMetaChunks[x].Normals[y].X.ToString()
                                   + " " + this.BSPPermutationRawDataMetaChunks[x].Normals[y].Y.ToString()
                                   + " " + this.BSPPermutationRawDataMetaChunks[x].Normals[y].Z.ToString();
                    */
                    SW.WriteLine(temps);
                }

                SW.WriteLine("# " + this.BSPPermutationRawDataMetaChunks[x].Vertices.Count + " normals");
                for (int y = 0; y < this.BSPPermutationRawDataMetaChunks[x].SubMeshInfo.Length; y++)
                {
                    SW.WriteLine("g " + tx + "." + y);
                    SW.WriteLine(
                        "usemtl  " + names[this.BSPPermutationRawDataMetaChunks[x].SubMeshInfo[y].ShaderNumber]);

                    // int[] s***e = new int[100000];
                    int[] s***e = new int[this.BSPPermutationRawDataMetaChunks[x].SubMeshInfo[y].IndiceCount];

                    int s = 0;
                    if (this.BSPPermutationRawDataMetaChunks[x].FaceCount * 3 !=
                        this.BSPPermutationRawDataMetaChunks[x].IndiceCount)
                    {
                        int m = this.BSPPermutationRawDataMetaChunks[x].SubMeshInfo[y].IndiceStart;

                        bool dir = false;
                        short tempx;
                        short tempy;
                        short tempz;

                        do
                        {
                            // if (mode.EndOfIndices[x][j]>m+2){break;}
                            tempx = this.BSPPermutationRawDataMetaChunks[x].Indices[m];
                            tempy = this.BSPPermutationRawDataMetaChunks[x].Indices[m + 1];
                            tempz = this.BSPPermutationRawDataMetaChunks[x].Indices[m + 2];

                            if (tempx != tempy && tempx != tempz && tempy != tempz)
                            {
                                if (dir == false)
                                {
                                    s***e[s] = vertcount + tempx;
                                    s***e[s + 1] = vertcount + tempy;
                                    s***e[s + 2] = vertcount + tempz;
                                    s += 3;

                                    dir = true;
                                }
                                else
                                {
                                    s***e[s] = vertcount + tempx;
                                    s***e[s + 1] = vertcount + tempz;
                                    s***e[s + 2] = vertcount + tempy;
                                    s += 3;
                                    dir = false;
                                }

                                m += 1;
                            }
                            else
                            {
                                if (dir)
                                {
                                    dir = false;
                                }
                                else
                                {
                                    dir = true;
                                }

                                m += 1;
                            }
                        }
                        while (m <
                               this.BSPPermutationRawDataMetaChunks[x].SubMeshInfo[y].IndiceStart +
                               this.BSPPermutationRawDataMetaChunks[x].SubMeshInfo[y].IndiceCount - 2);
                    }
                    else
                    {
                        for (int u = 0; u < this.BSPPermutationRawDataMetaChunks[x].SubMeshInfo[y].IndiceCount; u++)
                        {
                            s***e[u] = vertcount +
                                        this.BSPPermutationRawDataMetaChunks[x].Indices[
                                            this.BSPPermutationRawDataMetaChunks[x].SubMeshInfo[y].IndiceStart + u];
                        }

                        s = this.BSPPermutationRawDataMetaChunks[x].SubMeshInfo[y].IndiceCount;
                    }

                    for (int xx = 0; xx < s; xx += 3)
                    {
                        string temps = "f " + (s***e[xx] + 1) + "/" + (s***e[xx] + 1) + "/" + (s***e[xx] + 1) + " " +
                                       (s***e[xx + 1] + 1) + "/" + (s***e[xx + 1] + 1) + "/" + (s***e[xx + 1] + 1) + " " +
                                       (s***e[xx + 2] + 1) + "/" + (s***e[xx + 2] + 1) + "/" + (s***e[xx + 2] + 1);
                        SW.WriteLine(temps);
                    }

                    SW.WriteLine("# " + (s / 3) + " elements");
                }

                vertcount += this.BSPPermutationRawDataMetaChunks[x].VerticeCount;
            }

            SW.Close();
            FS.Close();

            #endregion
        }
Exemple #13
0
        public override int Intersect( Vector3 rayPosition, Vector3 rayDirection, ref Object3DCommon obj, Matrix worldSpace )
        {
            Matrix myModelSpace = scalingMatrix * rotationMatrix * translationMatrix * worldSpace;

            // transform world space to object space
            Vector3 pickRayOriginTemp = new Vector3(rayPosition.X, rayPosition.Y, rayPosition.Z);
            Vector3 pickRayDirectionTemp = new Vector3(rayDirection.X,rayDirection.Y,rayDirection.Z);

            // convert ray from 3d space to model space
            pickRayOriginTemp.TransformCoordinate(Matrix.Invert(myModelSpace));
            pickRayDirectionTemp.TransformNormal (Matrix.Invert(myModelSpace));

            // check to see if I intersect
            int zDistance = CheckIntersect(pickRayOriginTemp,pickRayDirectionTemp);
            if (zDistance > 0)
            {
                obj = this;
            }

            if (_children != null)
            {
                foreach (Object3DCommon childObj in _children)
                {
                    int newZDistance = childObj.Intersect(rayPosition, rayDirection, ref obj, myModelSpace);
                    if (newZDistance > zDistance)
                    {
                        zDistance = newZDistance;
                    }
                }
            }

            return zDistance;
        }
Exemple #14
0
        public static void GenerateShadow( Mesh polygonGeometry, Matrix worldMatrix, Vector2 lightPosWS,
            float zValue, Vector2 shadowCasterCenter)
        {
            Vector3 UVOffset = new Vector3( 0.0f, -0.5f, 0.0f );

            // Transform the light position into model space
            Vector2 lightPos = Vector2.TransformCoordinate( lightPosWS, Matrix.Invert( worldMatrix ) );

            List<Edge> contourEdges = new List<Edge>();

            for ( int edgeIndex = 0; edgeIndex < polygonGeometry.NumEdges; ++edgeIndex )
            {
                Edge edge = polygonGeometry.GetEdge( edgeIndex );
                Vector2 edgeCenter = ( edge.Vertex1Pos + edge.Vertex2Pos ) * 0.5f;
                Vector2 incidentLightDir = edgeCenter - lightPos;

                // If the edge faces away from the light source
                if ( Vector2.Dot( incidentLightDir, edge.Normal ) >= 0.0f )
                {
                    contourEdges.Add( edge );
                }
            }

            if ( contourEdges.Count < 1 || contourEdges.Count == polygonGeometry.NumEdges )
            {
                return;
            }

            const float ExtrudeMagnitude = 1280;

            Shadow shadow = new Shadow();

            Vector3 lightPosVec3 = new Vector3( lightPos.X, lightPos.Y, zValue );
            lightPosVec3.TransformCoordinate( worldMatrix );

            int quadIndex = 0;
            foreach ( Edge edge in contourEdges )
            {
                Vector3 vertex1 = new Vector3(
                    edge.Vertex1Pos.X, edge.Vertex1Pos.Y, zValue );
                Vector3 vertex2 = new Vector3(
                    edge.Vertex2Pos.X, edge.Vertex2Pos.Y, zValue );

                // Transform the position data from model space to world space
                vertex1.TransformCoordinate( worldMatrix );
                vertex2.TransformCoordinate( worldMatrix );

                Quad quad = new Quad();
                Color shadowColor = Color.FromArgb( 1, 0, 0, 0 );

                quad.Vertices[ 2 * quadIndex + 0 ].Position = vertex1 + UVOffset -
                    18.0f * Vector3.Normalize( vertex1 - lightPosVec3 );
                quad.Vertices[ 2 * quadIndex + 0 ].Color = shadowColor.ToArgb();

                quad.Vertices[ 2 * quadIndex + 1 ].Position = vertex1 + ExtrudeMagnitude * ( vertex1 - lightPosVec3 )
                     + UVOffset;
                quad.Vertices[ 2 * quadIndex + 1 ].Color = shadowColor.ToArgb();

                quad.Vertices[ 2 * quadIndex + 2 ].Position = vertex2 + UVOffset -
                    18.0f * Vector3.Normalize( vertex2 - lightPosVec3 );
                quad.Vertices[ 2 * quadIndex + 2 ].Color = shadowColor.ToArgb();

                quad.Vertices[ 2 * quadIndex + 3 ].Position = vertex2 + ExtrudeMagnitude * ( vertex2 - lightPosVec3 )
                    + UVOffset;
                quad.Vertices[ 2 * quadIndex + 3 ].Color = shadowColor.ToArgb();

                shadow.Quads.Add( quad );
            }

            shadows.Add( shadow );
        }
        /// <summary>
        /// Executes the command. 
        /// Copies the selected Items in a series around a given rotation axis.
        /// </summary>
        /// <param name="services">CommandServices object to interact with the system</param>
        public override void Run(Canguro.Controller.CommandServices services)
        {
            Dictionary<Joint, Joint> joints = new Dictionary<Joint, Joint>();
            Dictionary<Joint, Joint> jSelection = new Dictionary<Joint, Joint>();
            List<LineElement> lines = new List<LineElement>();
            List<LineElement> lSelection = new List<LineElement>();
            List<AreaElement> areas = new List<AreaElement>();
            List<AreaElement> aSelection = new List<AreaElement>();
            ItemList<Joint> jList = services.Model.JointList;
            ItemList<LineElement> lList = services.Model.LineList;
            ItemList<AreaElement> aList = services.Model.AreaList;
            Joint nJoint;
            LineElement nLine;
            AreaElement nArea;

            List<Item> selection = services.GetSelection();
            if (selection.Count == 0)
                return;

            foreach (Item item in selection)
            {
                if (item is Joint)
                {
                    jSelection.Add((Joint)item, null);
                    joints.Add((Joint)item, null);
                }
                else if (item is LineElement)
                {
                    LineElement l = (LineElement)item;
                    lSelection.Add(l);
                    lines.Add(l);
                    if (!jSelection.ContainsKey(l.I))
                    {
                        jSelection.Add(l.I, null);
                        joints.Add(l.I, null);
                    }
                    if (!jSelection.ContainsKey(l.J))
                    {
                        jSelection.Add(l.J, null);
                        joints.Add(l.J, null);
                    }
                }
                else if (item is AreaElement)
                {
                    AreaElement a = (AreaElement)item;
                    aSelection.Add(a);
                    areas.Add(a);
                    if (!jSelection.ContainsKey(a.J1))
                    {
                        jSelection.Add(a.J1, null);
                        joints.Add(a.J1, null);
                    }
                    if (!jSelection.ContainsKey(a.J2))
                    {
                        jSelection.Add(a.J2, null);
                        joints.Add(a.J2, null);
                    }
                    if (!jSelection.ContainsKey(a.J3))
                    {
                        jSelection.Add(a.J3, null);
                        joints.Add(a.J3, null);
                    }
                    if (a.J4 != null && !jSelection.ContainsKey(a.J4))
                    {
                        jSelection.Add(a.J4, null);
                        joints.Add(a.J4, null);
                    }
                }
            }

            Microsoft.DirectX.Vector3 v, v2;
            uint n = (uint)services.GetSingle(Culture.Get("getArrayRepetition"));

            float dAngle = float.Parse(services.GetString(Culture.Get("getPolarArrayAngle")));
            dAngle *= (float)Math.PI / 180.0F;
            float angle = 0.0F;

            Controller.Snap.Magnet m = services.GetPoint(Culture.Get("getPolarRotationCenter"));
            if (m == null) return;
            v = m.SnapPosition;

            services.TrackingService = LineTrackingService.Instance;
            services.TrackingService.SetPoint(m.SnapPositionInt);

            m = services.GetPoint(Culture.Get("getPolarRotationCenter"));
            if (m == null) return;
            v2 = m.SnapPosition;
            if (v2.Equals(v))
            {
                Canguro.View.GraphicView view = Canguro.View.GraphicViewManager.Instance.ActiveView;
                Vector3 v1Tmp = new Vector3(0, 0, 0);
                Vector3 v2Tmp = new Vector3(0, 0, 1);
                view.Unproject(ref v1Tmp);
                view.Unproject(ref v2Tmp);
                v2 = v2 + v1Tmp - v2Tmp;
            }
            services.TrackingService = null;

            List<Joint> newJoints = new List<Joint>();
            List<LineElement> newLines = new List<LineElement>();
            List<AreaElement> newAreas = new List<AreaElement>();

            for (int i = 1; i <= n; i++)
            {
                angle += dAngle;

                Matrix trans1 = new Matrix();
                trans1.Translate(-v);
                Matrix rot = new Matrix();
                rot.RotateAxis(v2 - v, angle);
                Matrix trans2 = new Matrix();
                trans2.Translate(v);
                rot = trans1 * rot * trans2;

                foreach (Joint j in joints.Keys)
                {
                    Vector3 pos = new Vector3(j.X, j.Y, j.Z);
                    pos.TransformCoordinate(rot);

                    jList.Add(nJoint = new Joint(pos.X, pos.Y, pos.Z));
                    nJoint.Masses = j.Masses;
                    nJoint.DoF = j.DoF;
                    jSelection[j] = nJoint;
                    newJoints.Add(nJoint);
                }
                foreach (LineElement l in lines)
                {
                    lList.Add(nLine = new LineElement(l, jSelection[l.I], jSelection[l.J]));
                    newLines.Add(nLine);
                }
                foreach (AreaElement a in areas)
                {
                    aList.Add(nArea = new AreaElement(a, jSelection[a.J1], jSelection[a.J2], jSelection[a.J3], (a.J4 != null) ? jSelection[a.J4] : null));
                    newAreas.Add(nArea);
                }
            }
            JoinCmd.Join(services.Model, newJoints, newLines, newAreas);
        }
        public override bool IsSelectionBoxSelected(AnimatTools.Framework.MouseEventArgs AnimatMouseArgs)
        {
            if(this.m_mshCB == null && this.m_mshLB == null)
                return false;
            else if (this.m_bUBSelected || this.m_bLBSelected)
                return true;
            else
            {
                IntersectInformation iiInfo = new IntersectInformation();

                //matrix transormation of the world
                Vector3 tmp = new Vector3();
                tmp.TransformCoordinate(CombinedTransformationMatrix * Device.Transform.World1);

                Matrix mWorld = this.Device.Transform.View;
                mWorld.Invert();
                mWorld.M41 = tmp.X;
                mWorld.M42 = tmp.Y;
                mWorld.M43 = tmp.Z;

                if(Util_DX.TestIntersectWithMouse(m_mshCB,Device.Viewport, Device.Transform.Projection, Device.Transform.View, mWorld,AnimatMouseArgs.X, AnimatMouseArgs.Y, out iiInfo))
                    return true;

                mWorld.M41 = m_v3LB.X;
                mWorld.M42 = m_v3LB.Y;
                mWorld.M43 = m_v3LB.Z;

                if(Util_DX.TestIntersectWithMouse(m_mshLB,Device.Viewport, Device.Transform.Projection, Device.Transform.View, mWorld,AnimatMouseArgs.X, AnimatMouseArgs.Y, out iiInfo))
                    return true;

                return false;
            }
        }
Exemple #17
0
 /// <summary>
 /// Move an object or frame of an object forward in its current direction
 /// </summary>
 /// <param name="m">the transformation matrix</param>
 /// <param name="dist">distance to travel</param>
 public static void MoveForward(ref Matrix m, float dist)
 {
     // set up the distance as a vector (with movement along z)
     Vector3 v = new Vector3(0,0,dist);
     // Transform this vector by the world matrix, thus rotating it into the object's orientation and
     // then adding the object's initial location
     v.TransformCoordinate(m);
     // This is now the new location, so copy it into the matrix
     m.M41 = v.X;
     m.M42 = v.Y;
     m.M43 = v.Z;
 }
        public override void UpdateWithMouse(AnimatTools.Framework.MouseEventArgs AnimatMouseArgs)
        {
            IntersectInformation iiInfo = new IntersectInformation();

            //matrix transormation of the world
            Vector3 tmp = new Vector3();
            tmp.TransformCoordinate(CombinedTransformationMatrix * this.Device.Transform.World1);

            Matrix mWorld = this.Device.Transform.View;
            mWorld.Invert();
            mWorld.M41 = tmp.X;
            mWorld.M42 = tmp.Y;
            mWorld.M43 = tmp.Z;

            if(AnimatMouseArgs.Button == System.Windows.Forms.MouseButtons.None)
            {
                m_bUBSelected = false;
                m_bLBSelected = false;
                m_bSelectionBoxSelected = false;
                return;
            }

            //Did we click on the middle selection box?
            if(m_mshCB != null && Util_DX.TestIntersectWithMouse(m_mshCB,Device.Viewport, Device.Transform.Projection, Device.Transform.View, mWorld,AnimatMouseArgs.X, AnimatMouseArgs.Y, out iiInfo))
                m_bUBSelected = true;

            mWorld.M41 = m_v3LB.X;
            mWorld.M42 = m_v3LB.Y;
            mWorld.M43 = m_v3LB.Z;

            //Did we click on the lower selection box?
            if(m_mshLB != null && Util_DX.TestIntersectWithMouse(m_mshLB,Device.Viewport, Device.Transform.Projection, Device.Transform.View, mWorld,AnimatMouseArgs.X, AnimatMouseArgs.Y, out iiInfo))
                m_bLBSelected = true;

            if(m_bUBSelected && !m_bSelectionBoxSelected)
                ProcessCenterSquare(AnimatMouseArgs);
            else if(m_bLBSelected && !m_bSelectionBoxSelected)
                ProcessLowerSquare(AnimatMouseArgs);
            else
            {
                mWorld = CombinedTransformationMatrix  * this.Device.Transform.World1;

                if(!m_bSelectionBoxSelected && this.m_mshSelectedBoundingBox != null && Util_DX.TestIntersectWithMouse(this.m_mshSelectedBoundingBox,Device.Viewport, Device.Transform.Projection, Device.Transform.View, mWorld,AnimatMouseArgs.X, AnimatMouseArgs.Y, out iiInfo))
                {
                    m_bSelectionBoxSelected = true;
                    Vector3[] vertsFace = Util_DX.FindIntersectionFace(this.m_mshSelectedBoundingBox, iiInfo);
                    //the normal of the selected face
                    this.m_v3SBBN =  Util_DX.CalculateNormal(vertsFace);
                }

                if(m_bSelectionBoxSelected)
                    ProcessSelectedBoundingBox(AnimatMouseArgs, this.m_v3SBBN);
            }
        }
        public override void UpdateWithMouse(AnimatTools.Framework.MouseEventArgs AnimatMouseArgs)
        {
            //If no button is pressed..nothing is selected
            if(AnimatMouseArgs.Button == System.Windows.Forms.MouseButtons.None)
            {
                m_bCBSelected = false;
                m_bRBSelected = false;
                return;
            }

            IntersectInformation iiInfo = new IntersectInformation();
            Vector3 tmp = new Vector3();
            tmp.TransformCoordinate(CombinedTransformationMatrix * Device.Transform.World1);

            Matrix mWorld = this.Device.Transform.View;
            mWorld.Invert();
            mWorld.M41 = tmp.X;
            mWorld.M42 = tmp.Y;
            mWorld.M43 = tmp.Z;

            if(m_mshCB != null
                && !m_bRBSelected
                && Util_DX.TestIntersectWithMouse(m_mshCB, Device.Viewport, Device.Transform.Projection, Device.Transform.View, mWorld,AnimatMouseArgs.X, AnimatMouseArgs.Y, out iiInfo) && (AnimatMouseArgs.Button == System.Windows.Forms.MouseButtons.Left || AnimatMouseArgs.Button == System.Windows.Forms.MouseButtons.Right))
                m_bCBSelected = true;

            tmp = new Vector3();
            tmp.TransformCoordinate(Matrix.Translation(0,-Radius,0.06f) * this.CombinedTransformationMatrix * Device.Transform.World1);

            mWorld = this.Device.Transform.View;
            mWorld.Invert();
            mWorld.M41 = tmp.X;
            mWorld.M42 = tmp.Y;
            mWorld.M43 = tmp.Z;

            if(m_mshCB != null
                && !m_bCBSelected
                && Util_DX.TestIntersectWithMouse(m_mshCB, Device.Viewport, Device.Transform.Projection, Device.Transform.View, mWorld,AnimatMouseArgs.X, AnimatMouseArgs.Y, out iiInfo) && (AnimatMouseArgs.Button == System.Windows.Forms.MouseButtons.Left || AnimatMouseArgs.Button == System.Windows.Forms.MouseButtons.Right))
                m_bRBSelected = true;

            if(m_bCBSelected)
                ProcessCenterSquare(AnimatMouseArgs);
            else if(m_bRBSelected)
                ProcessRadius(AnimatMouseArgs);
        }
        //TODO:  Find what causes the graphics to freeze in this code
        protected void DrawLowerSelectionBox()
        {
            RigidBodies.RigidBody_DX rbParent = (RigidBodies.RigidBody_DX)this.Parent;
            //			Vector3 v3D = rbParent.RelativeLocation - this.RelativeLocation;
            //			v3D.Normalize();

            IntersectInformation iiInfo = new IntersectInformation();
            Vector3 v = new Vector3();
            v.TransformCoordinate(this.CombinedTransformationMatrix);
            this.m_mshSelectedBoundingBox.Intersect(rbParent.RelativeLocation, Direction, out iiInfo);

            m_v3LB = Util_DX.FindIntersectionPoint(this.m_mshSelectedBoundingBox,iiInfo);
            //m_v3LB = rbParent.FindPointOnSurface(new Vector3(), -Direction);
            m_v3LB.TransformCoordinate(CombinedTransformationMatrix * Device.Transform.World1);
            Matrix m = this.Device.Transform.View;
            m.Invert();
            m.M41 = m_v3LB.X;
            m.M42 = m_v3LB.Y;
            m.M43 = m_v3LB.Z;
            this.Device.Transform.World = m;
            this.Device.Material = Util_DX.WhiteMaterial();
            this.Device.RenderState.ZBufferEnable = false;
            Device.SetTexture(0,texLB);
            m_mshLB.DrawSubset(0);
            Device.SetTexture(0,null);
            this.Device.RenderState.ZBufferEnable = true;
        }
        public override void UpdateWithMouse(AnimatTools.Framework.MouseEventArgs AnimatMouseArgs)
        {
            //set the location of the upper box
            Vector3 tmp = new Vector3();
            tmp.TransformCoordinate(CombinedTransformationMatrix * Device.Transform.World1);

            Matrix mWorld = this.Device.Transform.View;
            mWorld.Invert();
            mWorld.M41 = tmp.X;
            mWorld.M42 = tmp.Y;
            mWorld.M43 = tmp.Z;

            if(AnimatMouseArgs.Button == System.Windows.Forms.MouseButtons.None)
            {
                m_bCBSelected = false;
                m_bLCBSelected = false;
                m_bUCBSelected = false;
                return;
            }
            IntersectInformation iiInfo = new IntersectInformation();
            if(m_mshCB != null &&
                !this.m_bLCBSelected && !this.m_bUCBSelected &&
                Util_DX.TestIntersectWithMouse(m_mshCB,Device.Viewport, Device.Transform.Projection, Device.Transform.View, mWorld,AnimatMouseArgs.X, AnimatMouseArgs.Y, out iiInfo) && (AnimatMouseArgs.Button == System.Windows.Forms.MouseButtons.Left || AnimatMouseArgs.Button == System.Windows.Forms.MouseButtons.Right))
                m_bCBSelected = true;

            //set the location of the upper box
            tmp =  new Vector3();
            tmp.TransformCoordinate(Matrix.Translation( -m_fRadius * 2, 0,0) * Matrix.RotationAxis(m_v3Axis ,-m_fltMinAngle) * this.CombinedTransformationMatrix * Device.Transform.World1);

            mWorld = this.Device.Transform.View;
            mWorld.Invert();
            mWorld.M41 = tmp.X;
            mWorld.M42 = tmp.Y;
            mWorld.M43 = tmp.Z;

            //Did we click on the lower constraint box?
            if(m_mshLCB != null &&
                !this.m_bCBSelected && !this.m_bUCBSelected  &&
                Util_DX.TestIntersectWithMouse(m_mshLCB,Device.Viewport, Device.Transform.Projection, Device.Transform.View, mWorld,AnimatMouseArgs.X, AnimatMouseArgs.Y, out iiInfo) && (AnimatMouseArgs.Button == System.Windows.Forms.MouseButtons.Left))
                m_bLCBSelected = true;

            //set the location of the upper box
            tmp =  new Vector3();
            tmp.TransformCoordinate(Matrix.Translation( -m_fRadius * 2, 0,0) * Matrix.RotationAxis(m_v3Axis ,-m_fltMaxAngle) * this.CombinedTransformationMatrix * Device.Transform.World1);

            mWorld = this.Device.Transform.View;
            mWorld.Invert();
            mWorld.M41 = tmp.X;
            mWorld.M42 = tmp.Y;
            mWorld.M43 = tmp.Z;

            if(m_mshUCB != null
                && !this.m_bLCBSelected && !this.m_bCBSelected
                && Util_DX.TestIntersectWithMouse(m_mshUCB,Device.Viewport, Device.Transform.Projection, Device.Transform.View, mWorld,AnimatMouseArgs.X, AnimatMouseArgs.Y, out iiInfo) && (AnimatMouseArgs.Button == System.Windows.Forms.MouseButtons.Left))
                m_bUCBSelected = true;

            if(m_bCBSelected)
                ProcessCenterSquare(AnimatMouseArgs);
            else if(m_bLCBSelected && (AnimatMouseArgs.Button == MouseButtons.Left))
                ProcessLowerConstraint(AnimatMouseArgs);
            else if(m_bUCBSelected && (AnimatMouseArgs.Button == MouseButtons.Left))
                ProcessUpperConstraint(AnimatMouseArgs);
        }
        public override void DrawBoundingBox()
        {
            if(m_mshSelectedBoundingBox != null)
            {
                if(texCB == null)
                {
                    try
                    {
                        System.Reflection.Assembly myAssembly = System.Reflection.Assembly.Load("VortexAnimatTools");
                        System.IO.Stream stream = myAssembly.GetManifestResourceStream("VortexAnimatTools.Graphics.ikpoint0.png");

                        //load the texture for the selection boxes
                        //texCB = TextureLoader.FromFile(Device,"VortexAnimatTools.ikpoint0.png");

                        //load texture from stream
                        texCB = TextureLoader.FromStream(Device,stream);

                    }
                    catch(Exception ex)
                    {
                        Util.DisplayError(ex);
                    }
                }

                Matrix mWorld = this.Device.Transform.World;
                //set the material for the selection box
                Device.Material = this.m_matTransparentSelectedMaterial;

                //set the world matrix
                this.Device.Transform.World = Matrix.Translation(0,0,0.045f) * this.CombinedTransformationMatrix * this.Device.Transform.World1;  //moves the body to where it is in space

                //draw the bounding box
                this.m_mshSelectedBoundingBox.DrawSubset(0);

                Vector3 tmp = new Vector3();
                tmp.TransformCoordinate(CombinedTransformationMatrix * Device.Transform.World1);

                Matrix m = this.Device.Transform.View;
                m.Invert();
                m.M41 = tmp.X;
                m.M42 = tmp.Y;
                m.M43 = tmp.Z;
                this.Device.Transform.World = m;
                this.Device.Material = Util_DX.WhiteMaterial();

                this.Device.RenderState.ZBufferEnable = false;
                Device.SetTexture(0,texCB);
                m_mshCB.DrawSubset(0);

                tmp = Vector3.Empty;
                tmp.TransformCoordinate(Matrix.Translation(0,-Radius,0.06f) * this.CombinedTransformationMatrix * Device.Transform.World1);

                m = this.Device.Transform.View;
                m.Invert();
                m.M41 = tmp.X;
                m.M42 = tmp.Y;
                m.M43 = tmp.Z;
                this.Device.Transform.World = m;

                m_mshCB.DrawSubset(0);
                Device.SetTexture(0,null);
                this.Device.RenderState.ZBufferEnable = true;
            }
        }
        public static Mesh CreateConeLimit(Microsoft.DirectX.Direct3D.Device d3dDevice, float fltHalfAngle, float fltHeight, int iSides)
        {
            Mesh mesh;
            AttributeRange ar = new AttributeRange();

            float fltRotAmnt = Geometry.DegreeToRadian(360.0f/iSides);

            //create indices
            short[] aryIndices = new short[iSides * 3];

            //create vertices
            CustomVertex.PositionNormal[] aryVerts = new CustomVertex.PositionNormal[iSides + 1];

            //create mesh with desired vertex format and desired size
            mesh = new Mesh(aryIndices.Length/3, aryVerts.Length, MeshFlags.SystemMemory, CustomVertex.PositionNormal.Format, d3dDevice);

            //caclulate the bottom radius vertices
            Vector3 v3Current = new Vector3(0, 0,0);
            aryVerts[0].Position = v3Current;

            v3Current.Z = fltHeight;
            v3Current.TransformCoordinate(Matrix.RotationX(fltHalfAngle));

            aryVerts[1].Position = v3Current;

            for(int i=2; i<iSides + 1; i++)
            {
                v3Current.TransformCoordinate(Matrix.RotationZ(fltRotAmnt));
                aryVerts[i].Position = v3Current;
            }

            //calculate the indices
            int j =0;
            for(int i=0; i<aryIndices.Length; i+=3)
            {
                //get first triangle
                aryIndices[i] = (short)(0);
                aryIndices[i+1] = (short)(j + 2);
                aryIndices[i+2] = (short)(j + 1);

                if(i == aryIndices.Length - 3)
                {
                    aryIndices[i] =	(short)(0);
                    aryIndices[i+1] = (short)(1);
                    aryIndices[i+2] = (short)(j + 1);

                    /*	TODO:  Remove when done
                    Debug.WriteLine("\nj = " + j.ToString());
                    Debug.WriteLine(aryIndices[i]);
                    Debug.WriteLine(aryIndices[i+1]);
                    Debug.WriteLine(aryIndices[i+2]);
                    Debug.WriteLine(aryIndices[i+3]);
                    Debug.WriteLine(aryIndices[i+4]);
                    Debug.WriteLine(aryIndices[i+5]);
                    */
                }
                j++;
            }

            //			aryIndices[0] = 0;
            //			aryIndices[1] = 2;
            //			aryIndices[2] = 1;
            //			aryIndices[3] = 0;
            //			aryIndices[4] = 3;
            //			aryIndices[5] = 2;
            //			aryIndices[6] = 0;
            //			aryIndices[7] = 4;
            //			aryIndices[8] = 3;
            //			aryIndices[9] = 0;
            //			aryIndices[10] = 1;
            //			aryIndices[11] = 4;

            ar.AttributeId = 0;
            ar.FaceStart = 0;
            ar.FaceCount = aryIndices.Length/3;
            ar.VertexStart = 0;
            ar.VertexCount = aryVerts.Length;

            //set the mesh
            mesh.VertexBuffer.SetData(aryVerts, 0, LockFlags.None);
            mesh.IndexBuffer.SetData(aryIndices, 0, LockFlags.None);
            mesh.SetAttributeTable(new AttributeRange[]{ar});

            mesh.ComputeNormals();

            return (mesh);
        }
        public override void DrawBoundingBox()
        {
            base.DrawBoundingBox();

            if(texConstraint == null)
            {
                try
                {
                    System.Reflection.Assembly myAssembly = System.Reflection.Assembly.Load("VortexAnimatTools");
                    System.IO.Stream stream = myAssembly.GetManifestResourceStream("VortexAnimatTools.Graphics.ikpoint.png");

                    //load the texture for the selection boxes
                    //texCB = TextureLoader.FromFile(Device,"VortexAnimatTools.ikpoint0.png");

                    //load texture from stream
                    texConstraint = TextureLoader.FromStream(Device,stream);

                }
                catch(Exception ex)
                {
                    Util.DisplayError(ex);
                }
            }

            this.Device.RenderState.ZBufferEnable = false;
            this.Device.Material = Util_DX.WhiteMaterial();

            Matrix mWorld = this.CombinedTransformationMatrix * Device.Transform.World1;

            //Matrix.Translation( m_fRadius, 0,0) *  * mWorld;
            Vector3 tmp =  new Vector3();
            tmp.TransformCoordinate(Matrix.Translation( -m_fRadius * 2, 0,0) * Matrix.RotationAxis(m_v3Axis ,-m_fltMinAngle) * mWorld);

            Matrix m = this.Device.Transform.View;
            m.Invert();

            m.M41 = tmp.X;
            m.M42 = tmp.Y;
            m.M43 = tmp.Z;

            this.Device.Transform.World = m;
            Device.SetTexture(0,texConstraint);
            this.m_mshLCB.DrawSubset(0);

            tmp =  new Vector3();
            tmp.TransformCoordinate(Matrix.Translation( -m_fRadius * 2, 0,0) * Matrix.RotationAxis(m_v3Axis ,-m_fltMaxAngle) * mWorld);
            m.M41 = tmp.X;
            m.M42 = tmp.Y;
            m.M43 = tmp.Z;

            this.Device.Transform.World = m;

            this.m_mshUCB.DrawSubset(0);
            Device.SetTexture(0,null);
            Device.RenderState.ZBufferEnable = true;
        }
Exemple #25
0
        /// <summary>
        /// Executes the command. 
        /// Moves the selected Item's Joints around a given point and with a given angle.
        /// </summary>
        /// <param name="services">CommandServices object to interact with the system</param>
        public override void Run(Canguro.Controller.CommandServices services)
        {
            Dictionary<Joint, Joint> joints = new Dictionary<Joint, Joint>();
            ItemList<Joint> jList = services.Model.JointList;
            ItemList<LineElement> lList = services.Model.LineList;

            List<Item> selection = services.GetSelection();
            if (selection.Count == 0)
                return;

            foreach (Item item in selection)
            {
                if (item is Joint)
                    joints.Add((Joint)item, null);
                else if (item is LineElement)
                {
                    LineElement l = (LineElement)item;
                    if (!joints.ContainsKey(l.I))
                        joints.Add(l.I, null);
                    if (!joints.ContainsKey(l.J))
                        joints.Add(l.J, null);
                }
            }

            Microsoft.DirectX.Vector3 v, v2;

            float angle = float.Parse(services.GetString(Culture.Get("getRotationAngle")));
            angle *= (float)Math.PI / 180.0F;
            Controller.Snap.Magnet m = services.GetPoint(Culture.Get("getRotationCenter"));
            if (m == null) return;

            v = m.SnapPosition;

            services.TrackingService = LineTrackingService.Instance;
            services.TrackingService.SetPoint(m.SnapPositionInt);

            m = services.GetPoint(Culture.Get("getPolarRotationCenter"));
            if (m == null) return;
            v2 = m.SnapPosition;
            if (v2.Equals(v))
            {
                Canguro.View.GraphicView view = Canguro.View.GraphicViewManager.Instance.ActiveView;
                Vector3 v1Tmp = new Vector3(0, 0, 0);
                Vector3 v2Tmp = new Vector3(0, 0, 1);
                view.Unproject(ref v1Tmp);
                view.Unproject(ref v2Tmp);
                v2 = v2 + v1Tmp - v2Tmp;
            }
            services.TrackingService = null;

            Matrix trans1 = new Matrix();
            trans1.Translate(-v);
            Matrix rot = new Matrix();
            rot.RotateAxis(v2 - v, angle);
            Matrix trans2 = new Matrix();
            trans2.Translate(v);

            rot = trans1 * rot * trans2;

            foreach (Joint j in joints.Keys)
            {
                Vector3 pos = new Vector3(j.X, j.Y, j.Z);

                pos.TransformCoordinate(rot);

                j.X = pos.X;
                j.Y = pos.Y;
                j.Z = pos.Z;
            }
        }
        private void DrawArc()
        {
            //Create the vertices that will represent each axis
            CustomVertex.PositionColored[] vertArc = new CustomVertex.PositionColored[36];

            Vector3 v3Current = new Vector3();
            v3Current.TransformCoordinate(Matrix.Translation( m_fRadius, 0,0) * Matrix.RotationAxis(m_v3Axis ,m_fltMinAngle));
            float fltRotationAmount = (float)((Math.Abs(this.m_fltMinAngle) + this.m_fltMaxAngle)/vertArc.Length);
            int intInterpolateAmount = 100/ vertArc.Length;

            for(int i=0; i<vertArc.Length; i++)
            {
                if(i%2 == 0)
                    vertArc[i].Position = new Vector3(v3Current.X, v3Current.Y, v3Current.Z + m_fRadius/2);
                else
                    vertArc[i].Position = new Vector3(v3Current.X, v3Current.Y, v3Current.Z - m_fRadius/2);
                v3Current.TransformCoordinate(Matrix.RotationAxis(m_v3Axis, fltRotationAmount));
                vertArc[i].Color = Color.FromArgb(255, (int)(255 * (float)((i * intInterpolateAmount)/100.0)), 0).ToArgb();

            }
                vertArc[vertArc.Length -1].Position = new Vector3(v3Current.X, v3Current.Y, v3Current.Z - m_fRadius/2);
                vertArc[vertArc.Length -1].Color = Color.Purple.ToArgb();

            Device.Transform.World = Matrix.RotationY(Geometry.DegreeToRadian(180)) * this.CombinedTransformationMatrix * Device.Transform.World1;

            //tell the device what kind of vertex format we're using
            this.Device.VertexFormat = CustomVertex.PositionColored.Format;

            //draw the lines
            this.Device.RenderState.Lighting = false;
            this.Device.DrawUserPrimitives(PrimitiveType.TriangleStrip,vertArc.Length - 2,vertArc);
            this.Device.RenderState.Lighting = true;
        }
        public override void UpdateWithMouse(AnimatTools.Framework.MouseEventArgs AnimatMouseArgs)
        {
            //If no button is pressed..nothing is selected
            if(AnimatMouseArgs.Button == System.Windows.Forms.MouseButtons.None)
            {
                m_bCBSelected = false;
                m_bMinSelected = false;
                m_bMaxSelected = false;
                return;
            }

            //set the location for the max constraint box
            Vector3 tmp = new Vector3();
            tmp.TransformCoordinate(Matrix.Translation(0, 0, -MaxMovement + m_fRadius) * CombinedTransformationMatrix * Device.Transform.World1);

            Matrix m = this.Device.Transform.View;
            m.Invert();
            m.M41 = tmp.X;
            m.M42 = tmp.Y;
            m.M43 = tmp.Z;

            IntersectInformation iiInfo = new IntersectInformation();
            if(m_mshCB != null && Util_DX.TestIntersectWithMouse(m_mshCB,Device.Viewport, Device.Transform.Projection, Device.Transform.View, m,AnimatMouseArgs.X, AnimatMouseArgs.Y, out iiInfo)
                && !m_bCBSelected && !m_bMinSelected
                && (AnimatMouseArgs.Button == System.Windows.Forms.MouseButtons.Left || AnimatMouseArgs.Button == System.Windows.Forms.MouseButtons.Right))
                m_bMaxSelected = true;

            //set the location for the min constraint box
            tmp = new Vector3();
            tmp.TransformCoordinate(Matrix.Translation(0, 0, -MinMovement - m_fRadius) * CombinedTransformationMatrix * Device.Transform.World1);

            m = this.Device.Transform.View;
            m.Invert();
            m.M41 = tmp.X;
            m.M42 = tmp.Y;
            m.M43 = tmp.Z;

            if(m_mshCB != null && Util_DX.TestIntersectWithMouse(m_mshCB,Device.Viewport, Device.Transform.Projection, Device.Transform.View, m,AnimatMouseArgs.X, AnimatMouseArgs.Y, out iiInfo)
                && !m_bCBSelected && !m_bMaxSelected
                && (AnimatMouseArgs.Button == System.Windows.Forms.MouseButtons.Left || AnimatMouseArgs.Button == System.Windows.Forms.MouseButtons.Right))
                m_bMinSelected = true;

            //set the location of the center box
            tmp = new Vector3();
            tmp.TransformCoordinate(CombinedTransformationMatrix * Device.Transform.World1);

            Matrix mWorld = this.Device.Transform.View;
            mWorld.Invert();
            mWorld.M41 = tmp.X;
            mWorld.M42 = tmp.Y;
            mWorld.M43 = tmp.Z;

            if(m_mshCB != null
                && !m_bMaxSelected && !m_bMinSelected
                && Util_DX.TestIntersectWithMouse(m_mshCB, Device.Viewport, Device.Transform.Projection, Device.Transform.View, mWorld,AnimatMouseArgs.X, AnimatMouseArgs.Y, out iiInfo) && (AnimatMouseArgs.Button == System.Windows.Forms.MouseButtons.Left || AnimatMouseArgs.Button == System.Windows.Forms.MouseButtons.Right))
                m_bCBSelected = true;

            if(m_bCBSelected)
                ProcessCenterSquare(AnimatMouseArgs);
            else if(m_bMaxSelected && (AnimatMouseArgs.Button == MouseButtons.Left))
                ProcessMaxSquare(AnimatMouseArgs);
            else if(m_bMinSelected && (AnimatMouseArgs.Button == MouseButtons.Left))
                ProcessMinSquare(AnimatMouseArgs);
        }
Exemple #28
0
 private void setupMatrices()
 {
     _device.Transform.World = Matrix.RotationY(0);
     Vector3 v1 = new Vector3(0.0f,0.0f,-5.0f);
     v1.TransformCoordinate(Matrix.RotationYawPitchRoll(angle, viewz, 0));
     _device.Transform.View = Matrix.LookAtLH(v1,new Vector3(0.0f,0.0f,0.0f),new Vector3(0.0f,1.0f,0.0f));
     _device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, 1.0f, 1.0f, 100.0f);
 }
        protected virtual void DrawSelectionBoxes()
        {
            //Max Movement
            Vector3 tmp = new Vector3();
            tmp.TransformCoordinate(Matrix.Translation(0, 0, -MaxMovement + m_fRadius) * CombinedTransformationMatrix * Device.Transform.World1);

            Matrix m = this.Device.Transform.View;
            m.Invert();
            m.M41 = tmp.X;
            m.M42 = tmp.Y;
            m.M43 = tmp.Z;
            this.Device.Transform.World = m;
            this.Device.Material = Util_DX.WhiteMaterial();

            this.Device.RenderState.ZBufferEnable = false;
            Device.SetTexture(0,texCB);
            m_mshCB.DrawSubset(0);
            Device.SetTexture(0,null);
            this.Device.RenderState.ZBufferEnable = true;

            //Min Movement
            tmp = new Vector3();
            tmp.TransformCoordinate(Matrix.Translation(0, 0, -MinMovement - m_fRadius) * CombinedTransformationMatrix * Device.Transform.World1);

            m = this.Device.Transform.View;
            m.Invert();
            m.M41 = tmp.X;
            m.M42 = tmp.Y;
            m.M43 = tmp.Z;
            this.Device.Transform.World = m;
            this.Device.Material = Util_DX.WhiteMaterial();

            this.Device.RenderState.ZBufferEnable = false;
            Device.SetTexture(0,texCB);
            m_mshCB.DrawSubset(0);
            Device.SetTexture(0,null);
            this.Device.RenderState.ZBufferEnable = true;
        }