Commit f298a1ac authored by chili's avatar chili
Browse files

basic plane, doesn't work ;(

parent 2526ae6c
...@@ -14,8 +14,10 @@ GDIPlusManager gdipm; ...@@ -14,8 +14,10 @@ GDIPlusManager gdipm;
App::App() App::App()
: :
wnd( 1280,720,"The Donkey Fart Box" ), wnd( 1280,720,"The Donkey Fart Box" ),
light( wnd.Gfx() ) light( wnd.Gfx() ),
plane( wnd.Gfx(),3.0f )
{ {
plane.SetPos( { 1.0f,17.0f,-1.0f } );
wnd.Gfx().SetProjection( dx::XMMatrixPerspectiveLH( 1.0f,9.0f / 16.0f,0.5f,40.0f ) ); wnd.Gfx().SetProjection( dx::XMMatrixPerspectiveLH( 1.0f,9.0f / 16.0f,0.5f,40.0f ) );
} }
...@@ -29,6 +31,7 @@ void App::DoFrame() ...@@ -29,6 +31,7 @@ void App::DoFrame()
nano.Draw( wnd.Gfx() ); nano.Draw( wnd.Gfx() );
nano2.Draw( wnd.Gfx() ); nano2.Draw( wnd.Gfx() );
light.Draw( wnd.Gfx() ); light.Draw( wnd.Gfx() );
plane.Draw( wnd.Gfx() );
while( const auto e = wnd.kbd.ReadKey() ) while( const auto e = wnd.kbd.ReadKey() )
{ {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "ImguiManager.h" #include "ImguiManager.h"
#include "Camera.h" #include "Camera.h"
#include "PointLight.h" #include "PointLight.h"
#include "TestPlane.h"
#include "Mesh.h" #include "Mesh.h"
#include <set> #include <set>
...@@ -27,4 +28,5 @@ private: ...@@ -27,4 +28,5 @@ private:
PointLight light; PointLight light;
Model nano{ wnd.Gfx(),"Models\\nano_textured\\nanosuit.obj" }; Model nano{ wnd.Gfx(),"Models\\nano_textured\\nanosuit.obj" };
Model nano2{ wnd.Gfx(),"Models\\nano_textured\\nanosuit.obj" }; Model nano2{ wnd.Gfx(),"Models\\nano_textured\\nanosuit.obj" };
TestPlane plane;
}; };
\ No newline at end of file
#pragma once
#include <optional>
#include "Vertex.h"
#include "IndexedTriangleList.h"
#include <DirectXMath.h>
#include "ChiliMath.h"
#include <array>
class Plane
{
public:
static IndexedTriangleList MakeTesselatedTextured( Dvtx::VertexLayout layout,int divisions_x,int divisions_y )
{
namespace dx = DirectX;
assert( divisions_x >= 1 );
assert( divisions_y >= 1 );
constexpr float width = 2.0f;
constexpr float height = 2.0f;
const int nVertices_x = divisions_x + 1;
const int nVertices_y = divisions_y + 1;
Dvtx::VertexBuffer vb{ std::move( layout ) };
{
const float side_x = width / 2.0f;
const float side_y = height / 2.0f;
const float divisionSize_x = width / float( divisions_x );
const float divisionSize_y = height / float( divisions_y );
const float divisionSize_x_tc = 1.0f / float( divisions_x );
const float divisionSize_y_tc = 1.0f / float( divisions_y );
for( int y = 0,i = 0; y < nVertices_y; y++ )
{
const float y_pos = float( y ) * divisionSize_y - 1.0f;
const float y_pos_tc = 1.0f - float( y ) * divisionSize_y_tc;
for( int x = 0; x < nVertices_x; x++,i++ )
{
const float x_pos = float( x ) * divisionSize_x - 1.0f;
const float x_pos_tc = float( x ) * divisionSize_x_tc;
vb.EmplaceBack(
dx::XMFLOAT3{ x_pos,y_pos,0.0f },
dx::XMFLOAT3{ 0.0f,0.0f,1.0f },
dx::XMFLOAT2{ x_pos_tc,y_pos_tc }
);
}
}
}
std::vector<unsigned short> indices;
indices.reserve( sq( divisions_x * divisions_y ) * 6 );
{
const auto vxy2i = [nVertices_x]( size_t x,size_t y )
{
return (unsigned short)(y * nVertices_x + x);
};
for( size_t y = 0; y < divisions_y; y++ )
{
for( size_t x = 0; x < divisions_x; x++ )
{
const std::array<unsigned short,4> indexArray =
{ vxy2i( x,y ),vxy2i( x + 1,y ),vxy2i( x,y + 1 ),vxy2i( x + 1,y + 1 ) };
indices.push_back( indexArray[0] );
indices.push_back( indexArray[2] );
indices.push_back( indexArray[1] );
indices.push_back( indexArray[1] );
indices.push_back( indexArray[2] );
indices.push_back( indexArray[3] );
}
}
}
return{ std::move( vb ),std::move( indices ) };
}
static IndexedTriangleList Make()
{
using Dvtx::VertexLayout;
VertexLayout vl;
vl.Append( VertexLayout::Position3D );
vl.Append( VertexLayout::Normal );
vl.Append( VertexLayout::Texture2D );
return MakeTesselatedTextured( std::move( vl ),1,1 );
}
};
#include "TestPlane.h"
#include "Plane.h"
#include "BindableCommon.h"
TestPlane::TestPlane( Graphics& gfx,float size )
{
using namespace Bind;
namespace dx = DirectX;
auto model = Plane::Make();
model.Transform( dx::XMMatrixScaling( size,size,1.0f ) );
const auto geometryTag = "$plane." + std::to_string( size );
AddBind( VertexBuffer::Resolve( gfx,geometryTag,model.vertices ) );
AddBind( IndexBuffer::Resolve( gfx,geometryTag,model.indices ) );
AddBind( Texture::Resolve( gfx,"Images\\brickwall.jpg" ) );
auto pvs = VertexShader::Resolve( gfx,"PhongVS.cso" );
auto pvsbc = pvs->GetBytecode();
AddBind( std::move( pvs ) );
AddBind( PixelShader::Resolve( gfx,"PhongPS.cso" ) );
struct PSMaterialConstant
{
float specularIntensity = 0.8f;
float specularPower = 45.0f;
float padding[2];
} pmc;
AddBind( PixelConstantBuffer<PSMaterialConstant>::Resolve( gfx,pmc,1u ) );
AddBind( InputLayout::Resolve( gfx,model.vertices.GetLayout(),pvsbc ) );
AddBind( Topology::Resolve( gfx,D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST ) );
AddBind( std::make_shared<TransformCbuf>( gfx,*this ) );
}
void TestPlane::SetPos( DirectX::XMFLOAT3 pos ) noexcept
{
this->pos = pos;
}
void TestPlane::SetRotation( float roll,float pitch,float yaw ) noexcept
{
this->roll = roll;
this->pitch = pitch;
this->yaw = yaw;
}
DirectX::XMMATRIX TestPlane::GetTransformXM() const noexcept
{
return DirectX::XMMatrixRotationRollPitchYaw( roll,pitch,yaw ) *
DirectX::XMMatrixTranslation( pos.x,pos.y,pos.z );
}
#pragma once
#include "Drawable.h"
class TestPlane : public Drawable
{
public:
TestPlane( Graphics& gfx,float size );
void SetPos( DirectX::XMFLOAT3 pos ) noexcept;
void SetRotation( float roll,float pitch,float yaw ) noexcept;
DirectX::XMMATRIX GetTransformXM() const noexcept override;
private:
DirectX::XMFLOAT3 pos = { 1.0f,1.0f,1.0f };
float roll = 0.0f;
float pitch = 0.0f;
float yaw = 0.0f;
};
\ No newline at end of file
...@@ -118,6 +118,7 @@ ...@@ -118,6 +118,7 @@
<ClCompile Include="Sampler.cpp" /> <ClCompile Include="Sampler.cpp" />
<ClCompile Include="SolidSphere.cpp" /> <ClCompile Include="SolidSphere.cpp" />
<ClCompile Include="Surface.cpp" /> <ClCompile Include="Surface.cpp" />
<ClCompile Include="TestPlane.cpp" />
<ClCompile Include="Texture.cpp" /> <ClCompile Include="Texture.cpp" />
<ClCompile Include="Topology.cpp" /> <ClCompile Include="Topology.cpp" />
<ClCompile Include="TransformCbuf.cpp" /> <ClCompile Include="TransformCbuf.cpp" />
...@@ -161,6 +162,7 @@ ...@@ -161,6 +162,7 @@
<ClInclude Include="InputLayout.h" /> <ClInclude Include="InputLayout.h" />
<ClInclude Include="Keyboard.h" /> <ClInclude Include="Keyboard.h" />
<ClInclude Include="Mesh.h" /> <ClInclude Include="Mesh.h" />
<ClInclude Include="Plane.h" />
<ClInclude Include="PointLight.h" /> <ClInclude Include="PointLight.h" />
<ClInclude Include="Mouse.h" /> <ClInclude Include="Mouse.h" />
<ClInclude Include="PixelShader.h" /> <ClInclude Include="PixelShader.h" />
...@@ -169,6 +171,7 @@ ...@@ -169,6 +171,7 @@
<ClInclude Include="SolidSphere.h" /> <ClInclude Include="SolidSphere.h" />
<ClInclude Include="Sphere.h" /> <ClInclude Include="Sphere.h" />
<ClInclude Include="Surface.h" /> <ClInclude Include="Surface.h" />
<ClInclude Include="TestPlane.h" />
<ClInclude Include="Texture.h" /> <ClInclude Include="Texture.h" />
<ClInclude Include="Topology.h" /> <ClInclude Include="Topology.h" />
<ClInclude Include="TransformCbuf.h" /> <ClInclude Include="TransformCbuf.h" />
......
...@@ -150,6 +150,9 @@ ...@@ -150,6 +150,9 @@
<ClCompile Include="Mesh.cpp"> <ClCompile Include="Mesh.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="TestPlane.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="WindowsMessageMap.h"> <ClInclude Include="WindowsMessageMap.h">
...@@ -299,6 +302,12 @@ ...@@ -299,6 +302,12 @@
<ClInclude Include="BindableCodex.h"> <ClInclude Include="BindableCodex.h">
<Filter>Header Files\Bindable</Filter> <Filter>Header Files\Bindable</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Plane.h">
<Filter>Header Files\Geometry</Filter>
</ClInclude>
<ClInclude Include="TestPlane.h">
<Filter>Header Files\Drawable</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="hw3d.rc"> <ResourceCompile Include="hw3d.rc">
......
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