示例#1
0
 public Editing3dRot(Editing3d editing3d)
 {
     this.editing3d = editing3d;
     selectionmodel = SelectionModel.GetInstance();
     camera         = Camera.GetInstance();
     graphics       = GraphicsHelperFactory.GetInstance();
 }
示例#2
0
        public Editing3dScale( Editing3d editing3d )
        {
            this.editing3d = editing3d;

            camera = Camera.GetInstance();
            graphics = GraphicsHelperFactory.GetInstance();
            selectionmodel = SelectionModel.GetInstance();
        }
示例#3
0
 public WorldView(WorldModel worldmodel)
 {
     LogFile.WriteLine("WorldView(" + worldmodel + ")");
     this.worldmodel = worldmodel;
     graphics        = GraphicsHelperFactory.GetInstance();
     terrainview     = new TerrainView(worldmodel.terrainmodel);
     RendererFactory.GetInstance().WriteNextFrameEvent += new WriteNextFrameCallback(WorldView_WriteNextFrameEvent);
 }
示例#4
0
 public WorldView( WorldModel worldmodel )
 {
     LogFile.WriteLine( "WorldView(" + worldmodel + ")" );
     this.worldmodel = worldmodel;
     graphics = GraphicsHelperFactory.GetInstance();
     terrainview = new TerrainView( worldmodel.terrainmodel );
     RendererFactory.GetInstance().WriteNextFrameEvent += new WriteNextFrameCallback(WorldView_WriteNextFrameEvent);
 }
示例#5
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);
        }
示例#6
0
        public void ApplyTransforms()
        {
            IGraphicsHelper graphics = GraphicsHelperFactory.GetInstance();

            if (Parent != null)
            {
                EntityGroup parententity = Parent as EntityGroup;
                parententity.ApplyTransforms();
            }
            graphics.Translate(pos);
            graphics.Rotate(rot);
        }
示例#7
0
        public void DrawEditBarsToOpenGL(Vector3 camerapos)
        {
            if (bShowEditBars)
            {
                Entity entity = selectionmodel.GetFirstSelectedEntity();
                if (entity == null)
                {
                    return;
                }

                IGraphicsHelper graphics = GraphicsHelperFactory.GetInstance();

                graphics.PushMatrix();

                if (entity.Parent == null)
                {
                    //entity.DrawSelected();
                }
                else
                {
                    (entity.Parent as EntityGroup).ApplyTransforms();
                }

                graphics.Translate(entity.pos);
                graphics.Rotate(entity.rot);

                // Vector3[] FaceCentreOffsets = new Vector3[6];

                double distance = (entity.pos - camerapos).Det();

                Vector3 ScaleToUse = entity.scale;

                switch (editbartype)
                {
                case EditBarType.Pos:
                    editing3dpos.DrawEditHandles(ScaleToUse, distance);
                    //editing3dscale.DrawEditHandles(ScaleToUse, distance);
                    break;

                case EditBarType.Scale:
                    editing3dscale.DrawEditHandles(ScaleToUse, distance);
                    break;

                case EditBarType.Rot:
                    editing3drot.DrawEditHandles(ScaleToUse);
                    break;
                }

                graphics.PopMatrix();
            }
        }
示例#8
0
        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();
        }
示例#9
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();
        }
示例#10
0
 void Init(Image image, bool isalpha)
 {
     this.isalpha = isalpha;
     g            = GraphicsHelperFactory.GetInstance();
     this.width   = image.Width;
     this.height  = image.Height;
     if (isalpha)
     {
         GlReference = LoadImageToOpenGlAsAlpha(image);
     }
     else
     {
         GlReference = LoadImageToOpenGl(image);
     }
 }
示例#11
0
        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();
        }
        public EntityCreationProperties(int screenx, int screeny)
        {
            LogFile.WriteLine("create entity screen pos : " + screenx + " " + screeny);

            IGraphicsHelper graphics = GraphicsHelperFactory.GetInstance();

            Camera  camera      = Camera.GetInstance();
            Vector3 mousevector = graphics.GetMouseVector(
                camera.CameraPos, camera.CameraRot, screenx, screeny);

            pos = camera.CameraPos + 3.0 * mousevector.Normalize();
            LogFile.WriteLine("mousevector: " + mousevector);

            rot   = new Rot();
            scale = new Vector3(1, 1, 1);
        }
示例#13
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();
        }
示例#14
0
 void Init(ImageWrapper image, bool isalpha)
 {
     this.isalpha = isalpha;
     g            = GraphicsHelperFactory.GetInstance();
     g.CheckError();
     CreateGlId();
     this.width  = image.Width;
     this.height = image.Height;
     if (isalpha)
     {
         LoadImageToOpenGlAsAlpha(image);
     }
     else
     {
         LoadImageToOpenGl(image);
     }
     g.CheckError();
     LogFile.WriteLine("GlTexture.Init id = " + GlReference);
 }
示例#15
0
        public override void Draw()
        {
            //Test.Debug("EntityGroup.Draw()");
            IGraphicsHelper graphics = GraphicsHelperFactory.GetInstance();
            //SelectionModel selectionmodel = SelectionModel.GetInstance();
            Picker3dController picker3dcontroller = Picker3dController.GetInstance();

            if (graphics == null)
            {
                return;
            }

            graphics.PushMatrix();
            graphics.Translate(pos);

            bool bNeedToPopMatrix   = false;
            bool bRotatedToGroupRot = false;

            //for( int iSubEntityRef = 0; iSubEntityRef < iNumSubEntities; iSubEntityRef++ )
            foreach (Entity child in children)
            {
                if (!bRotatedToGroupRot)
                {
                    // dont rotate first prim in elevation for avatars (looks better like this)
                    //if( strcmp( sDeepEntityType, "AVATAR" ) != 0 )
                    if (true)  // Just display all avatars as is for now( we should put this back in though probably)
                    {
                        graphics.Rotate(rot);
                        bRotatedToGroupRot = true;
                    }

                    picker3dcontroller.AddHitTarget(child);
                    child.Draw();
                }

                if (bNeedToPopMatrix)
                {
                    graphics.PopMatrix();
                }
            }
            graphics.PopMatrix();
        }
示例#16
0
        public void Render()
        {
            SelectionModel  selectionmodel = SelectionModel.GetInstance();
            IGraphicsHelper graphics       = GraphicsHelperFactory.GetInstance();

            for (int i = 0; i < selectionmodel.SelectedObjects.Count; i++)
            {
                Entity entity = selectionmodel.SelectedObjects[i];

                graphics.PushMatrix();

                if (entity.Parent != null)
                {
                    (entity as EntityGroup).ApplyTransforms();
                }

                entity.DrawSelected();
                graphics.PopMatrix();
            }
        }
示例#17
0
        public override void Draw()
        {
            //        Debug( "Avatar::DrawEx\n" );
            //      glPrint(avatarname); // Print GL Text To The Screen

            IGraphicsHelper graphics = GraphicsHelperFactory.GetInstance();

            if (graphics == null)
            {
                return;
            }

/*
 *          graphics.PushMatrix();
 *          graphics.RasterPos3f( pos.x, pos.y, pos.z + 0.8 );
 *          graphics.PrintText( name );
 *
 *          graphics.PopMatrix();
 */

            base.Draw();
        }
示例#18
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 );
        }
示例#19
0
 void Init(Image image, bool isalpha)
 {
     this.isalpha = isalpha;
         g = GraphicsHelperFactory.GetInstance();
         this.width = image.Width;
         this.height = image.Height;
         if (isalpha)
         {
             GlReference = LoadImageToOpenGlAsAlpha(image);
         }
         else
         {
             GlReference = LoadImageToOpenGl(image);
         }
 }
 public static void SetGraphicsHelper( IGraphicsHelper newinstance )
 {
     instance = newinstance;
 }
示例#21
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 );
        }
示例#22
0
 public static void SetGraphicsHelper(IGraphicsHelper newinstance)
 {
     instance = newinstance;
 }