Beispiel #1
0
        public void DrawEditHandles(Vector3 entityscale)
        {
            // + x
            graphics.SetMaterialColor(editing3d.GetEditHandleColor(Axis.PosX));
            //graphics.SetMaterialColor( new double[]{ 1.0, 0.0, 0.0, 0.5 } );
            RendererFactory.GetPicker3dModel().AddHitTarget(new HitTargetEditHandle(Axis.PosX));
            graphics.PushMatrix();
            graphics.Scale(entityscale);
            graphics.Rotate(90f, 0f, 1f, 0f);
            DrawSelectionHandle();
            graphics.PopMatrix();

            // + y
            graphics.SetMaterialColor(editing3d.GetEditHandleColor(Axis.PosY));
            RendererFactory.GetPicker3dModel().AddHitTarget(new HitTargetEditHandle(Axis.PosY));
            graphics.PushMatrix();
            graphics.Scale(entityscale);
            graphics.Rotate(90, 1, 0, 0);
            DrawSelectionHandle();
            graphics.PopMatrix();

            // + z
            graphics.SetMaterialColor(editing3d.GetEditHandleColor(Axis.PosZ));
            RendererFactory.GetPicker3dModel().AddHitTarget(new HitTargetEditHandle(Axis.PosZ));
            graphics.PushMatrix();
            graphics.Scale(entityscale);
            //Gl.glRotatef( 90, 0, 1, 0 );
            DrawSelectionHandle();
            graphics.PopMatrix();
        }
Beispiel #2
0
        // for testing only
        void FrustrumCulling_WriteNextFrameEvent()
        {
            SetupFrustrum();

            IGraphicsHelper g = GraphicsHelperFactory.GetInstance();

            /*
             * g.SetMaterialColor(new Color(1, 1, 0));
             * Gl.glBegin(Gl.GL_LINES);
             * g.Vertex(camerapos + viewray * 0.51 + HNear / 2 * 0.95 * right + VNear / 2 * 0.95 * up);
             * g.Vertex(camerapos + viewray * 0.51 - HNear / 2 * 0.95 * right + VNear / 2 * 0.95 * up);
             * Gl.glEnd();
             * Gl.glBegin(Gl.GL_LINES);
             * g.Vertex(camerapos + viewray * 0.51 - HNear / 2 * 0.95 * right - VNear / 2 * 0.95 * up);
             * g.Vertex(camerapos + viewray * 0.51 + HNear / 2 * 0.95 * right - VNear / 2 * 0.95 * up);
             * Gl.glEnd();
             */

            g.SetMaterialColor(new Color(1, 0, 1));
            Gl.glBegin(Gl.GL_LINES);
            g.Vertex(camerapos + viewray * 1050 + HFar / 2 * 0.95 * right + VFar / 2 * 0.95 * up);
            g.Vertex(camerapos + viewray * 1050 - HFar / 2 * 0.95 * right + VFar / 2 * 0.95 * up);
            Gl.glEnd();
            Gl.glBegin(Gl.GL_LINES);
            g.Vertex(camerapos + viewray * 1050 - HFar / 2 * 0.95 * right - VFar / 2 * 0.95 * up);
            g.Vertex(camerapos + viewray * 1050 + HFar / 2 * 0.95 * right - VFar / 2 * 0.95 * up);
            Gl.glEnd();

            g.SetMaterialColor(new Color(1, 0, 0));
            Gl.glBegin(Gl.GL_LINES);
            g.Vertex(viewray * 10);
            g.Vertex(viewray * 100);
            Gl.glEnd();

            g.SetMaterialColor(new Color(0, 1, 0));
            Gl.glBegin(Gl.GL_LINES);
            g.Vertex(viewray * 10);
            g.Vertex(viewray * 10 + right * 100);
            Gl.glEnd();

            g.SetMaterialColor(new Color(0, 0, 1));
            Gl.glBegin(Gl.GL_LINES);
            g.Vertex(viewray * 10);
            g.Vertex(viewray * 10 + up * 100);
            Gl.glEnd();

            g.SetMaterialColor(new Color(0, 1, 1));
            for (int i = 0; i < 6; i++)
            {
                Gl.glBegin(Gl.GL_LINES);
                g.Vertex(planes[i].point + viewray * 100);
                g.Vertex(planes[i].point + planes[i].normalizednormal * 100 + viewray * 100);
                Gl.glEnd();
            }

            //Console.WriteLine( CheckObject(camerapos - 3 * viewray, 2) );
            //System.Environment.Exit(0);
        }
Beispiel #3
0
        void DrawSingleEditHandle(Vector3 entityscale, Vector3 handlescale, Axis handleaxis)
        {
            graphics.PushMatrix();

            graphics.SetMaterialColor(editing3d.GetEditHandleColor(handleaxis));
            RendererFactory.GetPicker3dModel().AddHitTarget(new HitTargetEditHandle(new Axis(handleaxis)));
            double fTranslateAmount = (handleaxis.GetAxisComponentIgnoreAxisDirection(entityscale) + handleaxis.GetAxisComponentIgnoreAxisDirection(handlescale)) / 2;

            graphics.Translate(fTranslateAmount * handleaxis.ToVector());
            graphics.Scale(handlescale);

            graphics.Rotate(handleaxis.ToRot());

            graphics.Rotate(90, 0, 1, 0);

            graphics.DrawCone();
            RendererFactory.GetPicker3dModel().EndHitTarget();
            graphics.PopMatrix();
        }
Beispiel #4
0
        public override void DrawSelected()
        {
            IGraphicsHelper graphics = GraphicsHelperFactory.GetInstance();

            graphics.SetMaterialColor(new Color(0.2, 0.7, 1.0));
            graphics.PushMatrix();
            graphics.Translate(pos);
            graphics.Rotate(rot);
            graphics.Scale(scale);

            graphics.DrawWireframeBox(10);

            graphics.PopMatrix();
        }
        public override void DrawSelected()
        {
            IGraphicsHelper graphics = GraphicsHelperFactory.GetInstance();

            graphics.SetMaterialColor(SelectionView.GetInstance().SelectionGridColor);
            graphics.PushMatrix();
            graphics.Translate(pos);
            graphics.Rotate(rot);
            graphics.Scale(scale);

            graphics.DrawWireframeBox(SelectionView.GetInstance().SelectionGridNumLines);

            graphics.PopMatrix();
        }
        public override void RenderSingleFace(int ifacenum)
        {
            IGraphicsHelper graphics = GraphicsHelperFactory.GetInstance();

            graphics.PushMatrix();

            graphics.SetMaterialColor(facecolors[0]);
            graphics.Translate(pos);
            graphics.Rotate(rot);
            graphics.Scale(scale);

            primitive.RenderSingleFace(ifacenum);

            graphics.PopMatrix();
        }
Beispiel #7
0
        public override void Draw()
        {
            // Test.Debug("cube draw");
            IGraphicsHelper graphics = GraphicsHelperFactory.GetInstance();

            graphics.PushMatrix();

            // Test.Debug( this.ToString() );
            graphics.SetMaterialColor(facecolors[0]);
            graphics.Translate(pos);
            graphics.Rotate(rot);
            graphics.Scale(scale);

            graphics.DrawCone();

            graphics.PopMatrix();
        }
Beispiel #8
0
        // The terrain rendering code is adapted from some example code in sdl or glut
        void renderer_WriteNextFrameEvent()
        {
            Gl.glPushMatrix();
            //Gl.glTranslatef(-MAXMESH / 2, MAXMESH * 2, 0);

            float[,] mesh = HeightMap.GetInstance().Map;
            int width  = HeightMap.GetInstance().Width;
            int height = HeightMap.GetInstance().Height;

            FrustrumCulling culling = FrustrumCulling.GetInstance();

            IGraphicsHelper g = GraphicsHelperFactory.GetInstance();

            iSectorsDrawn = 0;

            //Gl.glColor3ub(255, 255, 255);
            //g.SetMaterialColor(new Color(1, 0, 0));
            g.SetMaterialColor(new Color(0.3, 0.8, 0.3));
            for (int sectorx = 0; sectorx < (width / sectorsize) - 1; sectorx++)
            {
                for (int sectory = 0; sectory < (height / sectorsize) - 1; sectory++)
                {
                    //if (iSectorsDrawn == 0)
                    //{
                    int     sectorposx  = sectorx * sectorsize;
                    int     sectorposy  = sectory * sectorsize;
                    int     displayposx = sectorposx * SquareSize;
                    int     displayposy = sectorposy * SquareSize;
                    Vector3 sectorpos   = new Vector3(sectorposx, sectorposy, mesh[sectorposx, sectorposy]);
                    Vector3 displaypos  = new Vector3(displayposx, displayposy, mesh[sectorposx, sectorposy]);
                    if (culling.IsInsideFrustum(displaypos + new Vector3(sectorsize * SquareSize / 2, sectorsize * SquareSize / 2, 0), sectorsize * SquareSize))
                    {
                        iSectorsDrawn++;

                        // check how far away sector is
                        // if nearby we render it in detail
                        // otherwise just render a few points from it
                        double distancesquared = Vector3.DistanceSquared(displaypos, Camera.GetInstance().RoamingCameraPos);
                        //if ( distancesquared > detaildistance * detaildistance)
                        if (false)
                        {
                            g.SetMaterialColor(new Color(1, 0, 0));
                            Vector3 a = new Vector3(sectorsize * SquareSize, sectorsize * SquareSize,
                                                    mesh[sectorposx + sectorsize, sectorposy + sectorsize] -
                                                    mesh[sectorposx, sectorposy]);
                            Vector3 b = new Vector3(sectorsize * SquareSize, -sectorsize * SquareSize,
                                                    mesh[sectorposx + sectorsize, sectorposy] -
                                                    mesh[sectorposx, sectorposy + sectorsize]);

                            Vector3 normal = Vector3.CrossProduct(a, b).Normalize();
                            Gl.glNormal3d(normal.x, normal.y, normal.z);
                            Gl.glBegin(Gl.GL_TRIANGLE_STRIP);
                            Gl.glVertex3f(sectorposx * SquareSize, sectorposy * SquareSize, mesh[sectorposx, sectorposy]);
                            Gl.glVertex3f(sectorposx * SquareSize, sectorposy * SquareSize + sectorsize * SquareSize, mesh[sectorposx, sectorposy + sectorsize]);
                            Gl.glVertex3f(sectorposx * SquareSize + sectorsize * SquareSize, sectorposy * SquareSize, mesh[sectorposx + sectorsize, sectorposy]);
                            Gl.glVertex3f(sectorposx * SquareSize + sectorsize * SquareSize, sectorposy * SquareSize + sectorsize * SquareSize, mesh[sectorposx + sectorsize, sectorposy + sectorsize]);
                            Gl.glEnd();
                        }
                        else
                        {
                            int stepsize = 16;
                            if (distancesquared < 1200 * 1200)
                            {
                                stepsize = 1;
                            }
                            else if (distancesquared < 2400 * 2400)
                            {
                                stepsize = 2;
                            }
                            else if (distancesquared < 4000 * 4000)
                            {
                                stepsize = 4;
                            }
                            else if (distancesquared < 7200 * 7200)
                            {
                                stepsize = 8;
                            }
                            //else if (distancesquared < 1600 * 1600)
                            //{
                            //   stepsize = 16;
                            //}
                            if (colorlevelsofdetail)
                            {
                                g.SetMaterialColor(new Color(0, 0.5 + (float)stepsize * 8 / 255, 0));
                            }
                            DrawSubGrid(sectorposx, sectorposy, sectorsize, sectorsize, stepsize);
                        }
                    }
                    //}
                }
            }
            Gl.glPopMatrix();
            //Console.WriteLine( "sectors drawn: " + iSectorsDrawn );
        }
Beispiel #9
0
        // for testing only
        void FrustrumCulling_WriteNextFrameEvent(Vector3 camerapos)
        {
            SetupFrustrum();

            IGraphicsHelper g = GraphicsHelperFactory.GetInstance();

            g.SetMaterialColor(new Color(1, 1, 0));
            Gl.glBegin(Gl.GL_LINES);
            g.Vertex(camerapos + viewray * nearclip * 1.1 + HNear / 2 * 0.95 * right + VNear / 2 * 0.95 * up);
            g.Vertex(camerapos + viewray * nearclip * 1.1 - HNear / 2 * 0.95 * right + VNear / 2 * 0.95 * up);
            Gl.glEnd();
            Gl.glBegin(Gl.GL_LINES);
            g.Vertex(camerapos + viewray * nearclip * 1.1 - HNear / 2 * 0.95 * right - VNear / 2 * 0.95 * up);
            g.Vertex(camerapos + viewray * nearclip * 1.1 + HNear / 2 * 0.95 * right - VNear / 2 * 0.95 * up);
            Gl.glEnd();


            g.SetMaterialColor(new Color(1, 0, 1));
            Gl.glBegin(Gl.GL_LINES);
            g.Vertex(camerapos + viewray * farclip * 0.95 + HFar / 2 * 0.95 * right + VFar / 2 * 0.9 * up);
            g.Vertex(camerapos + viewray * farclip * 0.95 - HFar / 2 * 0.95 * right + VFar / 2 * 0.9 * up);
            Gl.glEnd();
            Gl.glBegin(Gl.GL_LINES);
            g.Vertex(camerapos + viewray * farclip * 0.95 - HFar / 2 * 0.95 * right - VFar / 2 * 0.9 * up);
            g.Vertex(camerapos + viewray * farclip * 0.95 + HFar / 2 * 0.95 * right - VFar / 2 * 0.9 * up);
            Gl.glEnd();

            /*
             * g.SetMaterialColor(new Color(1, 0, 0));
             * Gl.glBegin(Gl.GL_LINES);
             * g.Vertex(viewray * 10);
             * g.Vertex(viewray * 100);
             * Gl.glEnd();
             *
             * g.SetMaterialColor(new Color(0, 1, 0));
             * Gl.glBegin(Gl.GL_LINES);
             * g.Vertex(viewray * 10);
             * g.Vertex(viewray * 10 + right * 100);
             * Gl.glEnd();
             *
             * g.SetMaterialColor(new Color(0, 0, 1));
             * Gl.glBegin(Gl.GL_LINES);
             * g.Vertex(viewray * 10);
             * g.Vertex(viewray * 10 + up * 100);
             * Gl.glEnd();
             *
             * g.SetMaterialColor(new Color(0, 1, 1));
             * for (int i = 0; i < 6; i++)
             * {
             *  Gl.glBegin(Gl.GL_LINES);
             *  g.Vertex(planes[i].point + viewray * 100);
             *  g.Vertex(planes[i].point + planes[i].normalizednormal * 100 + viewray * 100);
             *  Gl.glEnd();
             * }
             */

            //Console.WriteLine( camerapos + " " + viewray );
            //Console.WriteLine( IsInsideFrustum( camerapos + viewray * nearclip * 1.5, 0 ) );
            //Console.WriteLine( IsInsideFrustum( camerapos + viewray * farclip * 0.9, 0 ) );
            //System.Environment.Exit( 0 );
        }