DirArrayGen::DirArrayGen( Vec2D const& d ) { difPos = Vec2D(0,0); dir = ( 1.0f / sqrtf( d.length2() ) ) * d; num = 1; offset = 2; }
void SimpleGen::generate( Weapon* weapon ) { Object* owner = weapon->owner; Object* destObj = weapon->destObj; Vec2D dif = destObj->getPos() - owner->getPos(); float s= sqrtf(dif.length2()); Vec2D speed = ( weapon->bulletSpeed / s ) * dif; Object* bullet = weapon->createBullet(); bullet->setVelocity( speed ); spawnObject(bullet); }
void CircleMove::update( Object& obj , long time ) { float len = m_speed * time / 1000.0f; Vec2D dir = getCenterPos( obj ) - org; float d = sqrtf( dir.length2() ); if ( d < 0.001 ) return; if( fabs( radius - d ) > len ) { if ( d > radius ) { obj.setVelocity( (-len / d)* dir ); return; } else { obj.setVelocity( (len / d) * dir ); return; } } float cos_ = ( radius*radius + d*d - len*len ) / ( 2 * radius * d ); if ( fabs( cos_ ) > 1 ) return; float theta = acos( cos_ ); Vec2D rDir = ( radius / d ) * dir; Vec2D dotDir( -rDir.y , rDir.x ); if ( !isClockwise ) dotDir = - dotDir; Vec2D outSpeed = ( cos( theta )* rDir) + ( sin( theta ) * dotDir) - dir; obj.setVelocity( outSpeed ); }
void DirArrayGen::setDir( Vec2D const& d ) { dir = ( 1.0f / sqrtf( d.length2() ) ) * d; }
void Follow::update( Object& obj , long time) { Vec2D dif = destObj->getPos() - getCenterPos( obj ); float s= sqrtf( dif.length2() ); obj.setVelocity( speed * time / (1000 *s ) * dif ); }