File: Call_Move.cpp

package info (click to toggle)
atlas-cpp 0.5.98-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,652 kB
  • ctags: 2,284
  • sloc: sh: 8,305; cpp: 6,372; python: 1,471; makefile: 216
file content (48 lines) | stat: -rw-r--r-- 942 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "timer.h"
#include <iostream>

class NPC
{
public:
  NPC() {x=y=z = vx=vy=vz = 0.0;}
  void move(double new_vx, double new_vy, double new_vz,
            double &res_x, double &res_y, double &res_z,
            double &res_vx, double &res_vy, double &res_vz);
private:
  double x,y,z;
  double vx,vy,vz;
};

void NPC::move(double new_vx, double new_vy, double new_vz,
               double &res_x, double &res_y, double &res_z,
               double &res_vx, double &res_vy, double &res_vz)
{
  vx = new_vx;
  vy = new_vy;
  vz = new_vz;
  
  x += vx;
  y += vy;
  z += vz;

  res_x = x;
  res_y = y;
  res_z = z;

  res_vx = vx;
  res_vy = vy;
  res_vz = vz;
}

int main()
{
  double i;
  NPC npc1;
  double x,y,z, vx,vy,vz;
  TIME_ON;
  for(i=0; i<10000000.0; i+=1.0)
    npc1.move(i,i-1.0,i+1.0, x,y,z, vx,vy,vz);
  TIME_OFF("NPC movements");
  std::cout<<"Resulting position: ("<<x<<","<<y<<","<<z<<")"<<std::endl;
  return 0;
}