Пример #1
0
bool Particle::Update(float32 timeElapsed)
{
	life += timeElapsed;
	if (life >= lifeTime)
	{
		return false;
	}

	position += direction * speed * timeElapsed * velocityOverLife;
	angle += spin * timeElapsed * spinOverLife;
	
	int32 forcesCount = (int32)forces.size();
	if(forcesCount > 0)
	{
		Vector3 velocity = direction*speed;
		for(int i = 0; i < forcesCount; i++)
		{
			Vector3 newVelocity = forces[i].direction * forces[i].value;
			if (forces[i].overlifeEnabled)
			{
				newVelocity *= forces[i].overlife;
			}

			velocity += (newVelocity  * timeElapsed);
		}
		float32 invSqrt = InvSqrtFast(velocity.SquareLength());
		speed = 1.f/invSqrt;
		direction = velocity*invSqrt;
	}
	return true;
}
Пример #2
0
//! Square length of poly segments
float32 Polygon3::SquareLength() const
{
    float32 squareLength = 0.0f;
    for(int32 i = 0; i < pointCount - 1; ++i)
    {
        Vector3 segment = points[i] - points[i + 1];
        squareLength += segment.SquareLength();
    }
    return squareLength;
}
Пример #3
0
//! Remove points in given radius
void Polygon3::RemovePointsInSphere(const Vector3 & center, float32 radius)
{
    float32 rad2 = radius * radius;
    for (int p = 0; p < pointCount; ++p)
    {
        Vector3 dist = points[p] - center;
        if (dist.SquareLength() <= rad2)
        {
            RemoveSegmentAtIndex(p);
            p--;
        }
    }
}
Пример #4
0
bool Collision::BoundingShpere_BoundingSphere(const BoundingSphere& sphere1, const BoundingSphere& sphere2, HitInfo& hitInfo) {
	float radius = sphere1.radius + sphere2.radius;
	Vector3 distance = sphere2.center - sphere1.center;

	if (distance.SquareLength() >= radius * radius)
		return false;

	//中央を結んだベクトルの正規化
	Vector3 n = distance.GetNormal();

	hitInfo.intersect = sphere2.center - radius * n;
	return true;
}
Пример #5
0
//! Remove small segments function remove all segments size of which smaller or equal than removalSize
int32 Polygon3::RemoveSmallSegments(float32 removalSize)
{
    float32 removalSquareSize = removalSize * removalSize;
    int removedCount = 0;
    for (int segment = 0; segment < pointCount - 1; ++segment)
    {
        Vector3 v = points[segment] - points[segment + 1];
        if (v.SquareLength() <= removalSquareSize)
        {
            RemoveSegmentAtIndex(segment);
            segment--;
            removedCount++;
        }
    }
    return removedCount;
}
Пример #6
0
bool Collision::BoundingSphere_Line(const BoundingSphere& sphere, const Line& line, HitInfo& hitInfo) {
	Vector3 vec = line.vector;

	Vector3 v1 = sphere.center - line.p1;
	float t = vec.Dot(v1) / vec.Dot(vec);
	if (t < 0 && v1.SquareLength() <= sphere.radius * sphere.radius) {
		hitInfo.intersect = line.p1;
		return true;
	}

	Vector3 v2 = sphere.center - line.p2;
	if (t > 0 && v2.SquareLength() <= sphere.radius * sphere.radius) {
		hitInfo.intersect = line.p2;
		return true;
	}

	Vector3 vn = v1 - t * vec;
	if ((0 < t && t < 1) && (vn.SquareLength() < sphere.radius * sphere.radius)) {
		hitInfo.intersect = line.p1 + t * vec;
		return true;
	}

	return false;
}