Ball is bouncing Quad. More...
#include <Ball.h>
Public Member Functions | |
| Ball () | |
| Ball (const Ball &) | |
| yes you can safely copy Ball! | |
| Ball * | Reincarnate () |
| Create child ball. | |
| void | Capture (Bongo *bong) |
| Catch bongo and control it's position. | |
| Ball () | |
| Ball (const Ball &) | |
| yes you can safely copy Ball! | |
| Ball * | Reincarnate () |
| Create child ball. | |
| void | Capture (Bongo *bong) |
| Catch bongo and control it's position. | |
Overloaded functions from Quad and Quad_impl | |
| bool | Init (XRes *resource, XCongo *xcongo) |
| Read Quad from resource file. | |
| bool | Display () |
| Draw itself in global cotext. Since quads are intented to be used with opengl, drawing context is global. | |
| const char * | ClassName () const |
| Used for RTTI. | |
| void | SetDirection (const double dir[3]) |
| This function first remebers last position and then calls Quad_impl::SetDirection. | |
| bool | Move (const double *forse) |
| When Ball is moved it will move captured Bongo as well. | |
| bool | Init (XRes *resource, XCongo *xcongo) |
| Read Quad from resource file. | |
| bool | Display () |
| Draw itself in global cotext. Since quads are intented to be used with opengl, drawing context is global. | |
| const char * | ClassName () const |
| Used for RTTI. | |
| void | SetDirection (const double dir[3]) |
| Set direction of moving. | |
| bool | Move (const double *forse) |
Private Attributes | |
| int | mLives |
| Number of times, ball will reincarnate before it is killed. | |
| double | mLastPos [3] |
| Last position is position when Ball changed direction last time. | |
| double | mSpeed |
| Speed of the Ball. | |
| Bongo * | mpBongo |
| Captured bongo. This is 0 most of the time. | |
| Ball::Ball | ( | ) |
| Ball::Ball | ( | const Ball & | ob | ) |
| Ball::Ball | ( | ) |
| Ball::Ball | ( | const Ball & | ) |
yes you can safely copy Ball!
| void Ball::Capture | ( | Bongo * | bong | ) |
Catch bongo and control it's position.
When bonog is killed it will be captured by the ball and bounce around. On the other side Ball will become transparent so bongo can still be visible to the user.
| bong | Captured Bongo. |
Definition at line 158 of file Ball.cpp.
References Quad_impl::mColor, mpBongo, Quad_impl::mSize, and Quad_impl::Size().
Referenced by CollisionMaster::Collision().
| void Ball::Capture | ( | Bongo * | bong | ) |
| const char* Ball::ClassName | ( | ) | const [virtual] |
| const char * Ball::ClassName | ( | ) | const [virtual] |
Used for RTTI.
Reimplemented from Quad_impl.
Definition at line 81 of file Ball.cpp.
Referenced by CollisionMaster::Collision().
{
return "Ball";
}
| bool Ball::Display | ( | ) | [virtual] |
Draw itself in global cotext. Since quads are intented to be used with opengl, drawing context is global.
Reimplemented from Quad_impl.
| bool Ball::Display | ( | ) | [virtual] |
Draw itself in global cotext. Since quads are intented to be used with opengl, drawing context is global.
Reimplemented from Quad_impl.
Definition at line 88 of file Ball.cpp.
References Quad_impl::mColor, mLastPos, Quad_impl::mPos, and Quad_impl::mSize.
{
glPushMatrix();
// enable blending only if ball is transparent
// this can only happend when Bongo is captured ...
if (mColor[3] < 1)
{
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
// set light and materal properties
GLfloat mat_specular[] = { mColor[0], mColor[1], mColor[2], mColor[3] };
GLfloat mat_shininess[] = { 50.0 };
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
// draw helper line from ball to the floor
glBegin(GL_LINES);
glVertex3f(mPos[0], 0.0, mPos[2]);
glVertex3f(mPos[0], mPos[1], mPos[2]);
glEnd();
// Draw helper line on the floor Y==0
glBegin(GL_LINES);
glVertex3f(mLastPos[0], 0.01, mLastPos[2]);
glVertex3f(mPos[0], 0.01, mPos[2]);
glEnd();
// Draw ball
glTranslatef(mPos[0], mPos[1], mPos[2]);
glutSolidSphere(mSize/2, int(mSize * 30), int(mSize * 22) ); /* draw sun */
// disable back blending if ball is transparent
if (mColor[3] < 1)
{
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
}
glPopMatrix();
return true;
}
| bool Ball::Init | ( | XRes * | resource, |
| XCongo * | xcongo | ||
| ) | [virtual] |
Read Quad from resource file.
| resource | Resource file contained description of Quad object. |
| xcongo | Global settings file contained parameters not specific to this quad. |
normalize direction
Reimplemented from Quad_impl.
Definition at line 31 of file Ball.cpp.
References XRes::DoubleValue(), XRes::IntValue(), Quad_impl::mColor, Quad_impl::mDirection, mLastPos, mLives, Quad_impl::mMass, Quad_impl::mPos, Quad_impl::mPower, Quad_impl::mSize, mSpeed, and vec_ofpow().
{
if (!resource->DoubleValue("mSize", &mSize) )
{
fprintf(stderr, "error: reading ball size\n");
return false;
}
if (!resource->DoubleValue("mPos.mX", &mPos[0])
|| !resource->DoubleValue("mPos.mY",&mPos[1])
|| !resource->DoubleValue("mPos.mZ", &mPos[2]))
{
fprintf(stderr, "error: reading ball position\n");
return false;
}
// set the last position to be current position
memcpy(mLastPos, mPos, sizeof(mLastPos) );
if (!resource->DoubleValue("mColor.red", &mColor[0])
|| !resource->DoubleValue("mColor.green",&mColor[1])
|| !resource->DoubleValue("mColor.blue", &mColor[2])
|| !resource->DoubleValue("mOpaque", &mColor[3]) )
{
fprintf(stderr, "error: reading ball color\n");
return false;
}
if (!resource->DoubleValue("mDirection.mX", &mDirection[0])
|| !resource->DoubleValue("mDirection.mY",&mDirection[1])
|| !resource->DoubleValue("mDirection.mZ", &mDirection[2])
|| !resource->DoubleValue("mPower", &mPower)
|| !resource->DoubleValue("mSpeed", &mSpeed) )
{
fprintf(stderr, "error: reading ball direction\n");
return false;
}
if (!resource->IntValue("mLives", &mLives) )
{
fprintf(stderr, "error: reading ball lives\n");
return false;
}
vec_ofpow(mDirection, mSpeed);
mMass = mSize * mSize * M_PI;
return true;
}
| bool Ball::Init | ( | XRes * | resource, |
| XCongo * | xcongo | ||
| ) | [virtual] |
| bool Ball::Move | ( | const double * | forse | ) |
When Ball is moved it will move captured Bongo as well.
Definition at line 166 of file Ball.cpp.
References Quad_impl::Move(), and mpBongo.
Referenced by CollisionMaster::Collision().
{
if (mpBongo)
mpBongo->Move(forse);
return Quad_impl::Move(forse);
}
| bool Ball::Move | ( | const double * | forse | ) |
| Ball * Ball::Reincarnate | ( | ) |
Create child ball.
Definition at line 143 of file Ball.cpp.
References Ball(), Bongo::Free(), Bongo::Lives(), mLives, mpBongo, and Bongo::SetLives().
Referenced by CollisionMaster::Collision().
| Ball* Ball::Reincarnate | ( | ) |
Create child ball.
| void Ball::SetDirection | ( | const double | dir[3] | ) | [virtual] |
Set direction of moving.
Reimplemented from Quad_impl.
| void Ball::SetDirection | ( | const double | dir[3] | ) | [virtual] |
This function first remebers last position and then calls Quad_impl::SetDirection.
Reimplemented from Quad_impl.
Definition at line 136 of file Ball.cpp.
References mLastPos, and Quad_impl::mPos.
Referenced by CollisionMaster::Collision().
{
memcpy(mLastPos, mPos, sizeof(mPos) );
Quad_impl::SetDirection(dir);
}
double Ball::mLastPos [private] |
int Ball::mLives [private] |
Number of times, ball will reincarnate before it is killed.
Definition at line 64 of file Ball.h.
Referenced by Ball(), Init(), and Reincarnate().
Bongo * Ball::mpBongo [private] |
double Ball::mSpeed [private] |
1.8.0