Exemplo n.º 1
0
void Bullet::initialize(    int id,
                            const Vector3& from,
                            const Vector3& angle,
                            const Robo* shooter,
                            const Robo* opponent,
                            bool is_homing)
{
    assert(id >= 0);
    owner_id_ = id;
    age_ = 0;
    is_homing_ = is_homing;
    previous_point_ = from;
    current_point_ = from;

    if (!is_homing_)
    {
        Matrix44 rotation;
        rotation.rotate(angle);
        velocity_ = Vector3(0.0, 0.0, Speed0);
        rotation.multiply(&velocity_);
    }
    else
    {
        velocity_ = *opponent->center();
        velocity_.subtract(from);
        velocity_.normalize(Speed0);
    }

    shooter_ = shooter;
    target_robo_ = opponent;
}
Exemplo n.º 2
0
void Batch::draw( 
const Matrix44& pvm, 
const Matrix34& wm, 
const Vector3& lightVector,
const Vector3& lightColor,
const Vector3& ambient,
const Vector3& diffuseColor ) const {
	Framework f = Framework::instance();
	//テクスチャセット
	if ( mTexture ){
		mTexture->set();
	}else{
		f.setTexture( 0 ); //空のテクスチャ
	}
	//ブレンドモードセット
	f.setBlendMode( mBlendMode );
	//ブレンドモードによってZバッファ書き込みのフラグをOn,Off
	if ( mBlendMode == Framework::BLEND_OPAQUE ){
		f.enableDepthWrite( true );
	}else{
		f.enableDepthWrite( false );
	}
	//ZテストはいつもOn
	f.enableDepthTest( true );
	//頂点をワールドに変換
	int vertexNumber = mVertexBuffer->size();
	Vector3* wv = new Vector3[ vertexNumber ];
	for ( int i = 0;i < vertexNumber; ++i ){
		wm.multiply( &wv[ i ], *mVertexBuffer->position( i ) );
	}
	//頂点を最終変換
	double* fv = new double[ vertexNumber * 4 ]; //final vertices
	for ( int i = 0;i < vertexNumber; ++i ){
		pvm.multiply( &fv[ i * 4 ], wv[ i ] );
	}
	//法線をワールド座標に変換する。本当はワールド行列ではいけない。
	Matrix34 wmNormal = wm; //ワールド行列から移動を抜いたもの
	wmNormal.m03 = wmNormal.m13 = wmNormal.m23 = 0.0;
	//前もって頂点単位で色を決めておく
	unsigned* colors = new unsigned[ vertexNumber ];
	for ( int i = 0; i < vertexNumber; ++i ){
		Vector3 wm; //world normal
		wmNormal.multiply( &wm, mNormals[ i ] ); //ワールド座標に変換
		wm *= 1.f / wm.length(); //長さを1にして
		colors[ i ] = light( lightVector, lightColor, ambient, diffuseColor, wm );
	}
	int triangleNumber = mIndexBuffer->size() / 3;
	for ( int i = 0; i < triangleNumber; ++i ){
		unsigned i0 = mIndexBuffer->index( i * 3 + 0 );
		unsigned i1 = mIndexBuffer->index( i * 3 + 1 );
		unsigned i2 = mIndexBuffer->index( i * 3 + 2 );
		f.drawTriangle3DH(
			&fv[ i0 * 4 ],
			&fv[ i1 * 4 ],
			&fv[ i2 * 4 ],
			&mVertexBuffer->uv( i0 )->x,
			&mVertexBuffer->uv( i1 )->x,
			&mVertexBuffer->uv( i2 )->x,
			colors[ i0 ],
			colors[ i1 ],
			colors[ i2 ] );
	}
	SAFE_DELETE_ARRAY( wv );
	SAFE_DELETE_ARRAY( fv );
	SAFE_DELETE_ARRAY( colors );
}