forked from yozlet/interface
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhand.cpp
More file actions
64 lines (54 loc) · 1.38 KB
/
Copy pathhand.cpp
File metadata and controls
64 lines (54 loc) · 1.38 KB
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
//
// hand.cpp
// interface
//
// Created by Philip Rosedale on 10/13/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#include "hand.h"
const float DEFAULT_X = 0.0;
const float DEFAULT_Y = 0.0;
const float DEFAULT_Z = -7.0;
Hand::Hand(float initradius, glm::vec3 initcolor)
{
color = initcolor;
radius = initradius;
reset();
noise = 0;
}
void Hand::render()
{
glEnable(GL_DEPTH_TEST);
glPushMatrix();
glLoadIdentity();
if (isColliding) glColor3f(1,0,0);
else glColor3f(color.x, color.y, color.z);
glBegin(GL_LINES);
glVertex3f(-0.05, -0.5, 0.0);
glVertex3f(position.x, position.y, position.z);
glVertex3f(0.05, -0.5, 0.0);
glVertex3f(position.x, position.y, position.z);
glEnd();
glTranslatef(position.x, position.y, position.z);
glutSolidSphere(radius, 15, 15);
glPopMatrix();
}
void Hand::reset()
{
position.x = DEFAULT_X;
position.y = DEFAULT_Y;
position.z = DEFAULT_Z;
velocity.x = velocity.y = velocity.z = 0;
isColliding = false;
}
void Hand::simulate(float deltaTime)
{
position += velocity*deltaTime;
velocity *= (1.f - 4.0*deltaTime);
if ((noise) && (randFloat() < 0.1))
{
velocity.x += (randFloat() - 0.5)*noise;
velocity.y += (randFloat() - 0.5)*noise;
velocity.z += (randFloat() - 0.5)*noise;
}
}