/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2006 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific: main-programmer: */ #include "blink.h" #include "util/loading/load_param.h" #include "util/loading/factory.h" #include "debug.h" #include "state.h" #include "material.h" ObjectListDefinition(Blink); CREATE_FACTORY(Blink); /** * standart constructor */ Blink::Blink (const TiXmlElement* root) { this->init(); if( root) this->loadParams(root); } /** * destroys a Blink */ Blink::~Blink () { if (this->material) delete this->material; } /** * initializes the Blink */ void Blink::init() { this->registerObject(this, Blink::_objectList); this->setName("Blink"); this->toList(OM_COMMON); this->material = new Material(); //this->material->setIllum(0); //this->material->setDiffuse(1.0,1.0,1.0); //this->material->setTransparency(0.0); // this->material->setSpecular(0.0,0.0,0.0); // this->material->setAmbient(1.0, 1.0, 1.0); //this->material->setBlendFunc(GL_ZERO,GL_ZERO); //this->material->setDiffuseMap("pictures/rblink2.png"); this->material->setDiffuseMap("maps/star_alpha.png"); //this->setAbsCoor(0, 0, 0);d //this->setVisibiliy(true); // this->setSize(5, 5); //srand((unsigned)time(NULL)); /// Standard values this->setAbsCoor(0, 0, 0); this->position = Vector(0, 0, 0); ///remove this->color = Vector(255, 255, 255); this->size = 10; this->omega = 10; this->angle = rand() % 1000; PRINTF(0)("\n\n\n\n\n\n\nangle: %f\n\n\n\n\n\n\n\n", this->angle); this->angle *= 2 * M_PI; PRINTF(0)("\n\n\n\n\n\n\nangle: %f\n\n\n\n\n\n\n\n", this->angle); } /** * load params * @param root TiXmlElement object */ void Blink::loadParams(const TiXmlElement* root) { WorldEntity::loadParams(root); LoadParam(root, "position", this, Blink, setPosition); LoadParam(root, "size", this, Blink, setSize); LoadParam(root, "color", this, Blink, setColor); LoadParam(root, "omega", this, Blink, setOmega); // LoadParam(root, "watersize", this, Blink, setWaterSize); // LoadParam(root, "wateruv", this, Blink, setWaterUV); // LoadParam(root, "waterflow", this, Blink, setWaterFlow); // LoadParam(root, "lightpos", this, Blink, setLightPos); // LoadParam(root, "waterangle", this, Blink, setWaterAngle); // LoadParam(root, "normalmapscale", this, Blink, setNormalMapScale); // LoadParam(root, "shinesize", this, Blink, setShineSize); // LoadParam(root, "shinestrength", this, Blink, setShineStrength); // LoadParam(root, "reflstrength", this, Blink, setReflStrength); // LoadParam(root, "refraction", this, Blink, setRefraction); // LoadParam(root, "watercolor", this, Blink, setWaterColor); /*LoadParam(root, "texture", this->material, Material, setDiffuseMap) .describe("the texture-file to load onto the Blink"); LoadParam(root, "size", this, Blink, setSize) .describe("the size of the Blink in Pixels");*/ } /** * ticks the Blink * @param dt the time to ticks */ void Blink::tick(float dt) { this->angle += dt * this->omega; if (this->angle > 2 * M_PI) this->angle -= 2 * M_PI; this->blinkStr = sinf(angle); } /** * draws the blink */ void Blink::draw() const { glPushAttrib(GL_ENABLE_BIT); glEnable(GL_LIGHTING); //glDisable(GL_LIGHTING); glDisable(GL_FOG); glMatrixMode(GL_MODELVIEW); glPushMatrix(); // Vector pos = this->getAbsCoor(); // Vector dir = pos - State::getCameraNode()->getAbsCoor(); // dir.normalize(); // // Vector up = Vector(0, 1, 0); // Vector h = dir.cross(up); // // Vector pos = this->getAbsCoor(); // glTranslatef(pos.x, pos.y, pos.z); /* translate */ // glTranslatef (this->getAbsCoor ().x, // this->getAbsCoor ().y, // this->getAbsCoor ().z); // Vector tmpRot = this->getAbsDir().getSpacialAxis(); // glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); // glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Set The Blending Function For Translucency // glEnable(GL_BLEND); // glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // glShadeModel(GL_SMOOTH); Vector camCoor = State::getCameraNode()->getAbsCoor(); Vector diff = camCoor - this->position; //glTranslatef(position.x + size/2, position.y + size/2, position.z); glTranslatef(this->position.x - this->size/2, this->position.y - this->size/2, this->position.z); // Vector view = this->getAbsCoor() - State::getCameraNode()->getAbsCoor(); // view.normalize(); // // Vector up = Vector(0, 1, 0); // Vector h = view.cross(up); this->material->select(); glColor4ub(this->color.x, this->color.y, this->color.z, 127.5*(this->blinkStr + 1)); glBegin(GL_QUADS); glTexCoord2f(1, 1); glVertex3f(0, 0, 0); glTexCoord2f(1, 0); glVertex3f(this->size, 0, 0); glTexCoord2f(0, 0); glVertex3f(this->size, this->size, 0); glTexCoord2f(0, 1); glVertex3f(0, this->size, 0); glEnd(); glPopMatrix(); glPopAttrib(); }