示例#1
0
 public Editing3dRot(Editing3d editing3d)
 {
     this.editing3d = editing3d;
     selectionmodel = SelectionModel.GetInstance();
     camera         = Camera.GetInstance();
     graphics       = GraphicsHelperFactory.GetInstance();
 }
示例#2
0
        public void DrawWorld()
        {
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);

            Gl.glLoadIdentity();

            new GraphicsHelperGl().CheckError();
            if (PreDrawEvent != null)
            {
                PreDrawEvent();
            }
            new GraphicsHelperGl().CheckError();

            // note to self: move lighting to subscriber object?
            float[] ambientLight  = new float[] { 0.4f, 0.4f, 0.4f, 1.0f };
            float[] diffuseLight  = new float[] { 0.6f, 0.6f, 0.6f, 1.0f };
            float[] specularLight = new float[] { 0.2f, 0.2f, 0.2f, 1.0f };
            float[] position      = new float[] { -1.0f, 0.2f, -0.4f, 1.0f };

            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_AMBIENT, ambientLight);
            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_DIFFUSE, diffuseLight);
            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_SPECULAR, specularLight);
            Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_POSITION, position);

            Vector3 camerapos = Camera.GetInstance().CameraPos;

            new GraphicsHelperGl().CheckError();
            if (WriteNextFrameEvent != null)
            {
                //LogFile.WriteLine("writenextframe");
                WriteNextFrameEvent(camerapos);
            }

            new GraphicsHelperGl().CheckError();
            if (WriteAlpha != null)
            {
                WriteAlpha(camerapos);
            }
            new GraphicsHelperGl().CheckError();

            // rotate so z axis is up, and x axis is forward
            //Gl.glRotatef( 90f, 0.0f, 0.0f, 1.0f );
            //Gl.glRotatef( 90f, 0.0f, 1.0f, 0.0f );

            //Gl.glLightfv(Gl.GL_LIGHT0, Gl.GL_POSITION, new float[] { -100.5f, 100.0f, 100.0f, 1.0f });

            //     DEBUG(  "...disp done" ); // DEBUG
        }
        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);
        }
示例#4
0
        public PlayerMovement()
        {
            Test.Debug("instantiating PlayerMovement()");

            Config config = Config.GetInstance();

            //XmlElement minnode = (XmlElement)config.clientconfig.SelectSingleNode("worldboundingboxmin");
            //XmlElement maxnode =(XmlElement) config.clientconfig.SelectSingleNode("worldboundingboxmax");
            WorldBoundingBoxMin = new Vector3(0, 0, config.mingroundheight);
            WorldBoundingBoxMax = new Vector3(config.world_xsize, config.world_ysize, config.ceiling);
            Test.WriteOut(WorldBoundingBoxMin);
            Test.WriteOut(WorldBoundingBoxMax);

            XmlElement movementnode = (XmlElement)config.clientconfig.SelectSingleNode("movement");

            fAvatarAcceleration = Convert.ToDouble(movementnode.GetAttribute("acceleration"));
            fAvatarTurnSpeed    = Convert.ToDouble(movementnode.GetAttribute("turnspeed"));
            fAvatarMoveSpeed    = Convert.ToDouble(movementnode.GetAttribute("movespeed"));
            fVerticalMoveSpeed  = Convert.ToDouble(movementnode.GetAttribute("verticalmovespeed"));
            fDeceleration       = Convert.ToDouble(movementnode.GetAttribute("deceleration"));

            camera = Camera.GetInstance();
            //KeyFilterComboKeys keyfiltercombokeys = KeyFilterComboKeys.GetInstance();

            CommandCombos.GetInstance().RegisterAtLeastCommand(
                "moveleft", new KeyCommandHandler(MoveLeft));
            CommandCombos.GetInstance().RegisterAtLeastCommand(
                "moveright", new KeyCommandHandler(MoveRight));
            CommandCombos.GetInstance().RegisterAtLeastCommand(
                "movebackwards", new KeyCommandHandler(MoveBackwards));
            CommandCombos.GetInstance().RegisterAtLeastCommand(
                "moveforwards", new KeyCommandHandler(MoveForwards));
            CommandCombos.GetInstance().RegisterAtLeastCommand(
                "moveup", new KeyCommandHandler(MoveUp));
            CommandCombos.GetInstance().RegisterAtLeastCommand(
                "movedown", new KeyCommandHandler(MoveDown));

            ViewerState.GetInstance().StateChanged += new ViewerState.StateChangedHandler(PlayerMovement_StateChanged);
            MouseCache.GetInstance().MouseMove += new MouseMoveHandler(PlayerMovement_MouseMove);
            MetaverseClient.GetInstance().worldstorage.terrainmodel.TerrainModified += new TerrainModel.TerrainModifiedHandler(terrainmodel_TerrainModified);

            timekeeper = new TimeKeeper();

            Test.Debug("PlayerMovement instantiated");
        }
示例#5
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);
            }
        }
示例#6
0
        void SetupFrustrum()
        {
            //LogFile.WriteLine("setup frustrum");

            camerapos = Camera.GetInstance().CameraPos;
            camerarot = Camera.GetInstance().CameraRot;
            Rot inversecamerarot = camerarot.Inverse();

            //viewray = -mvMath.YAxis * inversecamerarot;
            //viewray.Normalize();
            //right = mvMath.XAxis * inversecamerarot;
            //up = mvMath.ZAxis * inversecamerarot;
            //right.Normalize();
            //up.Normalize();

            viewray = mvMath.XAxis * inversecamerarot;
            viewray.Normalize();
            right = -mvMath.YAxis * inversecamerarot;
            up    = mvMath.ZAxis * inversecamerarot;
            right.Normalize();
            up.Normalize();

            nearclip = RendererFactory.GetInstance().NearClip;
            farclip  = RendererFactory.GetInstance().FarClip;
            VNear    = 2 * Math.Tan(RendererFactory.GetInstance().FieldOfView / 2 * Math.PI / 180) * nearclip;
            VFar     = VNear * farclip / nearclip;
            HNear    = VNear * (double)RendererFactory.GetInstance().OuterWindowWidth / RendererFactory.GetInstance().OuterWindowHeight;
            HFar     = HNear * farclip / nearclip;

            //Console.WriteLine( "clips: " + nearclip + " " + farclip + " " + VNear + " " + VFar + " " + HNear + " " + HFar );

            fc  = camerapos + viewray * farclip;
            ftl = fc + (up * VFar / 2) - (right * HFar / 2);
            ftr = fc + (up * VFar / 2) + (right * HFar / 2);
            fbl = fc - (up * VFar / 2) - (right * HFar / 2);
            fbr = fc - (up * VFar / 2) + (right * HFar / 2);

            nc = camerapos + viewray * nearclip;

            ntl = nc + (up * VNear / 2) - (right * HNear / 2);
            ntr = nc + (up * VNear / 2) + (right * HNear / 2);
            nbl = nc - (up * VNear / 2) - (right * HNear / 2);
            nbr = nc - (up * VNear / 2) + (right * HNear / 2);

            // note: all normals point outwards
            planes[0] = new Plane(-viewray, nc);
            planes[1] = new Plane(viewray, fc);

            Vector3 vectoralongplane;
            Vector3 normal;

            vectoralongplane = (ntr - camerapos).Normalize();
            normal           = (up * vectoralongplane).Normalize();
            planes[2]        = new Plane(-normal, camerapos);

            vectoralongplane = (nbr - camerapos).Normalize();
            normal           = (right * vectoralongplane).Normalize();
            planes[3]        = new Plane(-normal, camerapos);

            vectoralongplane = (nbl - camerapos).Normalize();
            normal           = -(up * vectoralongplane).Normalize();
            planes[4]        = new Plane(-normal, camerapos);

            vectoralongplane = (ntl - camerapos).Normalize();
            normal           = -(right * vectoralongplane).Normalize();
            planes[5]        = new Plane(-normal, camerapos);
        }