Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.98 KB | None | 0 0
  1. /**
  2.     Ps3ngine Camera header
  3. **/
  4.  
  5. #ifndef __CAMERA_INCLUDED
  6. #define __CAMERA_INCLUDED
  7.  
  8. #include <PSGL/psgl.h>
  9. #include <PSGL/psglu.h>
  10.  
  11. class Camera
  12. {
  13.     public:
  14.         void initCam();
  15.  
  16.         void setXrot(float);
  17.         void setYrot(float);
  18.         void setXpos(float);
  19.         void setYpos(float);
  20.         void setZpos(float);
  21.         void setAngle(float);
  22.  
  23.         float getXrot();
  24.         float getYrot();
  25.         float getXpos();
  26.         float getYpos();
  27.         float getZpos();
  28.         float getAngle();
  29.  
  30.         void updateCamera();
  31.  
  32.     private:
  33.         float xRotate;
  34.         float yRotate;
  35.         float xPos;
  36.         float yPos;
  37.         float zPos;
  38.         float Angle;
  39. };
  40.  
  41. #endif ///__CAMERA_INCLUDED
  42.  
  43. #include "Camera.hpp"
  44. void Camera::initCam()
  45. {
  46.     xRotate = 0;
  47.     yRotate = 0;
  48.     xPos = 0;
  49.     yPos = 0;
  50.     zPos = 0;
  51.     Angle = 0;
  52. }
  53.  
  54. void Camera::setXrot(float Val){xRotate = Val;}
  55. void Camera::setYrot(float Val){yRotate = Val;}
  56. void Camera::setXpos(float Val){xPos = Val;}
  57. void Camera::setYpos(float Val){yPos = Val;}
  58. void Camera::setZpos(float Val){zPos = Val;}
  59. void Camera::setAngle(float Val){Angle = Val;}
  60.  
  61. float Camera::getXrot(){return xRotate;}
  62. float Camera::getYrot(){return yRotate;}
  63. float Camera::getXpos(){return xPos;}
  64. float Camera::getYpos(){return yPos;}
  65. float Camera::getZpos(){return zPos;}
  66. float Camera::getAngle(){return Angle;}
  67.  
  68. void Camera::updateCamera()
  69. {
  70.     glRotatef(xRotate,1.0,0.0,0.0);
  71.     glRotatef(yRotate,0.0,1.0,0.0);
  72.     glTranslatef(-xPos,-yPos,-zPos);
  73. }
  74.  
  75. /**
  76.     Ps3ngine Control Input header
  77. **/
  78.  
  79. #ifndef __CONTROLS_INCLUDED
  80. #define __CONTROLS_INCLUDED
  81.  
  82. #include <cell/pad.h>
  83. static const int MAX_CON = 7;
  84.  
  85. enum cKeys
  86. {
  87.     JOY_RIGHT_X  = 4,
  88.     JOY_RIGHT_Y  = 5,
  89.     JOY_LEFT_X   = 6,
  90.     JOY_LEFT_Y   = 7,
  91.     PAD_RIGHT    = 8,
  92.     PAD_LEFT     = 9,
  93.     PAD_UP       = 10,
  94.     PAD_DOWN     = 11,
  95.     PAD_TRIANGLE = 12,
  96.     PAD_CIRCLE   = 13,
  97.     PAD_CROSS    = 14,
  98.     PAD_SQUARE   = 15,
  99.     PAD_L1       = 16,
  100.     PAD_R1       = 17,
  101.     PAD_L2       = 18,
  102.     PAD_R2       = 19,
  103.     SIXAXIS_X    = 20,
  104.     SIXAXIS_Y    = 21,
  105.     SIXAXIS_Z    = 22,
  106.     SIXAXIS_GYRO = 23
  107.  
  108. };
  109.  
  110. class Controller
  111. {
  112.     public:
  113.         ~Controller( void );
  114.         int initController( void );
  115.         int readPad( void );
  116.         bool readKey(const int, const int);
  117.         bool enableSixaxis(int);
  118.         bool disableSixaxis(int);
  119.  
  120.  
  121.         unsigned int rightJoyX(int);
  122.         unsigned int rightJoyY(int);
  123.         unsigned int leftJoyX(int);
  124.         unsigned int leftJoyY(int);
  125.         unsigned int sixaxisX(int);
  126.         unsigned int sixaxisY(int);
  127.         unsigned int sixaxisZ(int);
  128.         unsigned int sixaxisGyro(int);
  129.  
  130.     private:
  131.         CellPadInfo padInfo;
  132.         CellPadData padData[MAX_CON];
  133.         CellPadCapabilityInfo Capability[MAX_CON];
  134.         CellPadActParam actParam[MAX_CON];
  135.  
  136. };
  137.  
  138. #endif ///__CONTROLS_INCLUDED
  139.  
  140. #include "Controls.hpp"
  141.  
  142. Controller::~Controller( void )
  143. {
  144.     cellPadEnd();
  145. }
  146.  
  147. int Controller::initController( void )
  148. {
  149.     return cellPadInit(MAX_CON);
  150. }
  151.  
  152. int Controller::readPad( void )
  153. {
  154.     cellPadGetData(0, &padData[0]);
  155.     return (cellPadGetInfo(&padInfo));
  156. }
  157.  
  158. bool Controller::readKey(const int Pad, const int Key)
  159. {
  160.     if(Key > 7 && Key < 20)
  161.     {
  162.         return (padData[Pad].button[Key]);
  163.     }
  164.     return 0;
  165. }
  166.  
  167. bool Controller::enableSixaxis(int Pad)
  168. {
  169.     if(cellPadInfoSensorMode(Pad))
  170.     {
  171.         cellPadSetSensorMode(Pad, true);
  172.         return true;
  173.     }
  174.     return 0;
  175. }
  176.  
  177. bool Controller::disableSixaxis(int Pad)
  178. {
  179.     return cellPadSetSensorMode(Pad, false);
  180. }
  181.  
  182. unsigned int Controller::rightJoyX(int Pad){return (padData[Pad].button[JOY_RIGHT_X]);}
  183. unsigned int Controller::rightJoyY(int Pad){return (padData[Pad].button[JOY_RIGHT_Y]);}
  184. unsigned int Controller::leftJoyX(int Pad){return (padData[Pad].button[JOY_LEFT_X]);}
  185. unsigned int Controller::leftJoyY(int Pad){return (padData[Pad].button[JOY_LEFT_Y]);}
  186. unsigned int Controller::sixaxisX(int Pad){return (padData[Pad].button[SIXAXIS_X]);}
  187. unsigned int Controller::sixaxisY(int Pad){return (padData[Pad].button[SIXAXIS_Y]);}
  188. unsigned int Controller::sixaxisZ(int Pad){return (padData[Pad].button[SIXAXIS_Z]);}
  189. unsigned int Controller::sixaxisGyro(int Pad){return (padData[Pad].button[SIXAXIS_GYRO]);}
  190.  
  191. /**
  192.     Ps3ngine Rendering header
  193. **/
  194.  
  195. #ifndef __RENDERGLES_INCLUDED
  196. #define __RENDERGLES_INCLUDED
  197.  
  198. #include <sys/spu_initialize.h>
  199. #include <cell/sysmodule.h>
  200. #include <PSGL/psgl.h>
  201. #include <PSGL/psglu.h>
  202.  
  203. class Display
  204. {
  205.     public:
  206.         void initDisplay();
  207.         void clearDisplay( void );
  208.         void finalizeDisplay( void );
  209.         GLuint getScreenWidth( void );
  210.         GLuint getScreenHeight( void );
  211.         GLfloat getAspectRatio( void );
  212.  
  213.     private:
  214.         PSGLinitOptions Options;
  215.         PSGLdevice *Device;
  216.         PSGLcontext *Context;
  217.         GLuint screenWidth;
  218.         GLuint screenHeight;
  219.         GLfloat aspectRatio;
  220. };
  221.  
  222. #endif ///__RENDERGLES_INCLUDED
  223.  
  224. #include "RenderGLES.hpp"
  225.  
  226. void Display::initDisplay()
  227. {
  228.     sys_spu_initialize(6, 1);
  229.     screenWidth = 1280;
  230.     screenHeight = 720;
  231.     cellSysmoduleLoadModule(CELL_SYSMODULE_GCM_SYS);
  232.     cellSysmoduleLoadModule(CELL_SYSMODULE_FS);
  233.     cellSysmoduleLoadModule(CELL_SYSMODULE_USBD);
  234.     cellSysmoduleLoadModule(CELL_SYSMODULE_IO);
  235.     Options.enable = PSGL_INIT_MAX_SPUS | PSGL_INIT_INITIALIZE_SPUS;
  236.     Options.maxSPUs = 1;
  237.     Options.initializeSPUs = GL_FALSE;
  238.     Options.persistentMemorySize = 0,
  239.     Options.transientMemorySize = 0,
  240.     Options.errorConsole = 0,
  241.     Options.fifoSize = 256*1024,
  242.     Options.hostMemorySize = 128*1024*1024;
  243.     psglInit(&Options);
  244.     Device = psglCreateDeviceAuto(GL_ARGB_SCE,GL_DEPTH_COMPONENT24,GL_MULTISAMPLING_4X_SQUARE_ROTATED_SCE);
  245.     psglGetDeviceDimensions(Device, &screenWidth, &screenHeight);
  246.     aspectRatio = psglGetDeviceAspectRatio(Device);
  247.     Context = psglCreateContext();
  248.     psglMakeCurrent(Context, Device);
  249.     psglResetCurrentContext();
  250.  
  251.     glViewport(0, 0, screenWidth, screenHeight);
  252.     glScissor(0, 0, screenWidth, screenHeight);
  253.     glClearColor(0.0, 0.0, 0.0, 1.0);
  254.     glClearDepthf(1.0f);
  255.     glEnable(GL_DEPTH_TEST);
  256.  
  257.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
  258.     psglSwap();
  259. }
  260.  
  261. GLuint Display::getScreenWidth(void){return screenWidth;}
  262. GLuint Display::getScreenHeight(void){return screenHeight;}
  263. GLfloat Display::getAspectRatio(void){return aspectRatio;}
  264.  
  265. void Display::clearDisplay( void )
  266. {
  267.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
  268. }
  269.  
  270. void Display::finalizeDisplay( void )
  271. {
  272.     psglSwap();
  273. }
  274.  
  275. /**
  276.     Ps3ngine File IO header
  277. **/
  278.  
  279. #ifndef __FILEIO_INCLUDED
  280. #define __FILEIO_INCLUDED
  281.  
  282. class File
  283. {
  284.     public:
  285.         File(const char *, const char *);
  286.         bool Open(const char *, const char *);
  287.         int Print(char *, ...);
  288.         int Close( void );
  289.         int Read(void *, size_t, size_t);
  290.         int Write(const void *, size_t, size_t);
  291.         int Seek(long, int);
  292.         FILE *getFile( void );
  293.     private:
  294.         FILE *F;
  295. };
  296.  
  297. #endif //__FILEIO_INCLUDED
  298.  
  299. #include <stdio.h>
  300. #include "FileIO.hpp"
  301.  
  302. File::File(const char *FileName, const char *Mode)
  303. {
  304.     F = fopen(FileName, Mode);
  305. }
  306.  
  307. bool File::Open(const char *FileName, const char *Mode)
  308. {
  309.     F = fopen(FileName, Mode);
  310.     return !F;
  311. }
  312.  
  313. int File::Print(char *Format, ...)
  314. {
  315.     va_list Args;
  316.     char Buffer[BUFSIZ];
  317.  
  318.     va_start(Args, Format);
  319.     vsnprintf(Buffer, BUFSIZ, Format, Args);
  320.     va_end(Args);
  321.     return fprintf(F, Buffer);
  322. }
  323.  
  324. int File::Close(void)
  325. {
  326.     return fclose(F);
  327. }
  328.  
  329. int File::Read(void *Data, size_t Size, size_t Count)
  330. {
  331.     return fread(Data, Size, Count, F);
  332. }
  333.  
  334. int File::Write(const void *Data, size_t Size, size_t Count)
  335. {
  336.     return fwrite(Data, Size, Count, F);
  337. }
  338.  
  339. int File::Seek(long Offset, int Origin)
  340. {
  341.     return fseek(F, Offset, Origin);
  342. }
  343.  
  344. FILE *File::getFile( void )
  345. {
  346.     return F;
  347. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement