Guest User

Untitled

a guest
Apr 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.49 KB | None | 0 0
  1. #include "ocean.h"
  2. #include <iostream>
  3. #include <math.h>
  4. using namespace std;
  5.  
  6. ocean::ocean() {
  7.     coords ocean_c = {.0, .0, .0, .0};
  8.     oc_speed = 0;
  9.     box = 10;
  10. }
  11.  
  12. ocean::ocean(coords oc_input, int box_in, float oc_speed_in) {
  13.     ocean_c = oc_input;
  14.     oc_speed = oc_speed_in;
  15.     box = box_in;
  16. }
  17.  
  18. coords ocean::coords_to_unit(coords temp) {
  19.     float lenght;
  20.     lenght = sqrt((temp.x * temp.x) + (temp.y * temp.y) + (temp.z * temp.z));
  21.  
  22.     if(lenght < 0.0) {
  23.         temp.x = temp.x/lenght;
  24.         temp.y = temp.y/lenght;
  25.         temp.z = temp.z/lenght;
  26.         temp.lenght = lenght;
  27.     }
  28.  
  29.     return temp;
  30. }
  31.  
  32. void ocean::change_ocean(coords temp) {
  33.     ocean_c = coords_to_unit(temp);
  34. }
  35.  
  36. void ocean::change_ocean_speed(float oc_speed_in) {
  37.     oc_speed = oc_speed_in;
  38. }
  39.  
  40. fish::fish() {
  41.     coords ocean_c = {.0, .0, .0, .0};
  42.     oc_speed = 0;
  43.     box = 10;
  44.     coords fish_c = {.0, .0, .0, .0};
  45.     coords fish_direction = {.0, .0, .0, .0};
  46.     fish_speed = 0;
  47. }
  48.  
  49. fish::fish(coords oc_input, int box_in, float oc_speed_in, coords fish_input, coords fish_directions_input, int fish_speed_in) {
  50.     ocean_c = oc_input;
  51.     oc_speed = oc_speed_in;
  52.     box = box_in;
  53.     fish_c = fish_input;
  54.     fish_direction = fish_directions_input;
  55.     fish_speed = fish_speed_in;
  56.  
  57.     ocean_c = coords_to_unit(ocean_c);
  58.     fish_direction = coords_to_unit(fish_direction);
  59. }
  60.  
  61. void fish::show_coordinates() {
  62.     cout << "Fish coordinates: " << fish_c.x << ", " << fish_c.y << ", " << fish_c.z << endl;
  63. }
  64.  
  65. void fish::move(float time) {
  66.     coords ocean_temp;
  67.     coords fish_temp;
  68.  
  69.     ocean_temp.x = oc_speed * ocean_c.x;
  70.     ocean_temp.y = oc_speed * ocean_c.y;
  71.     ocean_temp.z = oc_speed * ocean_c.z;
  72.  
  73.     fish_temp.x = fish_speed * fish_direction.x;
  74.     fish_temp.y = fish_speed * fish_direction.y;
  75.     fish_temp.z = fish_speed * fish_direction.z;
  76.  
  77.     fish_c.x = (time * (ocean_temp.x + fish_temp.x)) + fish_c.x;
  78.     fish_c.y = (time * (ocean_temp.y + fish_temp.y)) + fish_c.y;
  79.     fish_c.z = (time * (ocean_temp.z + fish_temp.z)) + fish_c.z;
  80. }
  81.  
  82. void fish::change_fish(coords temp) {
  83.     fish_direction = coords_to_unit(temp);
  84. }
  85.  
  86. void fish::change_fish_speed(int fish_speed_in) {
  87.     fish_speed = fish_speed_in;
  88. }
  89.    
  90. ostream &operator<<(ostream& s, fish& d) {
  91.     s << "===========FISH===========" << endl << "Coordinates: " << d.fish_c.x << ", " << d.fish_c.y << ", " << d.fish_c.z << endl << "Direction: "
  92.         << d.fish_direction.x << ", " << d.fish_direction.y << ", " << d.fish_direction.z << endl << "Speed: " << d.fish_speed << endl << "==========================" << endl << endl;
  93.  
  94.     return s;
  95. }
Add Comment
Please, Sign In to add comment