Beispiel #1
0
bool CHitSquare::CheckHitCircleLineSegment(Circle * pcircle,Segment * seg)
{
	Segment segbuf,segbuf2;
	segbuf.s = seg->s;
	segbuf.v = pcircle->center - seg->s;

	segbuf2.s = seg->s + seg->v;
	segbuf2.v = segbuf.v - seg->v;

	float lenge = D3DXVec2Cross(&seg->v,&segbuf.v)/D3DXVec2Length(&seg->v);
	if(D3DXVec2Length(&seg->v) == 0)
		lenge = D3DXVec2Length(&(segbuf.v));

	if(lenge < 0)
		lenge = -lenge;
	
	if(pcircle->halfdiameter < lenge)
		return false;

	if(D3DXVec2Dot(&segbuf.v,&seg->v)*D3DXVec2Dot(&segbuf2.v,&seg->v) <= 0)
		return true;
	else
	if(pcircle->halfdiameter > D3DXVec2Length(&segbuf.v )||pcircle->halfdiameter > D3DXVec2Length(&segbuf2.v ))
		return true;

	return false;
}
Beispiel #2
0
//*************************************************************************************************************
void Update(float delta)
{
	// update exposure
	destexposurevelocity = 0;
	exposurevelocity = exposurevelocity + 0.4f * (destexposurevelocity - exposurevelocity);

	exposure.prev = exposure.curr;

	exposure.curr += exposurevelocity;
	exposure.curr = min(16.0f, max(0.004f, exposure.curr));

	// update cmaera & object
	D3DXVECTOR2 dir((float)mousedx, (float)mousedy);

	destcameravelocity = D3DXVECTOR2(0, 0);
	destobjectvelocity = D3DXVECTOR2(0, 0);

	if( mousedown == 1 )
		destcameravelocity = dir * 0.01f;

	if( mousedown == 2 )
		destobjectvelocity = dir * 0.01f;

	if( D3DXVec2Length(&destcameravelocity) > 0.7f )
	{
		D3DXVec2Normalize(&destcameravelocity, &destcameravelocity);
		destcameravelocity *= 0.7f;
	}

	if( D3DXVec2Length(&destobjectvelocity) > 0.7f )
	{
		D3DXVec2Normalize(&destobjectvelocity, &destobjectvelocity);
		destobjectvelocity *= 0.7f;
	}

	cameravelocity = cameravelocity + 0.3f * (destcameravelocity - cameravelocity);
	objectvelocity = objectvelocity + 0.3f * (destobjectvelocity - objectvelocity);

	cameraangle.prev = cameraangle.curr;
	cameraangle.curr += cameravelocity;

	objectangle.prev = objectangle.curr;
	objectangle.curr -= objectvelocity;

	if( cameraangle.curr.y >= 1.5f )
	{
		cameraangle.curr.y = 1.5f;
		cameravelocity.y = 0;
	}

	if( cameraangle.curr.y <= -1.5f )
	{
		cameraangle.curr.y = -1.5f;
		cameravelocity.y = 0;
	}
}
Beispiel #3
0
 std::shared_ptr<IPartawn>
 find_nearest_station(const Vector &v) {
     return *std::min_element(
         stations_.begin(),
         stations_.end(),
         [=](std::shared_ptr<IPartawn> car, std::shared_ptr<IPartawn> cdr) {
             auto d0 = car->location() - v;
             auto d1 = cdr->location() - v;
             return D3DXVec2Length(&d0) < D3DXVec2Length(&d1);
         });
 }
Beispiel #4
0
bool CBall::CalcGoalTexCollision(CSimpleSphere * sphr,CSimpleSquare * sqar,D3DXVECTOR3 * velo)
{
	D3DXVECTOR3 pos_coli;
	D3DXVECTOR2 pos_coli2D;
	D3DXVECTOR2 pos_goal2D;

	if(CalcSpherePlaneCollision(sphr,&sqar->m_TriangleVertex[0],velo,&pos_coli) == false)
		return false;

	if(CheckContained(sqar->m_TriangleVertex[0].m_Vertex[0],sqar->m_TriangleVertex[0].m_Vertex[1],sqar->m_TriangleVertex[0].m_Vertex[2],pos_coli)
	|| CheckContained(sqar->m_TriangleVertex[1].m_Vertex[0],sqar->m_TriangleVertex[1].m_Vertex[1],sqar->m_TriangleVertex[1].m_Vertex[2],pos_coli))
	{
		pos_coli2D.x = pos_coli.x;
		pos_coli2D.y = pos_coli.z;

		pos_goal2D.x = (sqar->m_TriangleVertex[0].m_Vertex[0].x + sqar->m_TriangleVertex[0].m_Vertex[1].x)/2;
		pos_goal2D.y = (sqar->m_TriangleVertex[0].m_Vertex[0].z + sqar->m_TriangleVertex[0].m_Vertex[2].z)/2;
	/*	pos_goal2D.x -= 5/16;
		pos_goal2D.y -= 5/16;*/

		D3DXVECTOR2 Dis = pos_goal2D - pos_coli2D;


		if(D3DXVec2Length(&Dis) < 1.0f
			//&&m_isReflected == false
			)
		{
			D3DXVECTOR2 velo2;
			velo2.x = velo->x;
			velo2.y = velo->z;
			if(D3DXVec2Length(&velo2) < 0.5f)
			{	
				return true;
			}
			else
			{
				velo->x += Dis.x*((1-D3DXVec2Length(&Dis))/10);
				velo->z += Dis.y*((1-D3DXVec2Length(&Dis))/10);	
				velo->y = D3DXVec2Length(&velo2)/2;
			}
		}
		else
		{
			velo->x *= 0.6f;
			velo->y *= 0.4f;
			velo->z *= 0.6f;
		}
	}

	return false;
}
Beispiel #5
0
/**
* CCamera::rotateCamera
* date Modified March 27, 2006
*/
void CCamera::rotateCamera(float fRot)
{
	//update the rotation
	m_fRotation += fRot;

	// if the rotation overlaps, fix it
	if(m_fRotation >= 2*M_PI)
		m_fRotation -= 2*M_PI;
	else if(m_fRotation <= -2*M_PI)
		m_fRotation += 2*M_PI;

	// trig it up, i hate matrix math.
	float fCameraDist = D3DXVec2Length(&(D3DXVECTOR2(m_TargToPos.x, m_TargToPos.z))); 
	m_Position.x = fCameraDist * sin(m_fRotation) + m_Target.x;
	m_Position.z = fCameraDist * cos(m_fRotation) + m_Target.z;

	// recompute the vector from the target to the camera position
	m_TargToPos = m_Position - m_Target;
	D3DXVec3Normalize(NULL, &m_UnitTargPos, &(m_Target - m_Position));

	// compute the new at and right of the camera
	m_AtVector = m_Target - m_Position;
	m_AtVector.y = 0;
	D3DXVec3Normalize(NULL, &m_AtVector, &m_AtVector);
	D3DXVec3Cross(&m_RightVector, &m_UpVector, &m_AtVector);
	D3DXVec3Normalize(NULL, &m_RightVector, &m_RightVector);
}
bool CObjCHAR_Collision::ReviseMonsterPosition(tagCYLINDERINFO *Cylinder)
{

	float distance;
	
	distance = sqrtf( (m_vCurrent.x - Cylinder->m_Position.x)*(m_vCurrent.x - Cylinder->m_Position.x) + (m_vCurrent.y - Cylinder->m_Position.y)*(m_vCurrent.y - Cylinder->m_Position.y) );  
	if(distance < Cylinder->m_fRadius)
	{
        float dir_[3];
		D3DXVECTOR2 v1,v2;
		D3DXVECTOR2 direction, p;
		float a,b,d,t;
		
		::getModelDirectionVector(m_hNodeModel, dir_);
				
		v1 = (D3DXVECTOR2)m_vCurrent - (D3DXVECTOR2)Cylinder->m_Position;
		v2.x = dir_[0]; v2.y = dir_[1]; 
		v2 /= D3DXVec2Length(&v2);
		direction = v1 - D3DXVec2Dot(&v1,&v2)*v2;
		
		if(D3DXVec2Length(&direction) < 0.001f)
		{
			direction.x = -v2.y;
			direction.y = v2.x;
		}
		direction/=D3DXVec2Length(&direction);
		p = (D3DXVECTOR2)m_vCurrent - (D3DXVECTOR2)Cylinder->m_Position;

		a= D3DXVec2Dot(&direction,&p);
		b= D3DXVec2Dot(&p,&p);
		d= Cylinder->m_fRadius * Cylinder->m_fRadius;
		t = -a + sqrtf(a*a+d-b); 

		if(t<0.0f)
			t=0.0f; 
		else
		{
		    m_vCurrent.x += (t+5)*direction.x;
			m_vCurrent.y += (t+5)*direction.y;
		}
	    
		return true;
       
	}

	return false;
}
void ObjectStaticWeaponCloseState::onUpdate()
{
    ObjectState::onUpdate();

    if (currentFramecount >= frameDelay)
    {
        D3DXVECTOR2 playerPos(pData->playerX, pData->playerY);
        D3DXVECTOR2 selfPos(pData->x + 16, pData->y + 16);
        D3DXVECTOR2 directVector = playerPos - selfPos;
        float length1 = D3DXVec2Length(&directVector);
        float length = length1;

        if (UIComponents::getInstance()-> getNumberPlayer() == 2)
        {
            playerPos = D3DXVECTOR2(pData->player2X, pData->player2Y);
            directVector = playerPos - selfPos;
            float length2 = D3DXVec2Length(&directVector);
            length = length1 > length2 ? length1 : length2;
        }

        if (length <= OBJECT_STATIC_WEAPON_RANGE_OPEN)
        {
            transition(new ObjectStaticWeaponPreparingState(this->pData, true));
            return;
        }

        /*if (((ObjectStaticWeaponData*)pData)->isUp)
        {
            if (this->pData->playerX - this->pData->x >= -OBJECT_STATIC_WEAPON_RANGE_OPEN)
            {
                this->pData->pState = new ObjectStaticWeaponPreparingState(this->pData, true);
            }
        }
        else
        {
            if (this->pData->playerX - this->pData->x >= -OBJECT_STATIC_WEAPON_RANGE_OPEN)
            {
                this->pData->pState = new ObjectStaticWeaponPreparingState(this->pData, true);
            }
        }*/
    }
    else
    {
        currentFramecount++;
    }
}
Beispiel #8
0
 bool in_teritory(const Vector& v) {
     for (auto& s: stations_) {
         Vector d = s->location() - v;
         if (D3DXVec2Length(&d) < 50.0f) {
             return true;
         }
     }
     return false;
 }
Beispiel #9
0
bool CBullet::TestCollision( const CLiveObject& obj ) const
{
	// вектор от одного объекта до другого
	D3DXVECTOR2 dist = obj.Pos() - Pos();

	// если расстояние меньше или равно сумме радиусов
	if (obj.Radius()>=D3DXVec2Length(&dist))
		return true; // столкновение

	return false; // иначе нет
}
void GuiSlider::onMessage(gui::Message* message)
{
    // anywhere onMouseUp
    if( message->event == gui::onMouseUp )
    {
        if( _scrolling ) _scrolling = false;
    }

    // anywhere onMouseMove if scrolling is enabled
    if( _scrolling && message->event == gui::onMouseMove )
    {
        // slider vector
        Flector sliding( float(_upperRect.left - _lowerRect.left), float(_upperRect.top - _lowerRect.top) );
        Flector slidingN;
        D3DXVec2Normalize( &slidingN, &sliding );
        // motion offset
        Flector offset( float( Gui::instance->getMouseDX() ), float( Gui::instance->getMouseDY() ) );
        // motion offset in slider space
        Flector slidingOffset = slidingN * D3DXVec2Dot( &slidingN, &offset );
        // parametric motion offset (0..1)
        float pSlidingOffset = D3DXVec2Length( &slidingOffset ) / D3DXVec2Length( &sliding );
        if( D3DXVec2Dot( &slidingN, &offset ) < 0 ) pSlidingOffset *= -1;
        // final update
        setPosition( getPosition() + pSlidingOffset * getUpperLimit() - getLowerLimit() );

        // messaging
        gui::Message message;
        message.origin = this;
        message.event = gui::onSlide;
        Gui::instance->pushMessage( &message );
    }

    // mousedown from scroll button
    if( _scrollButton && 
        message->event == gui::onMouseDown && 
        message->origin == _scrollButton->getPanel() )
    {    
        _scrolling = true;
    }
}
Beispiel #11
0
//=============================================================================
// is hit line
//=============================================================================
bool CollisionPoint::IsHitLine(const D3DXVECTOR2& position,const D3DXVECTOR2& start,const D3DXVECTOR2& end)const
{
	D3DXVECTOR2 vector_l = end - start;
	D3DXVECTOR2 vector_a = position_ - (start + position);
	D3DXVECTOR2 vector_b = position_ - (end + position);
	f32 cross = D3DXVec2CCW(&vector_l,&vector_a);

	if(cross <= 0.0001f || cross >= -0.0001f)
	{
		cross = 0.0f;
	}

	if(cross == 0.0f)
	{
		if(D3DXVec2Dot(&vector_a,&vector_l) >= 0 && D3DXVec2Length(&vector_l) >= D3DXVec2Length(&vector_a))
		{
			return true;
		}
	}

	return false;
}
Beispiel #12
0
//=============================================================================
// is hit line
//=============================================================================
bool CollisionCircle::IsHitLine(const D3DXVECTOR2& position,const D3DXVECTOR2& start,const D3DXVECTOR2& end)const
{
	D3DXVECTOR2 vector_l = end - start;
	D3DXVECTOR2 vector_a = position_ - (start + position);
	D3DXVECTOR2 vector_b = position_ - (end + position);
	f32 distance = D3DXVec2CCW(&vector_l,&vector_a) / D3DXVec2Length(&vector_l);

	if(distance <= radius_)
	{
		if(D3DXVec2Dot(&vector_a,&vector_l) * D3DXVec2Dot(&vector_b,&vector_l) <= 0)
		{
			return true;
		}

		if(D3DXVec2Length(&vector_a) <= radius_ || D3DXVec2Length(&vector_b) <= radius_)
		{
			return true;
		}
	}

	return false;
}
Beispiel #13
0
/**
*
* A polygon must be constructed that will cover an entire button.
* This function determines the length of each side of the polygon, to ensure complete coverage of a button.
*
* @author Jade Abbott
* @return Void.
*
*/
void
CRadialMenu::CalculateOuterPlanarLength()
{
	assert(m_ucNumButtons >= 3);
	assert(m_uiDiameter);

	float fRadius = m_uiDiameter * 0.5f;

	// Get the distance from the centre of the Radial Menu to the outer plane that will cover an entire button (requires two, but each vertex has the same length).
	float fAngle = ((2.0f * MathUtility::PI) / m_ucNumButtons) * 0.5f;	// Angle of this line.

	// From (0.0f, -fRadius), see where fAngle intersects the Y plane.
	float fScalar = cosf(fAngle) / fRadius;	// Percentage of distance covered.
	
	m_fOuterPlanarLength = D3DXVec2Length(&D3DXVECTOR2(fRadius, sinf(fAngle) / fScalar));
}
void Boss2FinalArmWaveState::moveAround(Boss2FinalJoint* joint, Boss2FinalJoint* joint0, float deltaRadius,
                                                float speed, float frame,Boss2FinalJoint::MoveAroundDirection dir, float delay)
{
    float x = joint0->getBody().x + joint0->getBody().width / 2;
    float y = joint0->getBody().y + joint0->getBody().height / 2;

    float x2 = joint->getBody().x + joint->getBody().width / 2;
    float y2 = joint->getBody().y + joint->getBody().height / 2;

    D3DXVECTOR2 dist(x - x2, y - y2);

    //joint ngoai cung se dung lai truoc joint trong cung va hand dung lai dau tien
    //thu hep khoang cach cua joint va hand lai vi xoay khoang cach bi gian ra
    //de tao hieu ung wave thi van toc cua cac joint phai khac nhau va joint trong cung di chuyen nhanh nhat
    joint->moveAround(x, y, D3DXVec2Length(&dist) - deltaRadius, frame, speed, dir, delay);
}
Beispiel #15
0
bool MENU_BaseObject::HeadTowardVector( D3DXVECTOR2* pObjectToMove, D3DXVECTOR2* pDestination, float fTime, float fSpeed )
{
	D3DXVECTOR2 vDirection = *pDestination - *pObjectToMove;
	float fDistance= D3DXVec2Length(&vDirection);

	// has it reached the destination
	if ( fDistance <= 1.0f)
		return true;

	D3DXVECTOR2 vNormDirection;
	D3DXVec2Normalize(&vNormDirection, &vDirection);

	pObjectToMove->x+= fTime * (fSpeed * vNormDirection.x);
	pObjectToMove->y+= fTime * (fSpeed * vNormDirection.y);

	return false;
}
Beispiel #16
0
void Projectile::Update( float _dt )
{
	// Add the current velocity to the position.
	this->SetPos(this->GetPos() + this->GetVel() * _dt);
	this->SetVel(this->GetVel() * 0.99f);
	
	// Cap max speed
	if(D3DXVec2Length(&this->GetVel()) > this->GetMaxSpeed())
	{
		D3DXVECTOR2 cappedVel;
		D3DXVec2Normalize(&cappedVel,&this->GetVel());
		cappedVel *= this->GetMaxSpeed();
		this->SetVel(cappedVel);
	}

	D3DXVECTOR2 vel = this->GetDir() * this->GetMaxSpeed();
	this->SetVel(vel);

	if( m_IsHoming )
	{
		// TODO:: this is for player only, change for AI.
		if(m_Target != nullptr && m_Target->GetIsAlive())
		{
			TurnToTarget(_dt);
			// TODO:: also leave smoke trail
		}
		else
		{
			if(this->m_Owner->GetType() == Entity_PlayerShip)
				m_Target = AIManager::GetInstance()->GetClosestEnemy(this->GetPos());
			else
				m_Target = AIManager::GetInstance()->GetTarget();
		}

		m_SmokeTrailEmitter->Update(_dt*2.0f, GetPos().x, GetPos().y - GetDir().y*16);
	}

	

	m_Life -= _dt;
	if(m_Life <= 0.0f)
	{
		m_Life = 5.0f;
		this->SetIsAlive(false);
	}
}
Beispiel #17
0
void Homing::Move(float dtime)
{
	D3DXVECTOR2 dir = m_pTarget->GetPosition() - m_pSelf->GetPosition();
	float distance = D3DXVec2Length(&dir);
	if (distance > 10)
	{
		D3DXVec2Normalize(&dir, &dir);
		D3DXVECTOR2 curDir = D3DXVECTOR2(cos(m_pSelf->GetAngle()), sin(m_pSelf->GetAngle()));

		D3DXVECTOR2 alteredDir; 
		D3DXVec2Lerp(&alteredDir, &curDir, &dir, m_TurningSpeed);
		float alteredAngle = atan2(alteredDir.y, alteredDir.x);

		//update angle and position
		m_pSelf->SetRotation(alteredAngle);
		m_pSelf->SetPosition(m_pSelf->GetPosition() + (D3DXVECTOR2(cos(alteredAngle), sin(alteredAngle)) * m_MoveSpeed * dtime));
	}
}
Beispiel #18
0
void MENU_BaseObject::HeadTowards( D3DXVECTOR2* pDestination , float fTime)
{
	D3DXVECTOR2 vDirection = *pDestination - D3DXVECTOR2(m_rBoundingBox->m_fX, m_rBoundingBox->m_fY);
	float fDistance= D3DXVec2Length(&vDirection);

	// has it reached the destination
	if ( fDistance <= 1.0f)
	{
		m_rBoundingBox->m_fX= m_pCurrentMovementPoint->x;
		m_rBoundingBox->m_fY= m_pCurrentMovementPoint->y;
		
		NextPoint();
		return;
	}

	D3DXVECTOR2 vNormDirection;
	D3DXVec2Normalize(&vNormDirection, &vDirection);

	m_rBoundingBox->m_fX+= fTime * (m_fMovementSpeed * vNormDirection.x);
	m_rBoundingBox->m_fY+= fTime * (m_fMovementSpeed * vNormDirection.y);
}
	//=============================================================================================================
	void CLensFlareRenderer9::Draw()
	{
		if( !CanBeApplied() )
			return;

		// a nézeti mátrix elsö oszlopa a nézési irány
		viewdir.x = View._13;
		viewdir.y = View._23;
		viewdir.z = View._33;

		lightpos = Eye + Sun;
		vdotl = D3DXVec3Dot(&viewdir, &lightpos);

		// ha háttal vagyunk a fénynek akkor nincs mit rajzolni
		if( vdotl / D3DXVec3Length(&lightpos) < 0 ) return;
		D3DXVec3Project(&lightpos, &lightpos, &viewport, &Projection, &View, &id);

		ctol.x = lightpos.x - center.x;
		ctol.y = lightpos.y - center.y;

		length = D3DXVec2Length(&ctol);
		alpha = 1.0f - (length / halfdiagonal);

		// ha valami eltakarja a fényforrást
		etos = Sun;
		D3DXVec3Normalize(&etos, &etos);

		for( occluderlist::iterator it = occluders.begin(); it != occluders.end(); ++it )
		{
			etoc = it->center - Eye;
			dist = D3DXVec3Length(&etoc);

			D3DXVec3Normalize(&etoc, &etoc);
			cosa = D3DXVec3Dot(&etoc, &etos);

			x = cosa * dist;
			rad = dist * dist - x * x;

			rad /= (it->radius * it->radius);
			alpha *= min(1, rad * rad);
		}

		color.a = min(1, alpha);
		D3DXVec2Normalize(&ctol, &ctol);

		// render
		manager->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
		manager->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
		manager->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);

		for( int i = 0; i < _FLARECOUNT_; ++i )
		{
			scaleddir = center + ctol * length * flares[i].scale;

			D3DXMatrixScaling(&scale, flares[i].size, flares[i].size, 1);
			D3DXMatrixTranslation(&translate, scaleddir.x - flares[i].size * 0.5f, scaleddir.y - flares[i].size * 0.5f, 0);
			D3DXMatrixMultiply(&transform, &scale, &translate);

			manager->SetTexture(0, lens[flares[i].index]);
			game->DrawImage(transform, color);
		}

		manager->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
	}
Beispiel #20
0
/** Puts trasformation for the given spots */
void GVegetationBox::InitSpotsRandom(const std::vector<D3DXVECTOR3>& trisInside, EShape shape, float density)
{
	D3DXVECTOR3 mid = BoxMin * 0.5f + BoxMax * 0.5f;
	D3DXVECTOR3 bs = (BoxMax - BoxMin);
	float rad = std::min(bs.x, bs.z) / 2.0f;

	delete InstancingBuffer; InstancingBuffer = NULL;
	delete GrassCB; GrassCB = NULL;
	VegetationSpots.clear();

	// Find random spots on the polygons (TODO: This is still based off the size of the polygons!)
	std::vector<D3DXVECTOR3> spots;
	for(unsigned int i=0;i<trisInside.size();i+=3)
	{
		for(unsigned int d=0;d<std::max(1.0f, 30 * density);d++)
		{
			D3DXVECTOR3 tri[] = {   trisInside[i], 
									trisInside[i+1], 
									trisInside[i+2]};


			float b0 = Toolbox::frand();
			float b1 = ( 1.0f - b0 ) * Toolbox::frand();
			float b2 = 1 - b0 - b1;

			D3DXVECTOR3 rnd = tri[0] * b0
					 + tri[1] * b1
					 + tri[2] * b2;

			// Get 2 random points on the edges
			/*D3DXVECTOR3 rp[3];
			D3DXVec3Lerp(&rp[0], &tri[0], &tri[1], Toolbox::frand());
			D3DXVec3Lerp(&rp[1], &tri[0], &tri[2], Toolbox::frand());

			// Get the last point on that random made edge
			D3DXVec3Lerp(&rp[2], &rp[0], &rp[1], Toolbox::frand());*/

			if(PositionInsideBox(rnd))
			{
				if(shape == S_Circle) // Restrict to smalles circle inside our AABB
				{
					D3DXVECTOR2 m2 = D3DXVECTOR2(mid.x, mid.z);
					float dist = D3DXVec2Length(&(D3DXVECTOR2(rnd.x, rnd.z) - m2));

					if(dist >= rad)
						continue;
				}

				spots.push_back(rnd);
			}
		}
	}


	// Create the transformation matrices for every spot
	for(unsigned int i=0;i<spots.size();i++)
	{
		D3DXMATRIX w;
		D3DXMATRIX s;
		D3DXMATRIX r;
		D3DXMatrixTranslation(&w, spots[i].x, spots[i].y, spots[i].z);
		float scale = Toolbox::lerp(20, 80, Toolbox::frand());
		D3DXMatrixScaling(&s, scale,scale,scale);
		D3DXMatrixRotationY(&r, Toolbox::frand() * (float)D3DX_PI * 2.0f);

		w = r * s * w;

		D3DXMatrixTranspose(&w, &w);

		VegetationSpots.push_back(w);
	}

	if(VegetationSpots.empty())
	{
		return;
	}

	// Create instancing buffer for this box
	Engine::GraphicsEngine->CreateVertexBuffer(&InstancingBuffer);
	InstancingBuffer->Init(&VegetationSpots[0], VegetationSpots.size() * sizeof(D3DXMATRIX));

	// Create constant buffer
	Engine::GraphicsEngine->CreateConstantBuffer(&GrassCB, NULL, sizeof(GrassConstantBuffer));

	RefitBoundingBox();

	Density = density;
	return;
}
Beispiel #21
0
/*
 * checks if two bounding boxes (obb's) intersect.
*/
 bool BoundingBox::intersects(BoundingBox* box2)
{
	float first_l, second_l, first_m, second_m;
	float dist1, dist2;

	// compute sphere radius for first box - find longest diagonal
	if (half_x > half_y) { 
		first_l = half_x;
		second_l = half_y;
	}
	else {
		first_l = half_y;
		second_l = half_x;
	}
	if (half_z > first_l) {
		second_l = first_l;
		first_l = half_z;
	}
	else
		if (half_z > second_l) 
			second_l = half_z;
		
	//compute sphere radius for second box - find longest diagonal
	if (box2->getHalfX() > box2->getHalfY()) { 
		first_m = box2->getHalfX();
		second_m = box2->getHalfY();
	}
	else {
		first_m = box2->getHalfY();
		second_m = box2->getHalfX();
	}
	if (box2->getHalfZ() > first_m) {
		second_m = first_m;
		first_m = box2->getHalfZ();
	}
	else
		if (box2->getHalfZ() > second_m) 
			second_m = box2->getHalfZ();
		
	D3DXVECTOR2 vec2;
	D3DXVECTOR3 vec3;

	vec2.x = first_l;
	vec2.y = second_l;

	dist1 = D3DXVec2Length(&vec2);

	vec2.x = first_m;
	vec2.y = second_m;

	dist2 = D3DXVec2Length(&vec2);

	vec3.x = center.x - box2->getCenter().x;
	vec3.y = center.y - box2->getCenter().y;
	vec3.z = center.z - box2->getCenter().z;

	float min_n, max_n, min_m, max_m;

	// test for box1 axis
	for (int i=0; i<3; i++)
	{
		getAxisProjection(getDirAxis(i), this, min_m, max_m);
		getAxisProjection(getDirAxis(i), box2, min_n, max_n);
		if (max_n < min_m || max_m < min_n)
			return false;
	}
	
	// test for box2 axis
	for (int i=0; i<3; i++)
	{
		getAxisProjection(box2->getDirAxis(i), this, min_m, max_m);
		getAxisProjection(box2->getDirAxis(i), box2, min_n, max_n);
		if (max_m < min_n || max_n < min_m)
			return false;
	}

	// test for combined axis
	D3DXVECTOR3 vOut;
	for (int i=0; i<3; i++)
	{
		for (int j=0; j<3; j++)
		{
			D3DXVec3Cross(&vOut, &(getDirAxis(i)), &(box2->getDirAxis(i)));
			getAxisProjection(vOut, this, min_m, max_m);
			getAxisProjection(vOut, box2, min_n, max_n);
			if (max_m < min_n || max_n < min_m)
				return false;
		}
	}
	
	return true;
}
Beispiel #22
0
//@}
//-------------------------------------------------------------------------
/// @name 幾何ベクトルの大きさ
//@{
/// @copydoc psyq::geometry::vector::length
inline psyq::geometry::vector::traits<D3DXVECTOR2>::element length(
    D3DXVECTOR2 const& in_vector)
{
    return D3DXVec2Length(&in_vector);
}
Beispiel #23
0
void EFFECT_LENSFLARE::Render()
{
	if(sprite == NULL || lensflareTexture == NULL)return;

	RECT sourceRectangles[7] = {{0, 0, 128, 128},
								{128, 0, 256, 128},
								{0, 128, 128, 256},
								{128, 128, 192, 192},
								{192, 128, 256, 192},
								{128, 192, 192, 256},
								{192, 192, 256, 256}};

	//Calculate screen position of light source
	D3DXVECTOR3 screenPos;
	D3DVIEWPORT9 Viewport;
	D3DXMATRIX Projection, View, World;
	m_pDevice->GetViewport(&Viewport);
	m_pDevice->GetTransform(D3DTS_VIEW, &View);
	m_pDevice->GetTransform(D3DTS_PROJECTION, &Projection);
	D3DXMatrixIdentity(&World);
	D3DXVec3Project(&screenPos, &m_position, &Viewport, &Projection, &View, &World);

	//Get viewport
	D3DVIEWPORT9 v;
	m_pDevice->GetViewport(&v);

	//Check that light source is within or without the screen bounds
	if(screenPos.x < 0 || screenPos.x > v.Width ||
	   screenPos.y < 0 || screenPos.y > v.Height || screenPos.z > 1.0f)
		m_inScreen = false;
	else m_inScreen = true;

	//Lensflares aren't visible so exit function...
	if(m_mainAlpha <= 0.0f)return;
	
	//Calculate the ray from the screen center to the light source
	D3DXVECTOR2 lightSource = D3DXVECTOR2(screenPos.x, screenPos.y);
	D3DXVECTOR2 screenCenter = D3DXVECTOR2(v.Width * 0.5f, v.Height * 0.5f);
	D3DXVECTOR2 ray = screenCenter - lightSource;

	//Draw the different flares
	D3DXMATRIX sca;
	sprite->Begin(D3DXSPRITE_ALPHABLEND);
	for(int i=0;i<(int)m_flares.size();i++)
	{
		//Calculate Flare position in screen coordinates
		RECT r = sourceRectangles[m_flares[i].sourceFlare];
		D3DXVECTOR2 offset = D3DXVECTOR2((r.right - r.left) / 2.0f, (r.bottom - r.top) / 2.0f) * m_flares[i].scale;
		D3DXVECTOR2 flarePos = lightSource + ray * m_flares[i].place - offset;

		//Scale
		D3DXMatrixScaling(&sca, m_flares[i].scale, m_flares[i].scale, 1.0f);

		//Calculate flare alpha
		D3DXCOLOR m_color = m_flares[i].m_color;
		float alpha = (D3DXVec2Length(&((flarePos + offset) - screenCenter)) + 150.0f) / (float)v.Height;
		if(alpha > 1.0f)alpha = 1.0f;
		m_color.a = alpha * m_mainAlpha * 1.5f;

		//Draw Flare
		sprite->SetTransform(&sca);
		sprite->Draw(lensflareTexture, &r, NULL, &D3DXVECTOR3(flarePos.x / m_flares[i].scale, flarePos.y / m_flares[i].scale, 0.0f), m_color);
	}
	sprite->End();

	D3DXMatrixIdentity(&sca);
	sprite->SetTransform(&sca);
}
void Manipulator::UpdateState(Manipulator::MeshPtr mesh, const D3DXVECTOR2& direction, 
    const Matrix& world, const Matrix& invProjection, bool pressed, float deltatime)
{
    if(m_selectedTool == NONE)
    {
        return;
    }

    // Ensure the tool axis are aligned with the mesh axis
    std::for_each(m_tools[m_selectedTool]->axis.begin(), 
        m_tools[m_selectedTool]->axis.end(), [&mesh](const MeshPtr& axis)
    {
        axis->SetRotationMatrix(mesh->GetRotationMatrix());
    });

    if(pressed)
    {
        if(m_selectedAxis != NO_AXIS && D3DXVec2Length(&direction) > 0.0f)
        {
            D3DXVECTOR3 axis;
            switch(m_selectedAxis)
            {
            case X_AXIS:
                axis = mesh->Right();
                break;
            case Y_AXIS:
                axis = mesh->Up();
                break;
            case Z_AXIS:
                axis = mesh->Forward();
                break;
            }

            D3DXVECTOR3 mouseDirection(direction.x, direction.y, CAMERA_NEAR);
            mouseDirection.x *= -1.0f;

            // Transform the screen space mouse direction into global 3D coordinates
            // Camera world matrix is the inverse view matrix
            D3DXVec3TransformNormal(&mouseDirection, &mouseDirection, &invProjection.GetMatrix());
            D3DXVec3TransformNormal(&mouseDirection, &mouseDirection, &world.GetMatrix());

            D3DXVec3Normalize(&mouseDirection, &mouseDirection);
            D3DXVec3Normalize(&axis, &axis);

            const float dot = D3DXVec3Dot(&axis, &mouseDirection);
            const float angle = RadToDeg(std::acos(dot));
            const float speed = fabs(dot) * (angle > 90.0f ? -1.0f : 1.0f) * deltatime;

            if(m_engine->diagnostic()->AllowDiagnostics(Diagnostic::MESH))
            {
                m_engine->diagnostic()->UpdateLine(Diagnostic::MESH,
                    "MouseDirection3D", Diagnostic::WHITE, mesh->Position(),
                    mesh->Position() + mouseDirection * 20.0f);

                m_engine->diagnostic()->UpdateText(Diagnostic::MESH,
                    "MovementDot", Diagnostic::WHITE, StringCast(dot));

                m_engine->diagnostic()->UpdateText(Diagnostic::MESH,
                    "MovementAngle", Diagnostic::WHITE, StringCast(angle));
            }

            switch(m_selectedTool)
            {
            case ROTATE:
                RotateMesh(mesh, speed * ROTATION_SPEED);
                break;
            case MOVE:
                mesh->ResetAnimation();
                TranslateMesh(mesh, speed * TRANSLATION_SPEED);
                break;
            case SCALE:
                ScaleMesh(mesh, speed * SCALE_SPEED);
                break;
            case ANIMATE:
                AnimateMesh(mesh, speed * TRANSLATION_SPEED);
                break;
            }
        }
    }

    if(m_selectedTool == ANIMATE)
    {
        if(mesh->GetAnimationPoints().empty() || (!pressed && m_saveAnimation))
        {
            m_saveAnimation = false;
            mesh->SavePosition();
        }
    }
}
Beispiel #25
0
HRESULT World::frameMove( double dTime, float fElapsedTime )
{
    EpCamera& camera = GetG().m_camera;
    HRESULT hr = S_OK;
    if ( m_bNotEntered )
    {
        enter();
        m_bNotEntered = false;
    }
    m_pic.frameMove(fElapsedTime);
    m_avatar.frameMove(fElapsedTime);
    //camera.frameMove(fElapsedTime);

    if ( m_sound )
        m_sound->UpdateAudio();

    DialogList::iterator itDialog = m_scriptedDialog.begin();
    for ( ; itDialog != m_scriptedDialog.end(); ++itDialog )
    {
        (*itDialog)->frameMove( dTime, fElapsedTime );
    }

    //GetG().m_camera.frameMove( fElapsedTime );

    m_sampleTeapotMeshRot += fElapsedTime * D3DXToRadian(35); // 35 degrees per second

    GetWorldStateManager().transit( dTime );
    GetWorldStateManager().getCurState()->frameMove(dTime, fElapsedTime);

    m_modelSg->getSceneRoot()->update(dTime, fElapsedTime);

    WCHAR msg[128];

    StringCchPrintf( msg, 128, L"Hero Pos : (%.2f, %.2f, %.2f)\n",
                     m_heroUnit->getPos().x,
                     m_heroUnit->getPos().y,
                     m_heroUnit->getPos().z );
    g_debugBuffer.append( msg );

    StringCchPrintf( msg, 128, L"Hero TilePos : (%d, %d)\n",
                     m_heroUnit->getTilePosX(),
                     m_heroUnit->getTilePosY() );
    g_debugBuffer.append( msg );

    ArnVec3 diff = m_heroUnit->getPos() - *GetG().m_camera.GetEyePt();
    StringCchPrintf( msg, 128, L"Hero - Camera Pos : (%.4f, %.4f, %.4f)\n",
                     diff.x, diff.y, diff.z );
    g_debugBuffer.append( msg );


    if ( D3DXVec2Length( (const D3DXVECTOR2*)&diff ) > 0.001f)
    {
        // Check for camera and character move inconsistency when field state
        //DebugBreak();
    }

    if ( ((Hero*)getHeroUnit())->isEncounterEnemy() && GetWorldStateManager().curStateEnum() != GAME_WORLD_STATE_BATTLE )
        battleEventCheck();

    wannaTalkingEventCheck();

    // Incidents update
    IncidentList::iterator itInc = m_incidents.begin();
    for ( ; itInc != m_incidents.end(); ++itInc )
    {
        (*itInc)->update( dTime, fElapsedTime );
    }

    UnitSet::iterator it2 = m_unitSet.begin();
    for ( ; it2 != m_unitSet.end(); ++it2 )
    {
        (*it2)->frameMove( dTime, fElapsedTime );

        // TODO:
        // Any registered units will not be deallocated automatically
        // until the world destructed.
    }
    return hr;
}
Beispiel #26
0
void SpherePopup::Update()
{
	D3DXVECTOR3 t;
	auto vp = GraphicsEngine::GetViewport();
	viewport.Width = vp.Width;
	viewport.Height = vp.Height;
	D3DXVec3Project(&t, &worldPos, &viewport, &projection, &view, &world);
	windowWP.x = t.x;
	windowWP.y = t.y;

	D3DXVECTOR4 t4;
	t = worldPos;
	t.y = 0;
	D3DXVec3Normalize(&t, &t);
	D3DXVec3Transform(&t4, &t, &world);
	
	if (animationState > .99f && t4.z <= .5f)
	{
		animationMultiplier = -1;
	}

	if (animationState < 0)
		isDead = true;

	if (animationState < 0.3333f)
	{
		if (windowPos.x < Window::GetWidth() / 2)//line should go to the right top corner
			animationState += animationMultiplier * .3333f * 10 / D3DXVec2Length(&(windowWP - windowPos2));
		else
			animationState += animationMultiplier * .3333f * 10 / D3DXVec2Length(&(windowWP - windowPos));
	}
	else if (animationState < 0.6666f)
	{
		animationState += animationMultiplier * .3333f * 10 / 192;
	}
	else
	{
		animationState += animationMultiplier * .3333f * 10 / 128;
		if (animationState > 1)
		{
			animationState = 1;
			animationMultiplier = 0;
		}
	}

	float s1 = animationState * 3,
		s2 = animationState * 3 - 1,
		s3 = animationState * 3 - 2;

	vLines[0] = windowWP.x;
	vLines[1] = windowWP.y;
	vLines[3] = lerp(windowWP.y, windowPos.y, s1);
	vLines[5] = vLines[7] = vLines[9] = vLines[19] = vWindow[1] = vWindow[5] = windowPos.y;
	vLines[11] = vLines[13] = vLines[15] = vLines[17] = vWindow[3] = vWindow[7] = lerp(windowPos.y, windowPos2.y, s3);

	if (windowPos.x < Window::GetWidth() / 2)//line should go to the right top corner
	{
		vLines[2] = lerp(windowWP.x, windowPos2.x, s1);
		vLines[4] = vLines[14] = vLines[16] = vLines[18] = vWindow[4] = vWindow[6] = windowPos2.x;
		vLines[6] = vLines[8] = vLines[10] = vLines[12] = vWindow[0] = vWindow[2] = lerp(windowPos2.x, windowPos.x, s2);
	}
	else
	{
		vLines[2] = lerp(windowWP.x, windowPos.x, s1);
		vLines[4] = vLines[14] = vLines[16] = vLines[18] = vWindow[0] = vWindow[2] = windowPos.x;
		vLines[6] = vLines[8] = vLines[10] = vLines[12] = vWindow[4] = vWindow[6] = lerp(windowPos.x, windowPos2.x, s2);
	}

	if (s3 > 0)
	{
		vWindow[3]--;
		vWindow[4]--;
		vWindow[6]--;
		vWindow[7]--;
	}

	meshLines->SetRawData(vLines, 20, 20 * sizeof(float), 2 * sizeof(float));
	meshWindow->SetRawData(vWindow, 8, 8 * sizeof(float), 2 * sizeof(float));
}
Beispiel #27
0
float length(const Vec2 &v)
{
	return D3DXVec2Length(&v);
}
/**
* State machine
*/
bool SMRandomPath::States( State_Machine_Event event, MSG_Object* msg, int state, int substate )
{
BeginStateMachine

	// global message responses
    OnMsg(MSG_Damaged)

        // update health and seek player
        m_owner->SetHealth( m_owner->GetHealth() - msg->GetIntData() );
        PushStateMachine( *new SMCombat( m_owner, g_database.Find(m_idPlayer)->GetID(), true) );

    OnMsg(MSG_Reset)

        // reset machine
        ChangeState(STATE_PickPath);

    /*-------------------------------------------------------------------------*/

    DeclareState( STATE_PickPath )
    
        OnEnter

            // start path computation request
            g_world.AddPathRequest(m_owner->GetGridPosition(), g_world.GetRandomMapLocation(), m_owner->GetID());

        OnMsg(MSG_PathComputed)

            // follow path
            ChangeStateDelayed(1.0f, STATE_FollowPath);

    /*-------------------------------------------------------------------------*/
	
    DeclareState( STATE_FollowPath )
	
        OnEnter

            // set velocity
            m_owner->SetVelocity(5.0f);
            m_owner->SetAcceleration(0.5f);

        OnUpdate

            PathWaypointList* waypointList = g_world.GetWaypointList(m_owner->GetID());

            // check if player nearby               
            D3DXVECTOR3 vPlayerDist = m_owner->GetPosition() - g_database.Find(m_idPlayer)->GetPosition();
            if( D3DXVec3Length( &vPlayerDist ) < 4.0f && g_database.Find(m_idPlayer)->GetHealth() > 0 )
            {
                ChangeState( STATE_SwitchToCombat );
            }

            // if out of waypoints, pick new path
            else if(waypointList->empty())
            {
                ChangeState( STATE_PickPath );
            }            
                
            // move towards waypoint
            else
            {
                // determine direction (ignore height)
                D3DXVECTOR2 vDirection = (*waypointList->begin()) - m_owner->GetGridPosition();

                // determine if the object has arrived
	            if( D3DXVec2Length( &vDirection ) < 0.1f )
                {
                    // pop off waypoint
                    waypointList->pop_front();
                }
                else
                {
                    // set object direction towards position
                    D3DXVec2Normalize(&vDirection, &vDirection);
                    m_owner->SetGridDirection(vDirection);
                }
            }

        OnExit

            // remove any waypoints
            g_world.ClearWaypointList(m_owner->GetID());

            // stop object
            m_owner->ResetMovement();

    /*-------------------------------------------------------------------------*/

    DeclareState( STATE_SwitchToCombat )

    	OnEnter
            
            // push combat state machine
            PushStateMachine( *new SMCombat( m_owner, g_database.Find(m_idPlayer)->GetID(), false) );

    /*-------------------------------------------------------------------------*/

EndStateMachine
}
HRESULT CPartParticle::Update(CPartEmitter* Emitter, DWORD CurrentTime, DWORD TimerDelta)
{
	if(m_State==PARTICLE_FADEIN)
	{
		if(CurrentTime - m_FadeStart >= m_FadeTime)
		{
			m_State = PARTICLE_NORMAL;
			m_CurrentAlpha = m_Alpha1;
		}
		else m_CurrentAlpha = ((float)CurrentTime - (float)m_FadeStart) / (float)m_FadeTime * m_Alpha1;

		return S_OK;
	}
	else if(m_State==PARTICLE_FADEOUT)
	{
		if(CurrentTime - m_FadeStart >= m_FadeTime)
		{
			m_IsDead = true;
			return S_OK;
		}
		else m_CurrentAlpha = m_FadeStartAlpha - ((float)CurrentTime - (float)m_FadeStart) / (float)m_FadeTime * m_FadeStartAlpha;

		return S_OK;
	}
	else
	{
		// time is up
		if(m_LifeTime > 0)
		{
			if(CurrentTime - m_CreationTime >= m_LifeTime)
			{
				if(Emitter->m_FadeOutTime > 0)
					FadeOut(CurrentTime, Emitter->m_FadeOutTime);
				else
					m_IsDead = true;
			}
		}
	
		// particle hit the border
		if(!m_IsDead && !IsRectEmpty(&m_Border))
		{
			POINT p;
			p.x = m_Pos.x;
			p.y = m_Pos.y;
			if(!PtInRect(&m_Border, p)) FadeOut(CurrentTime, Emitter->m_FadeOutTime);
		}
		if(m_State != PARTICLE_NORMAL) return S_OK;

		// update alpha
		if(m_LifeTime > 0)
		{
			int Age = CurrentTime - m_CreationTime;
			int AlphaDelta = m_Alpha2 - m_Alpha1;

			m_CurrentAlpha = m_Alpha1 + ((float)AlphaDelta / (float)m_LifeTime * (float)Age);
		}

		// update position
		float ElapsedTime = (float)TimerDelta/1000.f;

		for(int i=0; i<Emitter->m_Forces.GetSize(); i++)
		{
			CPartForce* Force = Emitter->m_Forces[i];
			switch(Force->m_Type)
			{
				case CPartForce::FORCE_GLOBAL:
					m_Velocity += Force->m_Direction * ElapsedTime;
					break;

				case CPartForce::FORCE_POINT:
					{
						D3DXVECTOR2 VecDist = Force->m_Pos - m_Pos;
						float Dist = fabs(D3DXVec2Length(&VecDist));
	
						Dist = 100.0f / Dist;

						m_Velocity += Force->m_Direction * Dist * ElapsedTime;
					}
					break;
			}			
		}
		m_Pos += m_Velocity * ElapsedTime;

		// update rotation
		m_Rotation += m_AngVelocity * ElapsedTime;
		m_Rotation = CBUtils::NormalizeAngle(m_Rotation);
		
		// update scale
		if(m_ExponentialGrowth)
			m_Scale += m_Scale / 100.0f * m_GrowthRate * ElapsedTime;
		else
			m_Scale += m_GrowthRate * ElapsedTime;

		if(m_Scale <= 0.0f) m_IsDead = true;


		return S_OK;
	}
}
Beispiel #30
0
//=============================================================================================================
void Avatar::Update()
{
    // robbanáskor mi történjen
    if( state & Exploded )
    {
        // lehetne az életet is nézni, de akkor eggyel elöbb hal
        bool alive = ((state & Invincible) == Invincible);

        // lejárt-e a várakozási idö
        if( flashticks > (unsigned)(alive ? 5 : 20) )
        {
            // nincs több élet, meghalt
            if( !alive )
            {
                dead();
            }
            // van még élet, egy kis idöre halhatatlan lesz
            else
            {
                flashticks = 0;
                power = 0;
                empowerticks = 0;
                Position = InitialPosition;

                DisableControls(false);
                state = Invincible;
            }
        }
        else
            ++flashticks;
    }
    else
    {
        // halhatatlan modban vagyunk
        if( state & Invincible )
        {
            // lejárt-e az idö
            if( flashticks > 25 )
            {
                flashticks = 0;
                state &= (~Invincible);
            }
            else
            {
                ++flashticks;

                // villogtatjuk
                if( flashticks % 4 == 0 )
                    drawornot = !drawornot;
            }
        }

        // felvett egy powerupot
        if( state & Empowered )
        {
            if( empowerticks > (size_t)power.count() + 1 )
                state &= (~Empowered);
            else
            {
                ++empowerticks;
                power.step();
            }
        }

        // találat érte, de a pajzs felfogta
        if( shieldticks <= shield.count() + 1 )
        {
            shield.step();
            ++shieldticks;
        }
    }

    // minden mennyiséget a felbontáshoz kell igazitani
    float maxvel = GameVariables::CorrelateH(Speed);
    float accel = GameVariables::CorrelateH(Acceleration);
    float resist = GameVariables::CorrelateH(Resistance);
    float length;

    direction.x = direction.y = 0;

    if( state & Forward )
        direction.x = (state & Backward ? 0.0f : 1.0f);
    else if( state & Backward )
        direction.x = -1;

    if( state & Up )
        direction.y = (state & Down ? 0.0f : -1.0f);
    else if( state & Down )
        direction.y = 1;

    D3DXVec2Normalize(&direction, &direction);
    velocity += direction * accel;

    D3DXVec2Normalize(&resistance, &velocity);
    length = D3DXVec2Length(&velocity);

    // max sebesség
    if( length > maxvel )
        velocity = resistance * maxvel;

    // légellenállás
    if( length > resist )
        velocity -= resistance * resist;
    else
        velocity.x = velocity.y = 0;

    // fix idöközönként lehet löni
    if( state & Shoot )
    {
        if( cooldown == 0 )
        {
            shoot();
            cooldown = WeaponCooldown;
        }
    }

    Position.extend(velocity);

    // ne menjen ki a képernyöröl
    if( DummyFramework::CHelper::Clamp2<float>(Position.current.x, Bounds.x, Bounds.z - Image->Size.x) )
        velocity.x = 0;

    if( DummyFramework::CHelper::Clamp2<float>(Position.current.y, Bounds.y, Bounds.w - Image->Size.y) )
        velocity.y = 0;

    if( cooldown > 0 )
        --cooldown;
}