ps: Added aabb calculation for emitter.
This commit is contained in:
parent
6def346bf9
commit
7fbbc1f98d
@ -393,11 +393,10 @@ class Particles : public entry::AppI
|
||||
|
||||
if (showBounds)
|
||||
{
|
||||
// Aabb aabb;
|
||||
// toAabb(aabb, tvb.data, tvb.size/tvb.stride, tvb.stride);
|
||||
|
||||
// ddSetColor(0xff0000ff);
|
||||
// ddDraw(aabb);
|
||||
Aabb aabb;
|
||||
psGetAabb(m_emitter[currentEmitter].m_handle, aabb);
|
||||
ddSetColor(0xff0000ff);
|
||||
ddDraw(aabb);
|
||||
}
|
||||
|
||||
|
||||
|
@ -182,6 +182,12 @@ void aabbExpand(Aabb& _aabb, float _factor)
|
||||
_aabb.m_max[2] += _factor;
|
||||
}
|
||||
|
||||
void aabbExpand(Aabb& _aabb, const float* _pos)
|
||||
{
|
||||
bx::vec3Min(_aabb.m_min, _aabb.m_min, _pos);
|
||||
bx::vec3Max(_aabb.m_max, _aabb.m_max, _pos);
|
||||
}
|
||||
|
||||
uint32_t aabbOverlapTest(const Aabb& _aabb0, const Aabb& _aabb1)
|
||||
{
|
||||
const uint32_t ltMinX = _aabb0.m_max[0] < _aabb1.m_min[0];
|
||||
|
@ -84,6 +84,9 @@ void toAabb(Aabb& _aabb, const float* _mtx, const void* _vertices, uint32_t _num
|
||||
/// Expand AABB.
|
||||
void aabbExpand(Aabb& _aabb, float _factor);
|
||||
|
||||
/// Expand AABB with xyz.
|
||||
void aabbExpand(Aabb& _aabb, const float* _pos);
|
||||
|
||||
/// Calculate surface area of axis aligned bounding box.
|
||||
float calcAreaAabb(const Aabb& _aabb);
|
||||
|
||||
|
@ -191,6 +191,7 @@ namespace ps
|
||||
void reset()
|
||||
{
|
||||
m_num = 0;
|
||||
memset(&m_aabb, 0, sizeof(Aabb) );
|
||||
}
|
||||
|
||||
void update(float _dt)
|
||||
@ -321,13 +322,19 @@ namespace ps
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t render(const float* _mtxView, const float* _eye, uint32_t _first, uint32_t _max, ParticleSort* _outSort, PosColorTexCoord0Vertex* _outVertices) const
|
||||
uint32_t render(const float* _mtxView, const float* _eye, uint32_t _first, uint32_t _max, ParticleSort* _outSort, PosColorTexCoord0Vertex* _outVertices)
|
||||
{
|
||||
bx::EaseFn easeRgba = s_easeFunc[m_uniforms.m_easeRgba];
|
||||
bx::EaseFn easePos = s_easeFunc[m_uniforms.m_easePos];
|
||||
bx::EaseFn easeBlend = s_easeFunc[m_uniforms.m_easeBlend];
|
||||
bx::EaseFn easeScale = s_easeFunc[m_uniforms.m_easeScale];
|
||||
|
||||
Aabb aabb =
|
||||
{
|
||||
{ HUGE_VALF, HUGE_VALF, HUGE_VALF },
|
||||
{ -HUGE_VALF, -HUGE_VALF, -HUGE_VALF },
|
||||
};
|
||||
|
||||
for (uint32_t jj = 0, num = m_num, current = _first
|
||||
; jj < num && current < _max
|
||||
; ++jj, ++current
|
||||
@ -376,6 +383,7 @@ namespace ps
|
||||
PosColorTexCoord0Vertex* vertex = &_outVertices[current*4];
|
||||
bx::vec3Sub(tmp, pos, udir);
|
||||
bx::vec3Sub(&vertex->m_x, tmp, vdir);
|
||||
aabbExpand(aabb, &vertex->m_x);
|
||||
vertex->m_abgr = abgr;
|
||||
vertex->m_u = 0.0f;
|
||||
vertex->m_v = 0.0f;
|
||||
@ -384,6 +392,7 @@ namespace ps
|
||||
|
||||
bx::vec3Add(tmp, pos, udir);
|
||||
bx::vec3Sub(&vertex->m_x, tmp, vdir);
|
||||
aabbExpand(aabb, &vertex->m_x);
|
||||
vertex->m_abgr = abgr;
|
||||
vertex->m_u = 1.0f;
|
||||
vertex->m_v = 0.0f;
|
||||
@ -392,6 +401,7 @@ namespace ps
|
||||
|
||||
bx::vec3Add(tmp, pos, udir);
|
||||
bx::vec3Add(&vertex->m_x, tmp, vdir);
|
||||
aabbExpand(aabb, &vertex->m_x);
|
||||
vertex->m_abgr = abgr;
|
||||
vertex->m_u = 1.0f;
|
||||
vertex->m_v = 1.0f;
|
||||
@ -400,6 +410,7 @@ namespace ps
|
||||
|
||||
bx::vec3Sub(tmp, pos, udir);
|
||||
bx::vec3Add(&vertex->m_x, tmp, vdir);
|
||||
aabbExpand(aabb, &vertex->m_x);
|
||||
vertex->m_abgr = abgr;
|
||||
vertex->m_u = 0.0f;
|
||||
vertex->m_v = 1.0f;
|
||||
@ -407,6 +418,8 @@ namespace ps
|
||||
++vertex;
|
||||
}
|
||||
|
||||
m_aabb = aabb;
|
||||
|
||||
return m_num;
|
||||
}
|
||||
|
||||
@ -417,6 +430,8 @@ namespace ps
|
||||
bx::RngMwc m_rng;
|
||||
EmitterUniforms m_uniforms;
|
||||
|
||||
Aabb m_aabb;
|
||||
|
||||
Particle* m_particles;
|
||||
uint32_t m_num;
|
||||
uint32_t m_max;
|
||||
@ -455,7 +470,7 @@ namespace ps
|
||||
|
||||
bgfx::RendererType::Enum type = bgfx::getRendererType();
|
||||
m_particleProgram = bgfx::createProgram(
|
||||
bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_particle")
|
||||
bgfx::createEmbeddedShader(s_embeddedShaders, type, "vs_particle")
|
||||
, bgfx::createEmbeddedShader(s_embeddedShaders, type, "fs_particle")
|
||||
, true
|
||||
);
|
||||
@ -519,7 +534,7 @@ namespace ps
|
||||
for (uint16_t ii = 0, numEmitters = m_emitterAlloc->getNumHandles(); ii < numEmitters; ++ii)
|
||||
{
|
||||
const uint16_t idx = m_emitterAlloc->getHandleAt(ii);
|
||||
const Emitter& emitter = m_emitter[idx];
|
||||
Emitter& emitter = m_emitter[idx];
|
||||
pos += emitter.render(_mtxView, _eye, pos, max, particleSort, vertices);
|
||||
}
|
||||
|
||||
@ -591,6 +606,15 @@ namespace ps
|
||||
}
|
||||
}
|
||||
|
||||
void getAabb(EmitterHandle _handle, Aabb& _outAabb)
|
||||
{
|
||||
BX_CHECK(m_emitterAlloc.isValid(_handle.idx)
|
||||
, "getAabb handle %d is not valid."
|
||||
, _handle.idx
|
||||
);
|
||||
_outAabb = m_emitter[_handle.idx].m_aabb;
|
||||
}
|
||||
|
||||
void destroyEmitter(EmitterHandle _handle)
|
||||
{
|
||||
BX_CHECK(m_emitterAlloc.isValid(_handle.idx)
|
||||
@ -658,6 +682,11 @@ void psUpdateEmitter(EmitterHandle _handle, const EmitterUniforms* _uniforms)
|
||||
s_ctx.updateEmitter(_handle, _uniforms);
|
||||
}
|
||||
|
||||
void psGetAabb(EmitterHandle _handle, Aabb& _outAabb)
|
||||
{
|
||||
s_ctx.getAabb(_handle, _outAabb);
|
||||
}
|
||||
|
||||
void psDestroyEmitter(EmitterHandle _handle)
|
||||
{
|
||||
s_ctx.destroyEmitter(_handle);
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include <bx/easing.h>
|
||||
#include <bx/rng.h>
|
||||
|
||||
#include "../bounds.h"
|
||||
|
||||
struct EmitterShape
|
||||
{
|
||||
enum Enum
|
||||
@ -74,6 +76,9 @@ EmitterHandle psCreateEmitter(EmitterShape::Enum _shape, EmitterDirection::Enum
|
||||
///
|
||||
void psUpdateEmitter(EmitterHandle _handle, const EmitterUniforms* _uniforms = NULL);
|
||||
|
||||
///
|
||||
void psGetAabb(EmitterHandle _handle, Aabb& _outAabb);
|
||||
|
||||
///
|
||||
void psDestroyEmitter(EmitterHandle _handle);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user