Merge pull request #5902 from ctrlaltdavid/particles-fixes

Particles fixes
This commit is contained in:
Eric Levin 2015-09-25 10:56:18 -07:00
commit 135e2683a6
5 changed files with 34 additions and 38 deletions

View file

@ -682,9 +682,9 @@ void ParticleEffectEntityItem::stepSimulation(float deltaTime) {
}
updateRadius(i, 0.0f);
// Velocity and acceleration
if (_polarStart == 0.0f && _polarFinish == 0.0f) {
// Emit along z-axis
// Position, velocity, and acceleration
if (_polarStart == 0.0f && _polarFinish == 0.0f && _emitDimensions.z == 0.0f) {
// Emit along z-axis from position
_particlePositions[i] = getPosition();
_particleVelocities[i] =
(_emitSpeed + (2.0f * randFloat() - 1.0f) * _speedSpread) * (_emitOrientation * Z_AXIS);
@ -711,10 +711,10 @@ void ParticleEffectEntityItem::stepSimulation(float deltaTime) {
if (_emitDimensions == glm::vec3()) {
// Point
emitDirection = _emitOrientation * fromSpherical(elevation, azimuth);
emitDirection = glm::angleAxis(PI_OVER_TWO - elevation, X_AXIS) * Z_AXIS;
emitDirection = glm::angleAxis(azimuth, Z_AXIS) * emitDirection;
_particlePositions[i] = getPosition();
} else {
// Ellipsoid
float radiusScale = 1.0f;
@ -730,9 +730,9 @@ void ParticleEffectEntityItem::stepSimulation(float deltaTime) {
float z = radiuses.z * glm::sin(elevation);
glm::vec3 emitPosition = glm::vec3(x, y, z);
emitDirection = glm::normalize(glm::vec3(
x / (radiuses.x * radiuses.x),
y / (radiuses.y * radiuses.y),
z / (radiuses.z * radiuses.z)
radiuses.x > 0.0f ? x / (radiuses.x * radiuses.x) : 0.0f,
radiuses.y > 0.0f ? y / (radiuses.y * radiuses.y) : 0.0f,
radiuses.z > 0.0f ? z / (radiuses.z * radiuses.z) : 0.0f
));
_particlePositions[i] = getPosition() + _emitOrientation * emitPosition;

View file

@ -58,3 +58,27 @@ glm::vec3 Vec3::toPolar(const glm::vec3& v) {
return glm::vec3(elevation, azimuth, radius);
}
glm::vec3 Vec3::fromPolar(const glm::vec3& polar) {
float x = glm::cos(polar.x) * glm::sin(polar.y);
float y = glm::sin(-polar.x);
float z = glm::cos(polar.x) * glm::cos(polar.y);
// Round small values to 0
if (glm::abs(x) < EPSILON) {
x = 0.0f;
}
if (glm::abs(y) < EPSILON) {
y = 0.0f;
}
if (glm::abs(z) < EPSILON) {
z = 0.0f;
}
return polar.z * glm::vec3(x, y, z);
}
glm::vec3 Vec3::fromPolar(float elevation, float azimuth) {
glm::vec3 v = glm::vec3(elevation, azimuth, 1.0f);
return fromPolar(v);
}

View file

@ -43,8 +43,8 @@ public slots:
bool withinEpsilon(const glm::vec3& v1, const glm::vec3& v2, float epsilon);
// FIXME misnamed, should be 'spherical' or 'euler' depending on the implementation
glm::vec3 toPolar(const glm::vec3& v);
glm::vec3 fromPolar(const glm::vec3& polar) { return fromSpherical(polar); }
glm::vec3 fromPolar(float elevation, float azimuth) { return fromSpherical(elevation, azimuth); }
glm::vec3 fromPolar(const glm::vec3& polar);
glm::vec3 fromPolar(float elevation, float azimuth);
const glm::vec3& UNIT_X() { return Vectors::UNIT_X; }
const glm::vec3& UNIT_Y() { return Vectors::UNIT_Y; }
const glm::vec3& UNIT_Z() { return Vectors::UNIT_Z; }

View file

@ -225,30 +225,6 @@ glm::quat rotationBetween(const glm::vec3& v1, const glm::vec3& v2) {
return glm::angleAxis(angle, axis);
}
glm::vec3 fromSpherical(const glm::vec3& spherical) {
float x = glm::cos(spherical.x) * glm::sin(spherical.y);
float y = glm::sin(-spherical.x);
float z = glm::cos(spherical.x) * glm::cos(spherical.y);
// Round small values to 0
if (glm::abs(x) < EPSILON) {
x = 0.0f;
}
if (glm::abs(y) < EPSILON) {
y = 0.0f;
}
if (glm::abs(z) < EPSILON) {
z = 0.0f;
}
return spherical.z * glm::vec3(x, y, z);
}
glm::vec3 fromSpherical(float elevation, float azimuth) {
glm::vec3 v = glm::vec3(elevation, azimuth, 1.0f);
return fromSpherical(v);
}
bool isPointBehindTrianglesPlane(glm::vec3 point, glm::vec3 p0, glm::vec3 p1, glm::vec3 p2) {
glm::vec3 v1 = p0 - p1, v2 = p2 - p1; // Non-collinear vectors contained in the plane
glm::vec3 n = glm::cross(v1, v2); // Plane's normal vector, pointing out of the triangle

View file

@ -117,10 +117,6 @@ float angleBetween(const glm::vec3& v1, const glm::vec3& v2);
glm::quat rotationBetween(const glm::vec3& v1, const glm::vec3& v2);
glm::vec3 fromSpherical(const glm::vec3& spherical);
glm::vec3 fromSpherical(float elevation, float azimuth);
bool isPointBehindTrianglesPlane(glm::vec3 point, glm::vec3 p0, glm::vec3 p1, glm::vec3 p2);
glm::vec3 extractTranslation(const glm::mat4& matrix);