summaryrefslogtreecommitdiff
path: root/gaunt01/src/bird.cpp
blob: e27a2a27a35093551ac98c9d4c0443604ffe4413 (plain)
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
70
71
72
73
74
75
76
77
#include "bird.h"

/*
keep track of the high-level properties of the bird here

activate and control sequences of targets in the morphmesh

finally drawAnimated()

*/

bird::bird()
{
	if (model.loadMesh("Bird-poses.xml")) printf("mesh loaded with %i vertices, %i face indices, %i targets\n",model.getNumVertices(),model.getNumIndices(),model.getNumTargets());
	else printf("mesh XML file not parsed\n");

	if (model.loadSeqs("Bird-anim.xml")) printf("animation loaded with %i sequences\n",model.getNumSequences());
	else printf("animation XML file not parsed\n");

	model.sequences["flap"].start();
	currentseq="hover";

	texture.loadImage("TextureBird.jpg");

	//starting pos
	position=ofVec3f(ofGetWidth()/2,ofGetHeight(),-ofGetHeight()/4);
	heading=-90;
	direction=ofVec3f(0,-1,0); //director for a heading of 0, level
	velocity=ofGetWidth()/50;

	turnRate=20;
	diveRate=0;

	lastTime=ofGetElapsedTimef();
}

bird::~bird()
{
    //dtor
}

void bird::update(const vector<ofVec3f>& players){
	float time=ofGetElapsedTimef();
	float timeSeg=time-lastTime;
	lastTime=time;
	heading+=turnRate*timeSeg;

	position-=direction.rotated(heading,ofVec3f(0,0,-1))*velocity*timeSeg; //.rotate(heading,ofVec3f(0,1,0))
}
void bird::draw(){
	glEnable(GL_DEPTH_TEST);
	ofPushMatrix();
		ofTranslate(position);
		ofRotate(90,0,0,1);
		ofRotate(90,-1,0,0);
		ofRotate(heading+90,0,1,0);
		ofSetHexColor(0xffffff);
		ofScale(.15,.15,.15);
		bindTexture(texture);
            model.drawAnimated();
		unbindTexture(texture);
	ofPopMatrix();
	glDisable(GL_DEPTH_TEST);
}
void bird::drawShadow(){
    ofPushMatrix();
		ofTranslate(position);
		ofRotate(90,0,0,1);
		ofRotate(90,-1,0,0);
		ofRotate(heading+90,0,1,0);
        ofSetHexColor(0x000000);
        ofTranslate(0,(-ofGetHeight()/4)+5,0);
        ofScale(.15,0,.15);
        model.drawAnimated();
    ofPopMatrix();
}