Beispiel #1
0
 private static Voxlap.point3d ToPoint3d(Voxlap.dpoint3d p)
 {
     return(new Voxlap.point3d()
     {
         x = (float)p.x,
         y = (float)p.y,
         z = (float)p.z,
     });
 }
Beispiel #2
0
        static void Main()
        {
            Sdl.SDL_Init(Sdl.SDL_INIT_VIDEO);

            g_pDisplaySurface = Sdl.SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, Sdl.SDL_DOUBLEBUF);
            g_DisplaySurface  = (Sdl.SDL_Surface)Marshal.PtrToStructure(g_pDisplaySurface, typeof(Sdl.SDL_Surface));

            Init();


            Sdl.SDL_ShowCursor(0);

            for (; ;)
            {
                if (Sdl.SDL_PollEvent(out g_Event) == 0)
                {
                    DoFrame();
                    Sdl.SDL_Flip(g_pDisplaySurface);

                    int forward = 0;
                    int strafe  = 0;

                    int    numkeys;
                    byte[] keys = Sdl.SDL_GetKeyState(out numkeys);
                    if (keys[Sdl.SDLK_w] != 0)
                    {
                        forward = 10;
                    }
                    if (keys[Sdl.SDLK_a] != 0)
                    {
                        strafe = -10;
                    }
                    if (keys[Sdl.SDLK_s] != 0)
                    {
                        forward = -10;
                    }
                    if (keys[Sdl.SDLK_d] != 0)
                    {
                        strafe = 10;
                    }

                    int  x, y;
                    byte state = Sdl.SDL_GetMouseState(out x, out y);

                    Voxlap.dpoint3d vec = new Voxlap.dpoint3d()
                    {
                        x = forward * or.ifo.x + strafe * or.ist.x,
                        y = forward * or.ifo.y + strafe * or.ist.y,
                        z = 0
                    };

                    or.ipo = Voxlap.ClipMove(or.ipo, vec, 8.0);

                    //or.ipo.x += forward * or.ifo.x;
                    //or.ipo.y += forward * or.ifo.y;

                    //or.ipo.x += strafe * or.ist.x;
                    //or.ipo.y += strafe * or.ist.y;
                }
                else
                {
                    if (g_Event.type == Sdl.SDL_MOUSEMOTION)
                    {
                        or.ifo = TodPoint3d(Voxlap.Rotate(
                                                ToPoint3d(or.ifo),
                                                new Voxlap.point3d()
                        {
                            z = 1
                        },
                                                (float)g_Event.motion.xrel / 100f));

                        or.ihe = TodPoint3d(Voxlap.Rotate(
                                                ToPoint3d(or.ihe),
                                                new Voxlap.point3d()
                        {
                            z = 1
                        },
                                                (float)g_Event.motion.xrel / 100f));

                        or.ist = TodPoint3d(Voxlap.Rotate(
                                                ToPoint3d(or.ist),
                                                new Voxlap.point3d()
                        {
                            z = 1
                        },
                                                (float)g_Event.motion.xrel / 100f));


                        float newangle = vertAngle + (float)-g_Event.motion.yrel / 100f;

                        if (newangle < Math.PI / 2 && newangle > -Math.PI / 2)
                        {
                            or.ifo = TodPoint3d(Voxlap.Rotate(
                                                    ToPoint3d(or.ifo),
                                                    ToPoint3d(or.ist),
                                                    (float)-g_Event.motion.yrel / 100f));

                            or.ihe = TodPoint3d(Voxlap.Rotate(
                                                    ToPoint3d(or.ihe),
                                                    ToPoint3d(or.ist),
                                                    (float)-g_Event.motion.yrel / 100f));

                            or.ist = TodPoint3d(Voxlap.Rotate(
                                                    ToPoint3d(or.ist),
                                                    ToPoint3d(or.ist),
                                                    (float)-g_Event.motion.yrel / 100f));

                            vertAngle = newangle;
                        }

                        Sdl.SDL_EventState(Sdl.SDL_MOUSEMOTION, Sdl.SDL_IGNORE);
                        Sdl.SDL_WarpMouse(SCREEN_WIDTH >> 1, SCREEN_HEIGHT >> 1);
                        Sdl.SDL_EventState(Sdl.SDL_MOUSEMOTION, Sdl.SDL_ENABLE);
                    }

                    if (g_Event.type == Sdl.SDL_MOUSEBUTTONDOWN)
                    {
                        if (g_Event.button.button == Sdl.SDL_BUTTON_WHEELUP)
                        {
                            or.ipo.z -= 10;
                        }

                        if (g_Event.button.button == Sdl.SDL_BUTTON_WHEELDOWN)
                        {
                            or.ipo.z += 10;
                        }
                    }

                    if (g_Event.type == Sdl.SDL_KEYDOWN)
                    {
                        if (g_Event.key.keysym.sym == Sdl.SDLK_ESCAPE)
                        {
                            break;
                        }
                    }

                    if (g_Event.type == Sdl.SDL_QUIT)
                    {
                        break;
                    }
                }
            }

            Sdl.SDL_Quit();
        }
Beispiel #3
0
        static void Main()
        {
            Sdl.SDL_Init(Sdl.SDL_INIT_VIDEO);

            g_pDisplaySurface = Sdl.SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32, Sdl.SDL_DOUBLEBUF);
            g_DisplaySurface = (Sdl.SDL_Surface)Marshal.PtrToStructure(g_pDisplaySurface, typeof(Sdl.SDL_Surface));

            Init();

            Sdl.SDL_ShowCursor(0);

            for (; ; )
            {
                if (Sdl.SDL_PollEvent(out g_Event) == 0)
                {
                    DoFrame();
                    Sdl.SDL_Flip(g_pDisplaySurface);

                    int forward = 0;
                    int strafe = 0;

                    int numkeys;
                    byte[] keys = Sdl.SDL_GetKeyState(out numkeys);
                    if (keys[Sdl.SDLK_w] != 0) { forward = 10; }
                    if (keys[Sdl.SDLK_a] != 0) { strafe = -10; }
                    if (keys[Sdl.SDLK_s] != 0) { forward = -10; }
                    if (keys[Sdl.SDLK_d] != 0) { strafe = 10; }

                    int x, y;
                    byte state = Sdl.SDL_GetMouseState(out x, out y);

                    Voxlap.dpoint3d vec = new Voxlap.dpoint3d()
                    {
                        x = forward * or.ifo.x + strafe * or.ist.x,
                        y = forward * or.ifo.y + strafe * or.ist.y,
                        z = 0
                    };

                    or.ipo = Voxlap.ClipMove(or.ipo, vec, 8.0);

                    //or.ipo.x += forward * or.ifo.x;
                    //or.ipo.y += forward * or.ifo.y;

                    //or.ipo.x += strafe * or.ist.x;
                    //or.ipo.y += strafe * or.ist.y;

                }
                else
                {
                    if (g_Event.type == Sdl.SDL_MOUSEMOTION)
                    {
                        or.ifo = TodPoint3d(Voxlap.Rotate(
                            ToPoint3d(or.ifo),
                            new Voxlap.point3d() { z = 1 },
                            (float)g_Event.motion.xrel / 100f));

                        or.ihe = TodPoint3d(Voxlap.Rotate(
                            ToPoint3d(or.ihe),
                            new Voxlap.point3d() { z = 1 },
                            (float)g_Event.motion.xrel / 100f));

                        or.ist = TodPoint3d(Voxlap.Rotate(
                            ToPoint3d(or.ist),
                            new Voxlap.point3d() { z = 1 },
                            (float)g_Event.motion.xrel / 100f));

                        float newangle = vertAngle + (float)-g_Event.motion.yrel / 100f;

                        if (newangle < Math.PI / 2 && newangle > -Math.PI / 2)
                        {
                            or.ifo = TodPoint3d(Voxlap.Rotate(
                                ToPoint3d(or.ifo),
                                ToPoint3d(or.ist),
                                (float)-g_Event.motion.yrel / 100f));

                            or.ihe = TodPoint3d(Voxlap.Rotate(
                                ToPoint3d(or.ihe),
                                ToPoint3d(or.ist),
                                (float)-g_Event.motion.yrel / 100f));

                            or.ist = TodPoint3d(Voxlap.Rotate(
                                ToPoint3d(or.ist),
                                ToPoint3d(or.ist),
                                (float)-g_Event.motion.yrel / 100f));

                            vertAngle = newangle;
                        }

                        Sdl.SDL_EventState(Sdl.SDL_MOUSEMOTION, Sdl.SDL_IGNORE);
                        Sdl.SDL_WarpMouse(SCREEN_WIDTH >> 1, SCREEN_HEIGHT >> 1);
                        Sdl.SDL_EventState(Sdl.SDL_MOUSEMOTION, Sdl.SDL_ENABLE);

                    }

                    if (g_Event.type == Sdl.SDL_MOUSEBUTTONDOWN)
                    {
                        if (g_Event.button.button == Sdl.SDL_BUTTON_WHEELUP)
                        {
                            or.ipo.z -= 10;
                        }

                        if (g_Event.button.button == Sdl.SDL_BUTTON_WHEELDOWN)
                        {
                            or.ipo.z += 10;
                        }
                    }

                    if (g_Event.type == Sdl.SDL_KEYDOWN)
                    {
                        if (g_Event.key.keysym.sym == Sdl.SDLK_ESCAPE)
                        {
                            break;
                        }
                    }

                    if (g_Event.type == Sdl.SDL_QUIT) break;

                }
            }

            Sdl.SDL_Quit();
        }