-
Notifications
You must be signed in to change notification settings - Fork 3
/
Player.cpp
36 lines (26 loc) · 927 Bytes
/
Player.cpp
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
#include <osg/Geometry>
#include <osg/Geode>
#include "Player.hpp"
Player::Player() {}
Player::Player( float width, float height )
{
init( width, height);
}
bool Player::intersectsWith( Player* player ) const
{
osg::Vec3 pos = getMatrix().getTrans();
osg::Vec3 pos2 = player->getMatrix().getTrans();
return fabs(pos[0] - pos2[0]) < (width() + player->width()) * 0.5f &&
fabs(pos[1] - pos2[1]) < (height() + player->height()) * 0.5f;
}
void Player::init( float width, float height )
{
_size.set( width, height );
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
osg::ref_ptr<osg::Drawable> quad = osg::createTexturedQuadGeometry(
osg::Vec3(-width*0.5f, -height*0.5f, 0.0f),
osg::Vec3(width, 0.0f, 0.0f), osg::Vec3(0.0f, height, 0.0f) );
geode->addDrawable( quad.get() );
addChild( geode.get() );
_speedVec = osg::Vec3(0.0f, 0.0f, 0.0f);
}