Exemplo n.º 1
0
void MetaballManager2D::SetMetaballPosition(const IvVector3& position, const float radius)
{
	for(int i = 0; i < 1; i++)
	{
		int startIDX = mVertices.size();
		float x1,y1,x2,y2,u1,u2,v1,v2;
		x1 = position.x - radius;
		x2 = position.x + radius;
		
		y1 = position.y - radius;
		y2 = position.y + radius;
		
		u1 = v2 = 0.0f;
		u2 = v1 = 1.0f;
		
		IvVector3 pos;
		pos.Set(x1,y1,0);
		mVertices.push_back(pos);
		pos.Set(x2,y1,0);
		mVertices.push_back(pos);
		pos.Set(x2,y2,0);
		
		mVertices.push_back(pos);
		pos.Set(x1,y2,0);
		mVertices.push_back(pos);
		
		IvColor c(1.0f,1.0f,1.0f,1.0f);
		mColors.push_back(c);
		mColors.push_back(c);
		mColors.push_back(c);
		mColors.push_back(c);
		
		IvVector2 uv;
		uv.Set(u1,v1);
		mUVs.push_back(uv);
		uv.Set(u2,v1);
		mUVs.push_back(uv);
		uv.Set(u2,v2);
		mUVs.push_back(uv);
		uv.Set(u1,v2);
		mUVs.push_back(uv);
		
		mIndices.push_back(startIDX + 0);
		mIndices.push_back(startIDX + 2);
		mIndices.push_back(startIDX + 3);
		
		mIndices.push_back(startIDX + 0);
		mIndices.push_back(startIDX + 1);
		mIndices.push_back(startIDX + 2);
	}
	mDirtyMesh = true;
}
Exemplo n.º 2
0
void LetterChooser::GridLayout()
{
	std::vector<IvAABB> blockedAreas;
	mGameLogic->GetBlockedDropletAreas(blockedAreas);
	
	mPositionList.clear();
	//float w = mGame.GetRenderer().GetWindowWidth();
	//float h = mGame.GetRenderer().GetWindowHeight();
	float x,y;
	x = mDisplayMin.x;
	y = mDisplayMin.y;

	int lettersPerRow = mSourceLetters.size()/mRows;
	IvVector2 dim = mDisplayMax - mDisplayMin;
	int yIncrement = dim.y/mRows;
	int xIncrement = dim.x/lettersPerRow;

	IvVector3 origin;
	GetWorldPosition(origin);
	for(int i = 0; i < mSourceLetters.size(); ++i)
	{
		LetterButton* l = mSourceLetters[i];
		IvVector3 pos;
		pos.Set(x,y,origin.z);
		mPositionList.push_back(pos);
		mPositionDB[l->mChar] = pos;
		x += xIncrement;
		if(x >= mDisplayMax.x)
		{
			y += yIncrement;
			x = mDisplayMin.x;	
		}
	}
	
}
Exemplo n.º 3
0
//-------------------------------------------------------------------------------
// @ IvQuat::GetAxisAngle()
//-------------------------------------------------------------------------------
// Get axis-angle based on quaternion
//-------------------------------------------------------------------------------
void
IvQuat::GetAxisAngle( IvVector3& axis, float& angle )
{
    angle = 2.0f*acosf( w );
    float length = ::IvSqrt( 1.0f - w*w );
    if ( ::IsZero(length) )
        axis.Zero();
    else
    {
        length = 1.0f/length;
        axis.Set( x*length, y*length, z*length );
    }

}   // End of IvQuat::GetAxisAngle()
Exemplo n.º 4
0
//-------------------------------------------------------------------------------
// @ Player::Update()
//-------------------------------------------------------------------------------
// Main update loop
//-------------------------------------------------------------------------------
void
Player::Update( float dt )
{
    float s = 1.0f;
    float r = 0.0f;
    float x = 0.0f, y = 0.0f, z = 0.0f; 
    IvQuat rotate;
    IvVector3 xlate;
    IvMatrix44 transform;
    
    // set up scaling
    if (IvGame::mGame->mEventHandler->IsKeyDown(';'))
    {
        s -= 0.25f*dt;
    }
    if (IvGame::mGame->mEventHandler->IsKeyDown('p'))
    {
        s += 0.25f*dt;
    }
    mScale *= s;
    
    // set up rotate
    if (IvGame::mGame->mEventHandler->IsKeyDown('o'))
    {
        r -= kPI*0.25f*dt;
    }
    if (IvGame::mGame->mEventHandler->IsKeyDown('u'))
    {
        r += kPI*0.25f*dt;
    }
    rotate.Set(IvVector3::zAxis, r);
    mRotate = rotate*mRotate;
    mRotate.Normalize();
    
    // set up translation
    if (IvGame::mGame->mEventHandler->IsKeyDown('k'))
    {
        x -= 3.0f*dt;
    }
    if (IvGame::mGame->mEventHandler->IsKeyDown('i'))
    {
        x += 3.0f*dt;
    }
    if (IvGame::mGame->mEventHandler->IsKeyDown('l'))
    {
        y -= 3.0f*dt;
    }
    if (IvGame::mGame->mEventHandler->IsKeyDown('j'))
    {
        y += 3.0f*dt;
    }
    xlate.Set( x, y, z );
    mTranslate += xlate;
    
    if (IvGame::mGame->mEventHandler->IsKeyPressed('s'))
    {
        mUseSkyShader = !mUseSkyShader;
    }

    // clear transform
    if (IvGame::mGame->mEventHandler->IsKeyPressed(' '))
    {
        mRotate.Identity();
        mScale = 1.0f;
        mTranslate.Zero();
    }

}   // End of Player::Update()
Exemplo n.º 5
0
void LetterChooser::RandomLayout()
{
	std::vector<IvAABB> blockedAreas;
	mGameLogic->GetBlockedDropletAreas(blockedAreas);
	
	mPositionList.clear();
	float x,y;
	x = mDisplayMin.x;
	y = 480.0f -  mDisplayMin.y;
	
	IvVector2 dim = mDisplayMax - mDisplayMin;
	int increment = 2.0f*TOUCH_RADIUS + mJitterStrength;
	
	IvVector3 origin;
	GetWorldPosition(origin);
	srand(1972);
	for(int i = 0; i < mSourceLetters.size(); ++i)
	{
		LetterButton* l = mSourceLetters[i];
		IvVector3 pos;
		
		float xNoise = rand() % (int)mJitterStrength;
		float yNoise = rand() % (int)mJitterStrength;
		
		
		pos.Set(x+xNoise,480.0f - (y+yNoise),origin.z);
		for(unsigned int j = 0; j < blockedAreas.size(); j++)
		{
			float yradius = l->mRadius*480.0f*0.5f;
			float xradius = l->mRadius*320.0f*0.5f;
			IvAABB blocker = blockedAreas[j];
			IvVector3 min, max;
			min.x = pos.x - xradius;
			min.y = pos.y - yradius;
			min.z = -5.0f;
			
			max.x = pos.x + xradius;
			max.y = pos.y + yradius;
			max.z = +5.0f;
			
			IvAABB test(min,max);
			
			if(test.Intersect(blocker))
			{
				float newX = blocker.GetMaxima().x + xradius;
				if(newX > x)
				{
					x = newX;
					if(x >= mDisplayMax.x)
					{
						y += increment;
						pos.y -= increment;
						x = mDisplayMin.x;	
					}
					pos.x = x;
				}
			}
			
		}
		mPositionList.push_back(pos);
		mPositionDB[l->mChar] = pos;
		x += increment;
		if(x >= mDisplayMax.x)
		{
			y += increment;
			x = mDisplayMin.x;	
		}
	}
	
}
Exemplo n.º 6
0
//-------------------------------------------------------------------------------
// @ Player::Update()
//-------------------------------------------------------------------------------
// Main update loop
//-------------------------------------------------------------------------------
void
Player::Update( float dt )
{
    float s = 1.0f;
    float r = 0.0f;
    float x = 0.0f, y = 0.0f, z = 0.0f; 
    IvMatrix33 rotate;
    IvVector3 xlate;
    IvMatrix44 transform;
    
    mTurret->Update( dt );
    
    // set up scaling
    if (IvGame::mGame->mEventHandler->IsKeyDown(';'))
    {
        s -= 0.25f*dt;
    }
    if (IvGame::mGame->mEventHandler->IsKeyDown('p'))
    {
        s += 0.25f*dt;
    }
    mScale *= s;
    
    // set up rotate
    if (IvGame::mGame->mEventHandler->IsKeyDown('o'))
    {
        r -= kPI*0.25f*dt;
    }
    if (IvGame::mGame->mEventHandler->IsKeyDown('u'))
    {
        r += kPI*0.25f*dt;
    }
    rotate.RotationZ(r);
    mRotate = rotate*mRotate;
    
    // set up translation
    if (IvGame::mGame->mEventHandler->IsKeyDown('k'))
    {
        x -= 3.0f*dt;
    }
    if (IvGame::mGame->mEventHandler->IsKeyDown('i'))
    {
        x += 3.0f*dt;
    }
    if (IvGame::mGame->mEventHandler->IsKeyDown('l'))
    {
        y -= 3.0f*dt;
    }
    if (IvGame::mGame->mEventHandler->IsKeyDown('j'))
    {
        y += 3.0f*dt;
    }
    xlate.Set( x, y, z );
    mTranslate += xlate;
    
    // clear transform
    if (IvGame::mGame->mEventHandler->IsKeyDown(' '))
    {
        mRotate.Identity();
        mScale = 0.25f;
        mTranslate.Zero();
    }

}   // End of Player::Update()