Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "SDL.h"
  4. #include <string.h>
  5. #include "drawline.h"
  6. #include "triangle.h"
  7. #include "object.h"
  8.  
  9.  
  10. // Create new object
  11. object_t *CreateObject(SDL_Surface *screen, triangle_t *model, int numtriangles)
  12. {
  13.  
  14. object_t *object;
  15. object = (object_t *)malloc(sizeof(object_t));
  16.  
  17. object->model = malloc(sizeof(triangle_t) * numtriangles);
  18. object->screen = screen;
  19. object->ttl = 5000;
  20. object->speedx = 1;
  21. object->speedy = 1;
  22. object->scale = 1;
  23. object->tx = 50;
  24. object->ty = 50;
  25. object->numtriangles = numtriangles;
  26. memcpy(object->model, model, sizeof(triangle_t) * numtriangles);
  27.  
  28. return object;
  29. }
  30.  
  31.  
  32. // Free memory used by object
  33. void DestroyObject(object_t *object)
  34. {
  35. free(object->model);
  36. free(object);
  37.  
  38. }
  39.  
  40.  
  41. // Draw object on screen
  42. void DrawObject(object_t *object)
  43. {
  44. int i;
  45. for (i = 0; i < object->numtriangles; i++){
  46. object->model[i].tx = object->tx;
  47. object->model[i].ty = object->ty;
  48. object->model[i].scale = object->scale;
  49. object->model[i].rotation = object->rotation;
  50.  
  51. DrawTriangle (object->screen, &object->model[i]);
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement