Пример #1
0
        protected void Update()         //mengambil input pergerakan
        {
            TimeSpan elapsed = DateTime.Now.Subtract(CurrentTime);

            CurrentTime = DateTime.Now;
            World.Prepare(this);
            if (!updating)
            {
                return;
            }
            double sx = 0;
            double sy = 0;
            double sz = 0;

            sx += PressedKeyRight?1:0;
            sx += PressedKeyLeft?-1:0;
            sy += PressedKeyUp?1:0;
            sy += PressedKeyDown?-1:0;
            sz += PressedKeyBackward?1:0;
            sz += PressedKeyForward?-1:0;

            this.strafeDir = new Point3D(sx, sy, sz);
            int xcenter = this.ViewPort.Width >> 1;
            int ycenter = this.ViewPort.Height >> 1;

            if (started)
            {
                WinApi.Point p = WinApi.GetCursorPos();
                camera.Pan((-p.x + xcenter) / 10f, (-p.y + ycenter) / 10f);
            }
            else
            {
                started = true;
            }
            Point3D moveDir        = camera.StrafeDir(this.strafeDir.Scaled(elapsed.TotalSeconds * this.StrafeSpeed));
            Point3D ColisionNormal = (ghostMode)?new Point3D(0, 0, 0):World.ColisionNormal(camera.Origin, moveDir, 30);

            if (ColisionNormal.Norm > 0)
            {
                moveDir       += ColisionNormal;
                ColisionNormal = World.ColisionNormal(camera.Origin, moveDir, 30);
            }
            //tembus tembok
            if (ColisionNormal.Norm < .5 && moveDir.Norm > 1)
            {
                camera.Translate(moveDir);
            }
            WinApi.SetCursorPos(xcenter, ycenter);
        }
Пример #2
0
 public override void Prepare(Avatar observer)
 {
     observer.Camera.Translate(-origin);
     obj.Prepare(observer);
     observer.Camera.Translate(origin);
 }