void Actor::Move( const D3DXVECTOR3& direction ) { // 가속 시작 시점 기록 - 타임 스탬프로 문제 해결 // 나중에는 타이머 만들어서 써볼까? m_AccelerationStartTime = timeGetTime(); SetIsAccelerating( true ); D3DXVECTOR3 normalVec( 0, 0, 0 ); D3DXVec3Normalize( &normalVec, &direction ); m_Rigidbody.m_Acceleration += ( normalVec * ACCELERATION_WEIGHT ); }
void PlayerCharacter::SetAcceleration() { // 가속 시작 시점 기록 - 타임 스탬프로 문제 해결 // 나중에는 타이머 만들어서 써볼까? m_AccelerationStart = timeGetTime(); m_IsAccelerating = true; D3DXVECTOR3 normalVec( 0, 0, 0 ); D3DXVECTOR3 viewDirection( GetViewDirection() ); Physics::GetNormalVector( &viewDirection, &normalVec ); // 조심해! // 가속도 가중치 하드 코딩 수정 할 것 m_Acceleration += ( viewDirection * 1.0f ); }
void CLineEmitter::InitParticle(ParticlePtr &particle) { math::vec2f ws_pos = mPos + mPositionOffset; math::vec2f dir = this->mDirection.Rotate(util::Rand::Get()->Randomf(-this->mEmisionAngle, this->mEmisionAngle)); dir.Normalize(); math::vec2f ws_end_pos = ws_pos + this->mPosEnd; math::vec2f normalVec(ws_pos - ws_end_pos); math::float32 len = normalVec.Length(); normalVec.Normalize(); //len = static_cast<math::float32>(rand()%static_cast<math::int32>(len)); len = util::Rand::Get()->Randomf(len); math::float32 speed = util::Rand::Get()->Randomf(mParticleSpeed-mParticleSpeedVariation, mParticleSpeed+mParticleSpeedVariation); math::CColorRGBA clr = RandomiseColor(); particle->Init(ws_pos + (normalVec * len), dir, speed, util::Rand::Get()->Randomf(this->mLiveTime-mLiveTimeVariation, this->mLiveTime+mLiveTimeVariation), clr, 0, mScale); }
static bool const buildCircleData (float radius, const unsigned int subdivisions, const osg::Vec3& orientation, osg::Geometry* geom, const bool wire ) { unsigned int numSub( subdivisions ); unsigned int totalVerts(0); if( numSub < 3 ) numSub = 3; if( numSub > 65530 ) { // Would create index array too large for use with DrawElementsUShort. Clamp. numSub = 65530; // leave headroom for a few spares osg::notify( osg::WARN ) << "buildCircleData: Clamping subdivisions to " << numSub << std::endl; } totalVerts = ( (numSub+2) ); // +2: Center, and final, closing vertex osg::notify( osg::INFO ) << "buildCircleData: totalVerts: " << totalVerts << std::endl; // Create data arrays and configure the Geometry osg::ref_ptr< osg::Vec3Array > vertices( new osg::Vec3Array ); vertices->resize( totalVerts ); geom->setVertexArray( vertices.get() ); osg::ref_ptr< osg::Vec3Array > normals; osg::ref_ptr< osg::Vec2Array > texCoords; if( !wire ) { normals = new osg::Vec3Array; normals->resize( totalVerts ); geom->setNormalArray( normals.get() ); geom->setNormalBinding( osg::Geometry::BIND_PER_VERTEX ); texCoords = new osg::Vec2Array; texCoords->resize( totalVerts ); geom->setTexCoordArray( 0, texCoords.get() ); } { osg::Vec4Array* osgC = new osg::Vec4Array; osgC->push_back( osg::Vec4( 1., 1., 1., 1. ) ); geom->setColorArray( osgC ); geom->setColorBinding( osg::Geometry::BIND_OVERALL ); } // Create the vertices, normals, and tex coords. unsigned int idx( 0 ); unsigned int subCounter; const osg::Vec3 centerVecZero( 0., 0., 0. ); osg::Vec3 normalVec( orientation ); normalVec.normalize(); // center: idx=0 (*vertices)[ idx ] = centerVecZero; if( !wire ) { (*normals)[ idx ] = normalVec; (*texCoords)[ idx ].set( centerVecZero.x(), centerVecZero.y() ); } // if idx++; // Find ideal base vector (at 90 degree angle to normalVec) osg::Vec3 crossVec( 1., 0., 0. ); if( osg::absolute( normalVec * crossVec ) > .9 ) crossVec = osg::Vec3( 0., 1., 0. ); osg::Vec3 baseVec = normalVec ^ crossVec; baseVec.normalize(); // circle-loop for( subCounter=0; subCounter<=numSub; subCounter++ ) { const double t( (double)(subCounter) / (double)numSub ); const double subAngle( t * 2.0 * osg::PI); // subAngle is in range (0,2pi) radians. osg::Matrix m( osg::Matrix::rotate( subAngle, normalVec ) ); osg::Vec3 v( baseVec * m ); (*vertices)[ idx ] = ( v * radius ); //osg::notify( osg::ALWAYS ) << v << std::endl; if( !wire ) { (*normals)[ idx ] = normalVec; const osg::Vec3 vRad(v * radius); (*texCoords)[ idx ].set( vRad.x(), vRad.y() ); } // if idx++; } if( idx != totalVerts ) { osg::notify( osg::WARN ) << "buildCircleData: Error creating vertices." << std::endl; osg::notify( osg::WARN ) << " idx " << idx << " != totalVerts " << totalVerts << std::endl; } // Create PrimitiveSets. if( !wire ) { // Solid -- Use GL_TRIANGLE_FAN // Create indices -- top group of triangles osg::DrawElementsUShort* fan( new osg::DrawElementsUShort( GL_TRIANGLE_FAN ) ); fan->resize( numSub+2 ); // center, 1...n, 1 again to close idx = 0; // push center (*fan)[ idx ] = 0; idx++; // circle loop for( unsigned int subCount=0; subCount<numSub+1; subCount++ )// numsub+1 gets us start, ring and end (which duplicates start) { (*fan)[ idx ] = idx; idx++; } geom->addPrimitiveSet( fan ); } // if !wire else { // Wire -- Use GL_LINE_LOOP // we skip vertex #0 (center) when drawing the LINE_LOOP // Create indices osg::DrawElementsUShort* ring; ring = new osg::DrawElementsUShort( GL_LINE_LOOP ); ring->resize( numSub+1 ); unsigned int loopIdx; for( loopIdx=0; loopIdx<numSub+1; loopIdx++ ) // numsub+1 gets us start, ring and end (which duplicates start) { (*ring)[ loopIdx ] = loopIdx + 1; // skipping #0, center } // for geom->addPrimitiveSet( ring ); } // wire return( true ); } // buildCircleData