virtual void OnUpdate() { Quat q; q.FromAxis(Float3(0, 1, 0), 0.5f * Root::Instance()->GetFrameTime()); gMesh->Rotate(q); }
void PS_Billboard::_updateBuffer() { mRenderOp.primCount = mParent->GetParticleCount() * 2; if (mRenderOp.primCount == 0) return ; Camera * pCamera = World::Instance()->GetCurrentRenderContext()->GetCamera(); const Quat & worldQ = mParent->GetParent()->GetWorldRotation(); Mat4 worldTM; if (mParent->IsScaleAble()) worldTM = mParent->GetParent()->GetWorldTM(); else worldTM.MakeTransform(mParent->GetParent()->GetWorldPosition(), worldQ, Float3(1, 1, 1)); pCamera->GetWorldRotation().ToAxis(mCamXAxis, mCamYAxis, mCamZAxis); mCamPos = pCamera->GetWorldPosition(); mCommonDir = mParent->GetCommonDirection(); mCommonUp = mParent->GetCommonUpVector(); if (mParent->GetBillboardType() == PS_BillboardType::PERPENDICULAR || mParent->GetBillboardType() == PS_BillboardType::PERPENDICULAR_COMMON) { mCommonDir.TransformQ(worldQ); mCommonUp.TransformQ(worldQ); } float width, height, asecpt = 1; Float3 xAxis, yAxis; Float3 pos, dir; const Float2 & center = mParent->GetBillboardCenter(); if (mParent->IsKeepAspect()) asecpt = mParent->_getTexture()->_getAscept(); PS_Vertex * v = (PS_Vertex *)mRenderOp.vertexBuffers[0]->Lock(eLockFlag::WRITE); for (int i = 0; i < mParent->GetParticleCount(); ++i) { const Particle * p = mParent->GetParticle(i); height = Max(0.0f, p->Size.y); if (!mParent->IsKeepAspect()) width = Max(0.0f, p->Size.x); else width = height * asecpt; pos = p->Position; dir = p->Direction; if (mParent->IsLocalSpace()) { pos.TransformA(worldTM); dir.TransformQ(mParent->GetParent()->GetWorldRotation()); } _getBillboardXYAxis(xAxis, yAxis, pos, dir); if (p->Rotation.x != 0) { Quat q; q.FromAxis(Float3::Cross(xAxis, yAxis), Math::DegreeToRadian(p->Rotation.x)); xAxis.TransformQ(q); yAxis.TransformQ(q); } xAxis *= width, yAxis *= height; v->position = pos - xAxis * center.x + yAxis * center.y; v->color = p->Color; v->uv.x = p->UVRect.x1, v->uv.y = p->UVRect.y1; ++v; v->position = pos + xAxis * (1 - center.x) + yAxis * center.y; v->color = p->Color; v->uv.x = p->UVRect.x2, v->uv.y = p->UVRect.y1; ++v; v->position = pos - xAxis * center.x - yAxis * (1 - center.y); v->color = p->Color; v->uv.x = p->UVRect.x1, v->uv.y = p->UVRect.y2; ++v; v->position = pos + xAxis * (1 - center.x) - yAxis * (1 - center.y); v->color = p->Color; v->uv.x = p->UVRect.x2, v->uv.y = p->UVRect.y2; ++v; } mRenderOp.vertexBuffers[0]->Unlock(); }