//----------------------------------------------------------------------------- // Name: getRandomVector() // Desc: Generates a random vector where X,Y, and Z components are between // -1.0 and 1.0 //----------------------------------------------------------------------------- D3DXVECTOR3 getRandomVector( void ) { D3DXVECTOR3 vVector; // Pick a random Z between -1.0f and 1.0f. vVector.z = getRandomMinMax( -1.0f, 1.0f ); // Get radius of this circle float radius = (float)sqrt(1 - vVector.z * vVector.z); // Pick a random point on a circle. float t = getRandomMinMax( -D3DX_PI, D3DX_PI ); // Compute matching X and Y for our Z. vVector.x = (float)cosf(t) * radius; vVector.y = (float)sinf(t) * radius; return vVector; }
void GLWidget::createScene() { QFile democles(":Democles.dae"); m_World= GLC_Factory::instance()->createWorldFromFile(democles); m_ShuttleBoundingBox= m_World.boundingBox(); GLC_StructOccurence* pRoot= m_World.rootOccurence(); QImage texture(QString(":particle.png")); GLC_3DRep pointSprite; const float min= -20000.0f; const float max= 20000.0f; for (int i= 0; i < 300; ++i) { QColor currentColor; currentColor.setRedF(getRandomMinMax(0.4, 1.0)); currentColor.setGreenF(getRandomMinMax(0.4, 0.7)); currentColor.setBlueF(getRandomMinMax(0.4, 1.0)); GLC_Material* pMaterial= GLC_Factory::instance()->createMaterial(texture); pMaterial->setDiffuseColor(currentColor); pointSprite= GLC_Factory::instance()->createPointSprite(getRandomMinMax(5.0f, 10.0f), pMaterial); GLC_StructReference* pStructReference= new GLC_StructReference(new GLC_3DRep(pointSprite)); GLC_StructInstance* pStructInstance= new GLC_StructInstance(pStructReference); GLC_Point3d position(getRandomMinMax(min, max), getRandomMinMax(min, max), getRandomMinMax(min, max)); const double norm= position.length(); if ((norm > max) || (norm < (max / 2))) position.setLength(max); pStructInstance->translate(position); pRoot->addChild(pStructInstance); } }