Beispiel #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);
        }
Beispiel #2
0
 public override Point3D ColisionNormal(Point3D point, Point3D direction, double radius)
 {
     return(obj.ColisionNormal(point.Translated(-origin), direction, radius));
 }