Go to the documentation of this file.00001 #include <stdio.h>
00002 #include <string.h>
00003 #include "Internal.h"
00004 #include "util.h"
00005 #include "Arrow.h"
00006
00007 #include "Bongo.h"
00008 #include "XRes.h"
00009
00010 Arrow::Arrow(Bongo* parent)
00011 : mpParent(parent), mGluQuadric(0), mbHitBox(false)
00012 {
00013 }
00014
00015 Arrow::~Arrow()
00016 {
00017 if (mGluQuadric)
00018 gluDeleteQuadric(mGluQuadric);
00019 }
00020
00021 Bongo* Arrow::GetParent()
00022 {
00023 return mpParent;
00024 }
00025
00026 bool Arrow::Init(XRes *resource, XCongo *xcongo)
00027 {
00028
00029 if (!Lifetime::Init(resource) )
00030 return false;
00031
00032 memset(mDirection, 0, 3 * sizeof(double) );
00033 if (!resource->DoubleValue("mPower", &mPower) )
00034 {
00035 LOGE("reading Arrow power");
00036 return false;
00037 }
00038 mDirection[1] = mPower;
00039 int i;
00040 const double *parent_pos = mpParent->Position();
00041 for (i = 0; i < 3; i++)
00042 mPos[i] = parent_pos[i];
00043
00044 mPos[1] += mpParent->Size();
00045 mSize = mpParent->Size();
00046 const double *parent_color = mpParent->Color();
00047 for (i = 0; i < 3; i++)
00048 mColor[i] = parent_color[i];
00049
00050
00051 mGluQuadric = gluNewQuadric();
00052 if (!mGluQuadric)
00053 {
00054 LOGE("gluNewQuadric");
00055 return false;
00056 }
00057 return true;
00058 }
00059
00060 const char* Arrow::ClassName() const
00061 {
00062 return "Arrow";
00063 }
00064
00066 bool Arrow::Move(const double *forse)
00067 {
00068 if (mbHitBox)
00069 return false;
00070
00071 return Quad_impl::Move(forse);
00072 }
00073
00074 bool Arrow::Display()
00075 {
00076 glPushMatrix();
00077
00078
00079 GLfloat mat_specular[] = { mColor[0], mColor[1], mColor[2], 1.0 };
00080 GLfloat mat_shininess[] = { 50.0 };
00081 glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
00082 glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_specular);
00083 glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
00084
00085
00086 glPushMatrix();
00087 glTranslatef(mPos[0], 0.0, mPos[2]);
00088 glRotatef(90, -1.0, 0.0, 0.0);
00089 gluCylinder(mGluQuadric, mSize/12, mSize/12, mPos[1], 4, 4);
00090 glPopMatrix();
00091
00092
00093 glTranslatef(mPos[0], mPos[1], mPos[2]);
00094 glRotatef(90, -1.0, 0.0, 0.0);
00095 glutSolidCone(mSize/4, mSize, int(mSize/2 * 30), int(mSize/2 * 22) );
00096
00097 glPopMatrix();
00098 return true;
00099 }
00100
00101 void Arrow::HitBox()
00102 {
00103 mbHitBox = true;
00104 }
00105
00106
00107
00108
00109