Commit f61cdfde authored by chili's avatar chili
Browse files

create a nice base for our test objects

parent 3bff8c88
...@@ -13,16 +13,7 @@ Box::Box( Graphics& gfx, ...@@ -13,16 +13,7 @@ Box::Box( Graphics& gfx,
std::uniform_real_distribution<float>& bdist, std::uniform_real_distribution<float>& bdist,
DirectX::XMFLOAT3 material ) DirectX::XMFLOAT3 material )
: :
r( rdist( rng ) ), TestObject( gfx,rng,adist,ddist,odist,rdist )
droll( ddist( rng ) ),
dpitch( ddist( rng ) ),
dyaw( ddist( rng ) ),
dphi( odist( rng ) ),
dtheta( odist( rng ) ),
dchi( odist( rng ) ),
chi( adist( rng ) ),
theta( adist( rng ) ),
phi( adist( rng ) )
{ {
namespace dx = DirectX; namespace dx = DirectX;
...@@ -79,21 +70,8 @@ Box::Box( Graphics& gfx, ...@@ -79,21 +70,8 @@ Box::Box( Graphics& gfx,
); );
} }
void Box::Update( float dt ) noexcept
{
roll += droll * dt;
pitch += dpitch * dt;
yaw += dyaw * dt;
theta += dtheta * dt;
phi += dphi * dt;
chi += dchi * dt;
}
DirectX::XMMATRIX Box::GetTransformXM() const noexcept DirectX::XMMATRIX Box::GetTransformXM() const noexcept
{ {
namespace dx = DirectX; namespace dx = DirectX;
return dx::XMLoadFloat3x3( &mt ) * return dx::XMLoadFloat3x3( &mt ) * TestObject::GetTransformXM();
dx::XMMatrixRotationRollPitchYaw( pitch,yaw,roll ) *
dx::XMMatrixTranslation( r,0.0f,0.0f ) *
dx::XMMatrixRotationRollPitchYaw( theta,phi,chi );
} }
#pragma once #pragma once
#include "DrawableBase.h" #include "TestObject.h"
class Box : public DrawableBase<Box> class Box : public TestObject<Box>
{ {
public: public:
Box( Graphics& gfx,std::mt19937& rng, Box( Graphics& gfx,std::mt19937& rng,
...@@ -11,24 +11,8 @@ public: ...@@ -11,24 +11,8 @@ public:
std::uniform_real_distribution<float>& rdist, std::uniform_real_distribution<float>& rdist,
std::uniform_real_distribution<float>& bdist, std::uniform_real_distribution<float>& bdist,
DirectX::XMFLOAT3 material ); DirectX::XMFLOAT3 material );
void Update( float dt ) noexcept override;
DirectX::XMMATRIX GetTransformXM() const noexcept override; DirectX::XMMATRIX GetTransformXM() const noexcept override;
private: private:
// positional
float r;
float roll = 0.0f;
float pitch = 0.0f;
float yaw = 0.0f;
float theta;
float phi;
float chi;
// speed (delta/s)
float droll;
float dpitch;
float dyaw;
float dtheta;
float dphi;
float dchi;
// model transform // model transform
DirectX::XMFLOAT3X3 mt; DirectX::XMFLOAT3X3 mt;
}; };
\ No newline at end of file
#pragma once
#include "DrawableBase.h"
template<class T>
class TestObject : public DrawableBase<T>
{
public:
TestObject( Graphics& gfx,std::mt19937& rng,
std::uniform_real_distribution<float>& adist,
std::uniform_real_distribution<float>& ddist,
std::uniform_real_distribution<float>& odist,
std::uniform_real_distribution<float>& rdist )
:
r( rdist( rng ) ),
droll( ddist( rng ) ),
dpitch( ddist( rng ) ),
dyaw( ddist( rng ) ),
dphi( odist( rng ) ),
dtheta( odist( rng ) ),
dchi( odist( rng ) ),
chi( adist( rng ) ),
theta( adist( rng ) ),
phi( adist( rng ) )
{}
void Update( float dt ) noexcept
{
roll += droll * dt;
pitch += dpitch * dt;
yaw += dyaw * dt;
theta += dtheta * dt;
phi += dphi * dt;
chi += dchi * dt;
}
DirectX::XMMATRIX GetTransformXM() const noexcept
{
namespace dx = DirectX;
return dx::XMMatrixRotationRollPitchYaw( pitch,yaw,roll ) *
dx::XMMatrixTranslation( r,0.0f,0.0f ) *
dx::XMMatrixRotationRollPitchYaw( theta,phi,chi );
}
private:
// positional
float r;
float roll = 0.0f;
float pitch = 0.0f;
float yaw = 0.0f;
float theta;
float phi;
float chi;
// speed (delta/s)
float droll;
float dpitch;
float dyaw;
float dtheta;
float dphi;
float dchi;
};
...@@ -176,6 +176,7 @@ ...@@ -176,6 +176,7 @@
<ClCompile Include="Sampler.cpp" /> <ClCompile Include="Sampler.cpp" />
<ClCompile Include="SkinnedBox.cpp" /> <ClCompile Include="SkinnedBox.cpp" />
<ClCompile Include="Surface.cpp" /> <ClCompile Include="Surface.cpp" />
<ClCompile Include="TestObject.h" />
<ClCompile Include="Texture.cpp" /> <ClCompile Include="Texture.cpp" />
<ClCompile Include="Topology.cpp" /> <ClCompile Include="Topology.cpp" />
<ClCompile Include="TransformCbuf.cpp" /> <ClCompile Include="TransformCbuf.cpp" />
......
...@@ -153,6 +153,9 @@ ...@@ -153,6 +153,9 @@
<ClCompile Include="PointLight.cpp"> <ClCompile Include="PointLight.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="TestObject.h">
<Filter>Header Files\Drawable</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="WindowsMessageMap.h"> <ClInclude Include="WindowsMessageMap.h">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment