-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMOTION.cpp
More file actions
71 lines (50 loc) · 924 Bytes
/
Copy pathMOTION.cpp
File metadata and controls
71 lines (50 loc) · 924 Bytes
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <GL/glut.h>
#include <iostream>
#include "MOTION.h"
using namespace std;
MOTION::MOTION()
{
X=0; Y=0; Z=0;
theta=0;
ux=0; uz=1;
Speed=0;
Acc=30; Friction=20;
t=30;
}
void MOTION::UpdateVector()
{
ux=cos(theta*(3.14/180));
uz=sin(theta*(3.14/180));
}
void MOTION::FreeMotion()
{
X=X+(ux*Speed)*(t/1000);
Z=Z+(uz*Speed)*(t/1000);
if(Speed>0)
{
if(Speed<Friction*(t/1000))
Speed=0;
else
Speed=Speed-Friction*(t/1000);
}
if(Speed<0)
{
if(Speed>-Friction*(t/1000))
Speed=0;
else
Speed=Speed+Friction*(t/1000);
}
}
void MOTION::DrawVector()
{
glColor3f(0,1,0);
glLineWidth(10);
glBegin(GL_LINES);
glVertex3f(X,Y+7,Z);
glVertex3f(X+30*ux,Y+7,Z+30*uz);
glEnd();
glLineWidth(1);
}