Castle Battle  1.0
Public Member Functions | Public Attributes | List of all members
Ball Class Reference

Ball represent the projectile of the cannon. More...

#include <ball.h>

Public Member Functions

 Ball (IrrlichtDevice *device, scene::ISceneManager *smgr, video::IVideoDriver *driver, Physics *physics, core::vector3df position)
 Default constructor will instance both irrlicht and bullet objects at specified position. More...
 
 ~Ball ()
 
void setCamera (scene::ICameraSceneNode *camera, core::vector3df rotation=core::vector3df(0, 0, 0))
 Set camera to the ball, at specified rotation. More...
 
bool moveCamera ()
 Move camera,. More...
 
void deleteCamera ()
 Remove active camera and substitue with a parent camera. More...
 

Public Attributes

scene::ISceneManager * smgr
 
btRigidBody * btBall
 Bullet btRigitBody instance of the projectile. More...
 
scene::ISceneNode * irrBall
 Irrlicht instance of the projectile. More...
 
f32 radius = 0.3f
 Radius of the projectile. More...
 
core::vector3df cameraStartPosition
 Start position of the camera. More...
 
Cameracamera
 Camera of related to the ball. More...
 
IrrlichtDevice * device
 Irrlicht device. More...
 
scene::ICameraSceneNode * parentCamera
 Parent camera of the ball, in particular is the cannon camera. More...
 
core::array< core::vector3df > points
 Points of the ball while moving in air. More...
 

Detailed Description

Ball represent the projectile of the cannon.

Constructor & Destructor Documentation

◆ Ball()

Ball::Ball ( IrrlichtDevice *  device,
scene::ISceneManager *  smgr,
video::IVideoDriver *  driver,
Physics physics,
core::vector3df  position 
)

Default constructor will instance both irrlicht and bullet objects at specified position.

5  {
6  this->irrBall = smgr->addSphereSceneNode(this->radius,32,0,-1,position);
7  this->irrBall->setMaterialFlag(video::EMF_LIGHTING, false);
8  this->irrBall->setMaterialTexture(0,driver->getTexture("media/cannon/cannonballtex.png"));
9  this->btBall = physics->createCannonBall(this->irrBall,position, radius);
10  this->btBall->activate(true);
11  #if (DEBUG_OUTPUT_MASK & 2)
12  this->irrBall->setDebugDataVisible((scene::E_DEBUG_SCENE_TYPE)scene::EDS_BBOX_BUFFERS);
13  #endif
14  this->device = device;
15  this->smgr = smgr;
16 }
btRigidBody * createCannonBall(scene::ISceneNode *node, core::vector3df position, f32 radius)
Create the projectile physics instance.
Definition: physics.cpp:65
f32 radius
Radius of the projectile.
Definition: ball.h:21
IrrlichtDevice * device
Irrlicht device.
Definition: ball.h:27
scene::ISceneManager * smgr
Definition: ball.h:15
scene::ISceneNode * irrBall
Irrlicht instance of the projectile.
Definition: ball.h:19
btRigidBody * btBall
Bullet btRigitBody instance of the projectile.
Definition: ball.h:17

◆ ~Ball()

Ball::~Ball ( )
17  {
18 
19 }

Member Function Documentation

◆ deleteCamera()

void Ball::deleteCamera ( )

Remove active camera and substitue with a parent camera.

59  {
60  if(this->camera){
61 
62 // core::array<core::vector3df> p;
63 //
64 // core::vector3df position = this->camera->camera->getAbsolutePosition();
65 //
66 // p.push_front(position);
67 //
68 // for(int i = 0; i < 35; i++){
69 // position+=core::vector3df(0,0.314f,0);
70 // p.push_back(position);
71 // }
72 //
73 // scene::ISceneNodeAnimator* animator = this->smgr->createFollowSplineAnimator(this->device->getTimer()->getTime(), p,20.f,false);
74 // this->camera->camera->addAnimator(animator);
75 // animator->drop();
76  delete this->camera;
77  this->camera = 0;
78  assert(this->parentCamera != 0);
79  this->smgr->setActiveCamera(this->parentCamera);
80  }
81 }
scene::ICameraSceneNode * parentCamera
Parent camera of the ball, in particular is the cannon camera.
Definition: ball.h:32
scene::ISceneManager * smgr
Definition: ball.h:15
Camera * camera
Camera of related to the ball.
Definition: ball.h:25

◆ moveCamera()

bool Ball::moveCamera ( )

Move camera,.

See also
Cannon::moveCamera()
36  {
37  assert(this->camera != 0);
38  if(!this->camera){
39  return false;
40  }
41 
42  if(toIrrlichtVector(this->btBall->getLinearVelocity()) == core::vector3df(0,0,0) && this->camera){
43  this->deleteCamera();
44  return false;
45  }
46  int sig = sign(cos(this->parentCamera->getRotation().Y*core::DEGTORAD64));
47 
48  assert(this->camera->camera != 0);
49  core::vector3df diff = core::vector3df(
50  this->irrBall->getAbsolutePosition() - core::vector3df(0,-0.4f,sig*CAMERA_OFFSET_BALL));
51  this->camera->camera->setPosition(diff);
52  this->camera->camera->setTarget(this->irrBall->getAbsolutePosition());
53  this->irrBall->updateAbsolutePosition();
54  this->camera->camera->updateAbsolutePosition();
55 // this->points.push_front(this->camera->camera->getAbsolutePosition());
56  return true;
57 
58 }
scene::ICameraSceneNode * parentCamera
Parent camera of the ball, in particular is the cannon camera.
Definition: ball.h:32
const f32 CAMERA_OFFSET_BALL
Definition: ball.h:10
Camera * camera
Camera of related to the ball.
Definition: ball.h:25
scene::ICameraSceneNode * camera
Irrlicht ICameraSceneNode.
Definition: camera.h:12
scene::ISceneNode * irrBall
Irrlicht instance of the projectile.
Definition: ball.h:19
int sign(int x)
Get sign of a integer.
Definition: bullethelper.cpp:80
core::vector3df toIrrlichtVector(btVector3 vec)
Inverse of toBulletVector()
Definition: bullethelper.cpp:15
btRigidBody * btBall
Bullet btRigitBody instance of the projectile.
Definition: ball.h:17
void deleteCamera()
Remove active camera and substitue with a parent camera.
Definition: ball.cpp:59

◆ setCamera()

void Ball::setCamera ( scene::ICameraSceneNode *  camera,
core::vector3df  rotation = core::vector3df(0,0,0) 
)

Set camera to the ball, at specified rotation.

21  {
22  assert(camera != 0);
23  this->parentCamera = camera;
24  // camera->setPosition(this->irrBall->getAbsolutePosition());
25 
26  core::vector3df offset = this->cameraStartPosition = camera->getAbsolutePosition();
27  this->camera = new Camera(offset,rotation,this->smgr,0);
28  this->camera->camera->setTarget(rotation);
29  this->camera->camera->setRotation(rotation);
30  this->camera->camera->bindTargetAndRotation(true);
31 // this->camera = new Camera(camera,this->smgr);
32 
33 // this->points.push_front(camera->getAbsolutePosition());
34 
35 }
scene::ICameraSceneNode * parentCamera
Parent camera of the ball, in particular is the cannon camera.
Definition: ball.h:32
scene::ISceneManager * smgr
Definition: ball.h:15
Camera * camera
Camera of related to the ball.
Definition: ball.h:25
scene::ICameraSceneNode * camera
Irrlicht ICameraSceneNode.
Definition: camera.h:12
core::vector3df cameraStartPosition
Start position of the camera.
Definition: ball.h:23
Camera based on ICameraSceneNode of Irrlicht.
Definition: camera.h:6

Member Data Documentation

◆ btBall

btRigidBody* Ball::btBall

Bullet btRigitBody instance of the projectile.

◆ camera

Camera* Ball::camera

Camera of related to the ball.

See also
Camera

◆ cameraStartPosition

core::vector3df Ball::cameraStartPosition

Start position of the camera.

◆ device

IrrlichtDevice* Ball::device

Irrlicht device.

◆ irrBall

scene::ISceneNode* Ball::irrBall

Irrlicht instance of the projectile.

◆ parentCamera

scene::ICameraSceneNode* Ball::parentCamera

Parent camera of the ball, in particular is the cannon camera.

See also
Cannon
Cannon::moveCamera()

◆ points

core::array<core::vector3df> Ball::points

Points of the ball while moving in air.

It is used for a special effect. For now it is not used

◆ radius

f32 Ball::radius = 0.3f

Radius of the projectile.

◆ smgr

scene::ISceneManager* Ball::smgr

The documentation for this class was generated from the following files: