Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Mar 16th, 2012  |  syntax: None  |  size: 2.23 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /* camera.h */
  2. #ifndef _CAMERA_H_
  3. #define _CAMERA_H_
  4.  
  5. #include <psptypes.h>
  6.  
  7. /* ____________________ S T R U C T S ____________________ */
  8. struct Camera
  9. {
  10.         float                   x, y, z;
  11.         float                   pitch, yaw;
  12.         ScePspFMatrix4  matrix;
  13. };
  14.  
  15. /* __________ P U B L I C  F U N C T I O N S __________ */
  16. void
  17. updateCamera(float a_x, float a_y, float a_z, float a_pitch, float a_yaw);
  18.  
  19. ScePspFMatrix4
  20. getCamMatrix(void);
  21.  
  22. #endif
  23.  
  24. /* camera.c */
  25. #include <stdio.h>
  26. #include <malloc.h>
  27. #include <math.h>
  28. #include <pspgu.h>
  29. #include <pspgum.h>
  30. #include "camera.h"
  31.  
  32. static struct Camera camera;
  33.  
  34. void
  35. updateCamera(float a_x, float a_y, float a_z, float a_pitch, float a_yaw)
  36. {
  37.         camera.x = a_x;
  38.         camera.y = a_y;
  39.         camera.z = a_z;
  40.        
  41.         camera.pitch = a_pitch;
  42.         camera.yaw = a_yaw;
  43.        
  44.         /* update camera matrix */
  45.         ScePspFMatrix4 pitch, yaw, translate, result;
  46.         /* rotation about x-axis */
  47.         pitch.x.x = 1.0f;
  48.         pitch.x.y = 0.0f;
  49.         pitch.x.z = 0.0f;
  50.         pitch.x.w = 0.0f;
  51.        
  52.         pitch.y.x = 0.0f;
  53.         pitch.y.y = cosf(camera.pitch);
  54.         pitch.y.z = -sinf(camera.pitch);
  55.         pitch.y.w = 0.0f;
  56.        
  57.         pitch.z.x = 0.0f;
  58.         pitch.z.y = sinf(camera.pitch);
  59.         pitch.z.z = cosf(camera.pitch);
  60.         pitch.z.w = 0.0f;
  61.        
  62.         pitch.w.x = 0.0f;
  63.         pitch.w.y = 0.0f;
  64.         pitch.w.z = 0.0f;
  65.         pitch.w.w = 1.0f;
  66.        
  67.         /* rotation about y-axis */
  68.         yaw.x.x = cosf(camera.yaw);
  69.         yaw.x.y = 0.0f;
  70.         yaw.x.z = -sinf(camera.yaw);
  71.         yaw.x.w = 0.0f;
  72.        
  73.         yaw.y.x = 0.0f;
  74.         yaw.y.y = 1.0f;
  75.         yaw.y.z = 0.0f;
  76.         yaw.y.w = 0.0f;
  77.        
  78.         yaw.z.x = -sinf(camera.yaw);
  79.         yaw.z.y = 0.0f;
  80.         yaw.z.z = cosf(camera.yaw);
  81.         yaw.z.w = 0.0f;
  82.        
  83.         yaw.w.x = 0.0f;
  84.         yaw.w.y = 0.0f;
  85.         yaw.w.z = 0.0f;
  86.         yaw.w.w = 1.0f;
  87.        
  88.         gumMultMatrix(&result, &pitch, &yaw);
  89.        
  90.         translate.x.x = 1.0f;
  91.         translate.x.y = 0.0f;
  92.         translate.x.z = 0.0f;
  93.         translate.x.w = 0.0f;
  94.        
  95.         translate.y.x = 0.0f;
  96.         translate.y.y = 1.0f;
  97.         translate.y.z = 0.0f;
  98.         translate.y.w = 0.0f;
  99.        
  100.         translate.z.x = 0.0f;
  101.         translate.z.y = 0.0f;
  102.         translate.z.z = 1.0f;
  103.         translate.z.w = 0.0f;
  104.        
  105.         translate.w.x = camera.x;
  106.         translate.w.y = camera.y;
  107.         translate.w.z = camera.z;
  108.         translate.w.w = 1.0f;
  109.        
  110.         gumMultMatrix(&result, &result, &translate);
  111.         gumLoadMatrix(&camera.matrix, &result);
  112. }
  113.  
  114. ScePspFMatrix4
  115. getCamMatrix(void)
  116. {
  117.         return camera.matrix;
  118. }