예제 #1
0
 public Editing3dRot(Editing3d editing3d)
 {
     this.editing3d = editing3d;
     selectionmodel = SelectionModel.GetInstance();
     camera         = Camera.GetInstance();
     graphics       = GraphicsHelperFactory.GetInstance();
 }
예제 #2
0
        void renderableminimap_Render(int minimapleft, int minimaptop, int minimapwidth, int minimapheight)
        {
            //Console.WriteLine("renderableminimap_Render");
            Vector3 intersectpoint = EditingHelper.GetIntersectPoint();

            if (intersectpoint != null)
            {
                Vector2 minimappos = new Vector2(intersectpoint.x * minimapwidth / MetaverseClient.GetInstance().worldstorage.terrainmodel.MapWidth,
                                                 intersectpoint.y * minimapheight / MetaverseClient.GetInstance().worldstorage.terrainmodel.MapHeight);

                //Console.WriteLine("minmappos: " + minimappos);
                //double distancefromcamera = (intersectpoint - camerapos).Det();
                GraphicsHelperFactory.GetInstance().SetMaterialColor(new Color(0, 0, 1));
                Gl.glPushMatrix();
                Gl.glDisable(Gl.GL_LIGHTING);
                Gl.glDisable(Gl.GL_CULL_FACE);
                Gl.glColor3ub(0, 0, 255);
                Gl.glBegin(Gl.GL_POINTS);
                Gl.glVertex2d(minimapleft + minimappos.x, minimaptop + minimappos.y);
                Gl.glEnd();
                Gl.glEnable(Gl.GL_CULL_FACE);
                Gl.glEnable(Gl.GL_LIGHTING);
                Gl.glColor3ub(255, 255, 255);
                //Gl.glTranslated(intersectpoint.x, intersectpoint.y, intersectpoint.z);
                //Gl.glScaled(0.01 * distancefromcamera, 0.01 * distancefromcamera, 0.01 * distancefromcamera);
                //GraphicsHelperFactory.GetInstance().DrawSphere();
                Gl.glPopMatrix();
            }
        }
예제 #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 void ApplyTransforms()
        {
            IGraphicsHelper graphics = GraphicsHelperFactory.GetInstance();

            if (Parent != null)
            {
                EntityGroup parententity = Parent as EntityGroup;
                parententity.ApplyTransforms();
            }
            graphics.Translate(pos);
            graphics.Rotate(rot);
        }
예제 #5
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();
            }
        }
예제 #6
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();
        }
예제 #7
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();
        }
예제 #8
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);
        }
예제 #10
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();
        }
예제 #11
0
        void renderer_WriteNextFrameEvent(Vector3 camerapos)
        {
            Gl.glPushMatrix();
            Gl.glBegin(Gl.GL_LINES);
            GraphicsHelperFactory.GetInstance().SetMaterialColor(new Color(1, 0, 0));
            Gl.glVertex3d(1, 1, 1);
            Gl.glVertex3d(10, 1, 1);

            GraphicsHelperFactory.GetInstance().SetMaterialColor(new Color(0, 1, 0));
            Gl.glVertex3d(1, 1, 1);
            Gl.glVertex3d(1, 10, 1);

            GraphicsHelperFactory.GetInstance().SetMaterialColor(new Color(0, 0, 1));
            Gl.glVertex3d(1, 1, 1);
            Gl.glVertex3d(1, 1, 10);
            Gl.glEnd();
            Gl.glPopMatrix();
        }
예제 #12
0
        void CurrentEditSpot_WriteNextFrameEvent(Vector3 camerapos)
        {
            if (ViewerState.GetInstance().CurrentViewerState != ViewerState.ViewerStateEnum.Terrain)
            {
                return;
            }
            Vector3 intersectpoint = EditingHelper.GetIntersectPoint();

            if (intersectpoint != null)
            {
                double distancefromcamera = (intersectpoint - camerapos).Det();
                GraphicsHelperFactory.GetInstance().SetMaterialColor(new Color(0, 0, 1));
                Gl.glPushMatrix();
                Gl.glTranslated(intersectpoint.x, intersectpoint.y, intersectpoint.z + 0.01 * distancefromcamera);
                Gl.glScaled(0.01 * distancefromcamera, 0.01 * distancefromcamera, 0.01 * distancefromcamera);
                GraphicsHelperFactory.GetInstance().DrawSphere();
                Gl.glPopMatrix();
            }
        }
예제 #13
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);
 }
예제 #14
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();
        }
예제 #15
0
        /// <summary>
        /// Return current mouse intersect point to x-y plane on map, in display coordinates
        /// </summary>
        /// <returns></returns>
        public static Vector3 GetIntersectPoint()
        {
            // intersect mousevector with x-z plane.
            TerrainModel terrain     = MetaverseClient.GetInstance().worldstorage.terrainmodel;
            Vector3      mousevector = GraphicsHelperFactory.GetInstance().GetMouseVector(
                Camera.GetInstance().CameraPos,
                Camera.GetInstance().CameraRot,
                MouseCache.GetInstance().MouseX,
                MouseCache.GetInstance().MouseY);
            Vector3 camerapos = Camera.GetInstance().CameraPos;
            int     width     = terrain.HeightMapWidth;
            int     height    = terrain.HeightMapHeight;

            //Vector3 planenormal = mvMath.ZAxis;
            mousevector.Normalize();
            if (mousevector.z < -0.0005)
            {
                //Vector3 intersectionpoint = camerapos + mousevector * (Vector3.DotProduct(camerapos, planenormal) + 0) /
                //  (Vector3.DotProduct(mousevector, planenormal));
                Vector3 intersectpoint = camerapos - mousevector * (camerapos.z / mousevector.z);
                //Console.WriteLine("intersection: " + intersectionpoint.ToString());
                double heightmapx = intersectpoint.x;
                double heightmapy = intersectpoint.y;
                if (heightmapx >= 0 && heightmapy >= 0 &&
                    heightmapx < width && heightmapy < height)
                {
                    intersectpoint.z = terrain.Map[(int)heightmapx, (int)heightmapy];
                    return(intersectpoint);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                //                Console.WriteLine("no intersection");
                return(null);
            }
        }
예제 #16
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();
        }
예제 #17
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 );
        }