00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <sprites/ExplosionLaserBeamRenderer.h>
00022 #include <common/Defines.h>
00023 #include <console/Console.h>
00024 #include <image/ImageFactory.h>
00025 #include <sound/SoundUtils.h>
00026 #include <client/ScorchedClient.h>
00027 #include <graph/ParticleEmitter.h>
00028 #include <graph/ParticleEngine.h>
00029
00030
00031 REGISTER_CLASS_SOURCE(ExplosionLaserBeamRenderer);
00032
00033 GLTexture *ExplosionLaserBeamRenderer::_texture = 0;
00034
00035 ExplosionLaserBeamRenderer::~ExplosionLaserBeamRenderer()
00036 {
00037 }
00038
00039 ExplosionLaserBeamRenderer::ExplosionLaserBeamRenderer():
00040 totalTime_(0), time_(0), size_(12.0f), angle_(0)
00041 {
00042
00043 }
00044
00045 void ExplosionLaserBeamRenderer::init(unsigned int playerId,
00046 Vector &position, Vector &velocity, const char *data)
00047 {
00048 if (0 != strcmp("none", data))
00049 {
00050 SoundBuffer *firedSound =
00051 Sound::instance()->fetchOrCreateBuffer(
00052 S3D::getDataFile(data));
00053 SoundUtils::playAbsoluteSound(VirtualSoundPriority::eAction,
00054 firedSound, position);
00055 }
00056
00057 for (int j=0;j<layers;j++){
00058 for(int i=0;i<sides;i++){
00059 points[j][i]=Vector((float)(360/sides)*i,(double)((size_/(layers+1))*(j+1)));
00060 }
00061 }
00062 if (!_texture)
00063 {
00064 std::string file1 = S3D::getDataFile("data/textures/waves.bmp");
00065
00066 ImageHandle map = ImageFactory::loadImageHandle(file1.c_str(), file1.c_str(), false);
00067 _texture = new GLTexture;
00068 _texture->create(map, true);
00069 }
00070
00071 position_ = position;
00072
00073 ParticleEmitter emmiter;
00074 emmiter.setAttributes(
00075 10.0f, 0.9f,
00076 0.5f, 9.5f,
00077 0.0f, 0.0f,
00078 Vector::getNullVector(), Vector::getNullVector(),
00079 Vector(0.9f, 0.9f, 0.1f), 0.9f,
00080 Vector(0.9f, 0.9f, 0.1f), 0.1f,
00081 Vector(0.6f, 0.6f, 0.95f), 0.0f,
00082 Vector(0.8f, 0.8f, 1.0f), 0.1f,
00083 0.0f, 0.0f, 0.5f, 0.5f,
00084 0.0f, 0.0f, 10.0f, 10.0f,
00085 Vector(0.0f, 0.0f, 10.0f),
00086 true,
00087 false);
00088
00089 Vector newPos1 = position_ + Vector(-4.0f, -4.0f, 0.0f);
00090 Vector newPos2 = position_ + Vector(4.0f, 4.0f, 0.0f);
00091 emmiter.emitLinear(800, newPos1, newPos2,
00092 ScorchedClient::instance()->getParticleEngine(),
00093 ParticleRendererQuads::getInstance());
00094 }
00095
00096 void ExplosionLaserBeamRenderer::draw(Action *action)
00097 {
00098 GLState currentState(GLState::TEXTURE_ON | GLState::BLEND_ON);
00099 _texture->draw();
00100
00101 glPushMatrix();
00102 glTranslatef(position_[0],position_[1],0.0f);
00103 glScalef(time_*0.05f,time_*0.05f,1.0f);
00104
00105 for (int j=0;j<layers;j++){
00106 glRotatef(angle_,0.0f,0.0f,1.0f);
00107 glBegin(GL_TRIANGLE_STRIP);
00108 int tempheight=(int)(time_*time_*time_);
00109 if (tempheight>100) tempheight=100;
00110 Vector height(0,0,tempheight);
00111
00112 glColor4f(0.0f,0.6f,0.9f, 0.4f);
00113
00114 for (int i=0;i<(sides+1);i++){
00115
00116 glNormal3fv ((float*)(points[j][i%sides]));
00117 if (i%2){
00118 glTexCoord2f(0.0f, 0.0f+((layers-j)*time_));
00119 }else{
00120 glTexCoord2f(2.0f, 0.0f+((layers-j)*time_));
00121 }
00122 glVertex3fv((float*)(points[j][i%sides]+height));
00123 glNormal3fv ((float*)(points[j][i%sides]));
00124 if (i%2){
00125 glTexCoord2f(0.0f, (float)(tempheight/10)+((layers-j)*time_));
00126 }else{
00127 glTexCoord2f(2.0f, (float)(tempheight/10)+((layers-j)*time_));
00128 }
00129 glVertex3fv((float*)(points[j][i%sides]));
00130 }
00131 for (int i=0;i<(sides+1);i++){
00132
00133 glNormal3fv ((float*)(points[j][i%sides]));
00134 if (i%2){
00135 glTexCoord2f(0.0f, 0.0f-((layers-j)*time_));
00136 }else{
00137 glTexCoord2f(2.0f, 0.0f-((layers-j)*time_));
00138 }
00139 glVertex3fv((float*)(points[j][i%sides]));
00140 glNormal3fv ((float*)(points[j][i%sides]));
00141 if (i%2){
00142 glTexCoord2f(0.0f, (float)(tempheight/10)-((layers-j)*time_));
00143 }else{
00144 glTexCoord2f(2.0f, (float)(tempheight/10)-((layers-j)*time_));
00145 }
00146 glVertex3fv((float*)(points[j][i%sides]+height));
00147 }
00148
00149 glEnd();
00150 }
00151 glPopMatrix();
00152
00153 }
00154 void ExplosionLaserBeamRenderer::simulate(Action *action, float frameTime, bool &remove)
00155 {
00156
00157 totalTime_ += frameTime;
00158 time_ += frameTime;
00159 angle_=(angle_+3.0f);
00160 if (angle_>360.0f){
00161 angle_=0.0f;
00162 }
00163 if ((time_)>size_){
00164 remove=true;
00165 }else{
00166 remove=false;
00167 }
00168
00169
00170 }
00171