#include #include "mx3d_math.h" SDL_Surface *front = 0; void *buf = 0; mx3d::mxObject obj; mx3d::vec4D cam_pos(0,0,0,1), cam_dir(0,0,0,1), scale(5.0f,5.0f,5.0f,1), obj_pos(0,0,0,1), obj_rot(0,0,0,1); mx3d::Camera cam; mx3d::PipeLine graph; mx3d::RenderList rl; mx3d::Mat4D rotation_matrix; SDL_Joystick *stick = 0; void render(int screen) { SDL_FillRect(front, 0, 0); Uint8 *keys = SDL_GetKeyState(0); // mxhwnd.SetTicks(); rl.Reset(); obj.Reset(); float angle_x = 0, angle_y = 0, angle_z = 0; /* 0 Triangle 1 Circle 2 Cross 3 Square 4 Left trigger 5 Right trigger 6 Down 7 Left 8 Up 9 Right 10 Select 11 Start 12 Home 13 Hold */ /* mxhwnd.text.settextcolor(D3DCOLOR_XRGB(rand()%255,rand()%255,rand()%255)); mxhwnd.text.printtextf(10,10," Use Left to rotate +x Right to rotate -x\n Up to rotate +z Down to rotate-z\n Use W,A,S,D,Z,X to rotate camera position x,y,z"); */ if(SDL_JoystickGetButton(stick,7)||keys[SDLK_DOWN]) { angle_x = 1; } if(SDL_JoystickGetButton(stick, 9)) { angle_x = -1; } if(SDL_JoystickGetButton(stick, 8)) { angle_z = 1; } if(SDL_JoystickGetButton(stick, 6)) { angle_z = -1; } if(SDL_JoystickGetButton(stick, 0)) { cam.pos.z ++; } if(SDL_JoystickGetButton(stick, 1)) { cam.pos.z --; } if(SDL_JoystickGetButton(stick, 2)) { cam.pos.x++; } if(SDL_JoystickGetButton(stick, 3)) { cam.pos.x--; } if(SDL_JoystickGetButton(stick, 4)) { cam.pos.y++; } if(SDL_JoystickGetButton(stick, 5)) { cam.pos.y--; } rotation_matrix.BuildXYZ(angle_x,angle_y,angle_z); obj.TransformObject(rotation_matrix,0); // Model the Object to our world obj.ModelToWorld(); // Build Camera (Model Euler) Way ZYX cam.BuildEuler(5); obj.RemoveFaces(rotation_matrix,cam.pos); // World Cordinates to Camera Cordinates cam.WorldToCamera(obj); // Camera to Perspective cam.CameraToPerspective(obj); // Perspective to Screen cordinates cam.PerspectiveToScreen(obj); obj.BuildRenderList(rl); graph.Begin(); graph.DrawSolidPolys(rl); graph.End(); // mxhwnd.WaitTicks(5); } int init() { if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) return -1; front = SDL_SetVideoMode(480,272,0,0); max_clip_x = front->w; max_clip_y = front->h; stick = SDL_JoystickOpen(0); SDL_JoystickEventState(SDL_ENABLE); mx3d::BuildTables(); // init code here if(obj.LoadPLG("MXCUBE.PLG", scale, obj_pos, obj_rot)) { cam.Init(0,cam_pos,cam_dir,0,50.0f,500.0f,90.0f,float(front->w),float(front->h)); obj.world_pos.x = 0.0f; obj.world_pos.y = 0.0f; obj.world_pos.z = 100.0f; } else { printf("ERROR!"); exit(0); } return 0; } extern "C" int SDL_main(int argc, char **argv) { init(); SDL_Event e; int active = 1; while(active == 1) { SDL_FillRect(front, 0,0); render(0); SDL_UpdateRect(front, 0,0,front->w, front->h); if(SDL_PollEvent(&e)) { switch(e.type) { case SDL_QUIT: active = 0; break; } } } SDL_FreeSurface(front); SDL_JoystickClose(stick); SDL_Quit(); return 0; }