1
0

CAM.C 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /******************************************************************************
  2. Plush Version 1.2
  3. cam.c
  4. Camera Control
  5. Copyright (c) 1996-2000, Justin Frankel
  6. ******************************************************************************/
  7. #include "plush.h"
  8. void plCamDelete(pl_Cam *c) {
  9. if (c) free(c);
  10. }
  11. void plCamSetTarget(pl_Cam *c, pl_Float x, pl_Float y, pl_Float z) {
  12. double dx, dy, dz;
  13. dx = x - c->X;
  14. dy = y - c->Y;
  15. dz = z - c->Z;
  16. c->Roll = 0;
  17. if (dz > 0.0001f) {
  18. c->Pan = (pl_Float) (-atan(dx/dz)*(180.0/PL_PI));
  19. dz /= cos(c->Pan*(PL_PI/180.0));
  20. c->Pitch = (pl_Float) (atan(dy/dz)*(180.0/PL_PI));
  21. } else if (dz < -0.0001f) {
  22. c->Pan = (pl_Float) (180.0-atan(dx/dz)*(180.0/PL_PI));
  23. dz /= cos((c->Pan-180.0f)*(PL_PI/180.0));
  24. c->Pitch = (pl_Float) (-atan(dy/dz)*(180.0/PL_PI));
  25. } else {
  26. c->Pan = 0.0f;
  27. c->Pitch = -90.0f;
  28. }
  29. }
  30. pl_Cam *plCamCreate(pl_uInt sw, pl_uInt sh, pl_Float ar, pl_Float fov,
  31. pl_uChar *fb, pl_ZBuffer *zb) {
  32. pl_Cam *c;
  33. c = malloc(sizeof(pl_Cam));
  34. if (!c) return 0;
  35. memset(c,0,sizeof(pl_Cam));
  36. c->Fov = fov;
  37. c->AspectRatio = ar;
  38. c->ClipRight = c->ScreenWidth = sw;
  39. c->ClipBottom = c->ScreenHeight = sh;
  40. c->CenterX = sw>>1;
  41. c->CenterY = sh>>1;
  42. c->ClipBack = 8.0e30f;
  43. c->frameBuffer = fb;
  44. c->zBuffer = zb;
  45. c->Sort = 1;
  46. if (zb) c->Sort = 0;
  47. return (c);
  48. }