static int displayLight(gfluxstruct *gp) { int polys = 0; double x,y; double z; double dx = 2.0/((double)_squares); double dy = 2.0/((double)_squares); glLoadIdentity(); glRotatef(gp->anglex,1,0,0); glRotatef(gp->angley,0,1,0); glRotatef(gp->anglez,0,0,1); userRot(gp); glScalef(1,1,(GLfloat)_waveHeight); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); for(x=-1;x<0.9999;x+=dx) { glBegin(GL_QUAD_STRIP); for(y=-1;y<=1;y+=dy) { z = getGrid(gp, x,y,gp->time); genColour(z); glColor3fv(gp->colour); glNormal3f( getGrid(gp, x+dx,y,gp->time)-getGrid(gp, x-dx,y,gp->time), getGrid(gp, x,y+dy,gp->time)-getGrid(gp, x,y-dy,gp->time), 1 ); glVertex3f(x,y,z); z = getGrid(gp, x+dx,y,gp->time); genColour(z); glColor3fv(gp->colour); glNormal3f( getGrid(gp, x+dx+dx,y,gp->time)-getGrid(gp, x,y,gp->time), getGrid(gp, x+dx,y+dy,gp->time)-getGrid(gp, x+dx,y-dy,gp->time), 1 ); glVertex3f(x+dx,y,z); polys++; } glEnd(); } if (! gp->button_down_p) { gp->time -= _speed; gp->anglex -= _rotationx; gp->angley -= _rotationy; gp->anglez -= _rotationz; } return polys; }
static int displayWire(gfluxstruct *gp) { int polys = 0; double x,y; double z; double dx1 = 2.0/((double)(_squares*_resolution)) - 0.00001; double dy1 = 2.0/((double)(_squares*_resolution)) - 0.00001; double dx2 = 2.0/((double)_squares) - 0.00001; double dy2 = 2.0/((double)_squares) - 0.00001; glLoadIdentity(); glRotatef(gp->anglex,1,0,0); glRotatef(gp->angley,0,1,0); glRotatef(gp->anglez,0,0,1); userRot(gp); glScalef(1,1,(GLfloat)_waveHeight); glClear(GL_COLOR_BUFFER_BIT); for(x=-1;x<=1;x+=dx2) { glBegin(GL_LINE_STRIP); for(y=-1;y<=1;y+=dy1) { z = getGrid(gp, x,y,gp->time); genColour(z); glColor3fv(gp->colour); glVertex3f(x,y,z); polys++; } glEnd(); } for(y=-1;y<=1;y+=dy2) { glBegin(GL_LINE_STRIP); for(x=-1;x<=1;x+=dx1) { z = getGrid(gp, x,y,gp->time); genColour(z); glColor3fv(gp->colour); glVertex3f(x,y,z); polys++; } glEnd(); } if (! gp->button_down_p) { gp->time -= _speed; gp->anglex -= _rotationx; gp->angley -= _rotationy; gp->anglez -= _rotationz; } return polys; }
//--------------------------------------------------------------------- void BeamElement::_updateBillboardChains( Real time ) { mCurrentFrequencyTime += time; if (mCurrentFrequencyTime > mFrequencyTime || mFrequency == 0.0f) { // 如果目标位置为初始位置,就不进行更新,防止第一帧出现的位置不正确 if (mDestPos == Ogre::Vector3::UNIT_Y) { return; } Ogre::Vector3 originPos = mBasicNode->_getDerivedPosition(); // 如果初始点还没初始化(在LogicModel::addEffect中会把这个特效的位置设成一个很低的地方),也return if ( originPos.y < -9000 ) { return; } if (mBillboardChain) { Ogre::ColourValue colour; genColour(colour); for (int j = 0; j < mNumBillboardElements; ++j) { if (j == 0) { mBillboardChain->setChainElement(j, Ogre::EffectBillboardChainElement( Ogre::Vector3::ZERO, mWidth, 0.0f, colour) ); } else if ( j == (mNumBillboardElements-1) ) { mBillboardChain->setChainElement(j, Ogre::EffectBillboardChainElement( mDestPos - originPos, mWidth, 1.0f, colour) ); } else { float interpolateValue = (float)j / (float)mNumBillboardElements; Ogre::Vector3 pos = (mDestPos - originPos) * interpolateValue; pos.x += Ogre::Math::RangeRandom(mNoiseXMin, mNoiseXMax); pos.y += Ogre::Math::RangeRandom(mNoiseYMin, mNoiseYMax); pos.z += Ogre::Math::RangeRandom(mNoiseZMin, mNoiseZMax); mBillboardChain->setChainElement(j, Ogre::EffectBillboardChainElement( pos, mWidth, interpolateValue, colour) ); } } mBillboardChain->updateBoundingBox(); // 数据已准备好,可以进行渲染了 mBillboardChain->isInitData(true); } mCurrentFrequencyTime = 0.0f; } }