Commit 99e15f43 authored by chili's avatar chili
Browse files

add nmap test cube / necessary changes

parent 27a08d83
#pragma once
#include <optional>
#include "Vertex.h"
#include "IndexedTriangleList.h"
#include <DirectXMath.h>
#include "ChiliMath.h"
#include <array>
class Cube
{
public:
static IndexedTriangleList MakeIndependent( Dvtx::VertexLayout layout )
{
using namespace Dvtx;
using Type = Dvtx::VertexLayout::ElementType;
constexpr float side = 1.0f / 2.0f;
VertexBuffer vertices( std::move( layout ),24u );
vertices[0].Attr<Type::Position3D>() = { -side,-side,-side };// 0 near side
vertices[1].Attr<Type::Position3D>() = { side,-side,-side };// 1
vertices[2].Attr<Type::Position3D>() = { -side,side,-side };// 2
vertices[3].Attr<Type::Position3D>() = { side,side,-side };// 3
vertices[4].Attr<Type::Position3D>() = { -side,-side,side };// 4 far side
vertices[5].Attr<Type::Position3D>() = { side,-side,side };// 5
vertices[6].Attr<Type::Position3D>() = { -side,side,side };// 6
vertices[7].Attr<Type::Position3D>() = { side,side,side };// 7
vertices[8].Attr<Type::Position3D>() = { -side,-side,-side };// 8 left side
vertices[9].Attr<Type::Position3D>() = { -side,side,-side };// 9
vertices[10].Attr<Type::Position3D>() = { -side,-side,side };// 10
vertices[11].Attr<Type::Position3D>() = { -side,side,side };// 11
vertices[12].Attr<Type::Position3D>() = { side,-side,-side };// 12 right side
vertices[13].Attr<Type::Position3D>() = { side,side,-side };// 13
vertices[14].Attr<Type::Position3D>() = { side,-side,side };// 14
vertices[15].Attr<Type::Position3D>() = { side,side,side };// 15
vertices[16].Attr<Type::Position3D>() = { -side,-side,-side };// 16 bottom side
vertices[17].Attr<Type::Position3D>() = { side,-side,-side };// 17
vertices[18].Attr<Type::Position3D>() = { -side,-side,side };// 18
vertices[19].Attr<Type::Position3D>() = { side,-side,side };// 19
vertices[20].Attr<Type::Position3D>() = { -side,side,-side };// 20 top side
vertices[21].Attr<Type::Position3D>() = { side,side,-side };// 21
vertices[22].Attr<Type::Position3D>() = { -side,side,side };// 22
vertices[23].Attr<Type::Position3D>() = { side,side,side };// 23
return{
std::move( vertices ),{
0,2, 1, 2,3,1,
4,5, 7, 4,7,6,
8,10, 9, 10,11,9,
12,13,15, 12,15,14,
16,17,18, 18,17,19,
20,23,21, 20,22,23
}
};
}
static IndexedTriangleList MakeIndependentTextured()
{
using namespace Dvtx;
using Type = Dvtx::VertexLayout::ElementType;
auto itl = MakeIndependent( std::move( VertexLayout{}
.Append( Type::Position3D )
.Append( Type::Normal )
.Append( Type::Texture2D )
) );
itl.vertices[0].Attr<Type::Texture2D>() = { 0.0f,0.0f };
itl.vertices[1].Attr<Type::Texture2D>() = { 1.0f,0.0f };
itl.vertices[2].Attr<Type::Texture2D>() = { 0.0f,1.0f };
itl.vertices[3].Attr<Type::Texture2D>() = { 1.0f,1.0f };
itl.vertices[4].Attr<Type::Texture2D>() = { 0.0f,0.0f };
itl.vertices[5].Attr<Type::Texture2D>() = { 1.0f,0.0f };
itl.vertices[6].Attr<Type::Texture2D>() = { 0.0f,1.0f };
itl.vertices[7].Attr<Type::Texture2D>() = { 1.0f,1.0f };
itl.vertices[8].Attr<Type::Texture2D>() = { 0.0f,0.0f };
itl.vertices[9].Attr<Type::Texture2D>() = { 1.0f,0.0f };
itl.vertices[10].Attr<Type::Texture2D>() = { 0.0f,1.0f };
itl.vertices[11].Attr<Type::Texture2D>() = { 1.0f,1.0f };
itl.vertices[12].Attr<Type::Texture2D>() = { 0.0f,0.0f };
itl.vertices[13].Attr<Type::Texture2D>() = { 1.0f,0.0f };
itl.vertices[14].Attr<Type::Texture2D>() = { 0.0f,1.0f };
itl.vertices[15].Attr<Type::Texture2D>() = { 1.0f,1.0f };
itl.vertices[16].Attr<Type::Texture2D>() = { 0.0f,0.0f };
itl.vertices[17].Attr<Type::Texture2D>() = { 1.0f,0.0f };
itl.vertices[18].Attr<Type::Texture2D>() = { 0.0f,1.0f };
itl.vertices[19].Attr<Type::Texture2D>() = { 1.0f,1.0f };
itl.vertices[20].Attr<Type::Texture2D>() = { 0.0f,0.0f };
itl.vertices[21].Attr<Type::Texture2D>() = { 1.0f,0.0f };
itl.vertices[22].Attr<Type::Texture2D>() = { 0.0f,1.0f };
itl.vertices[23].Attr<Type::Texture2D>() = { 1.0f,1.0f };
return itl;
}
};
\ No newline at end of file
......@@ -27,26 +27,26 @@ public:
);
}
}
//// asserts face-independent vertices w/ normals cleared to zero
//void SetNormalsIndependentFlat() noxnd
//{
// using namespace DirectX;
// for( size_t i = 0; i < indices.size(); i += 3 )
// {
// auto& v0 = vertices[indices[i]];
// auto& v1 = vertices[indices[i + 1]];
// auto& v2 = vertices[indices[i + 2]];
// const auto p0 = XMLoadFloat3( &v0.pos );
// const auto p1 = XMLoadFloat3( &v1.pos );
// const auto p2 = XMLoadFloat3( &v2.pos );
void SetNormalsIndependentFlat() noxnd
{
using namespace DirectX;
using Type = Dvtx::VertexLayout::ElementType;
for( size_t i = 0; i < indices.size(); i += 3 )
{
auto v0 = vertices[indices[i]];
auto v1 = vertices[indices[i + 1]];
auto v2 = vertices[indices[i + 2]];
const auto p0 = XMLoadFloat3( &v0.Attr<Type::Position3D>() );
const auto p1 = XMLoadFloat3( &v1.Attr<Type::Position3D>() );
const auto p2 = XMLoadFloat3( &v2.Attr<Type::Position3D>() );
// const auto n = XMVector3Normalize( XMVector3Cross( (p1 - p0),(p2 - p0) ) );
//
// XMStoreFloat3( &v0.n,n );
// XMStoreFloat3( &v1.n,n );
// XMStoreFloat3( &v2.n,n );
// }
//}
const auto n = XMVector3Normalize( XMVector3Cross( (p1 - p0),(p2 - p0) ) );
XMStoreFloat3( &v0.Attr<Type::Normal>(),n );
XMStoreFloat3( &v1.Attr<Type::Normal>(),n );
XMStoreFloat3( &v2.Attr<Type::Normal>(),n );
}
}
public:
Dvtx::VertexBuffer vertices;
......
......@@ -16,8 +16,8 @@ public:
assert( divisions_x >= 1 );
assert( divisions_y >= 1 );
constexpr float width = 2.0f;
constexpr float height = 2.0f;
constexpr float width = 1.0f;
constexpr float height = 1.0f;
const int nVertices_x = divisions_x + 1;
const int nVertices_y = divisions_y + 1;
Dvtx::VertexBuffer vb{ std::move( layout ) };
......
#include "TestCube.h"
#include "Cube.h"
#include "BindableCommon.h"
#include "TransformCbufDoubleboi.h"
#include "imgui/imgui.h"
TestCube::TestCube( Graphics& gfx,float size )
{
using namespace Bind;
namespace dx = DirectX;
auto model = Cube::MakeIndependentTextured();
model.Transform( dx::XMMatrixScaling( size,size,size ) );
model.SetNormalsIndependentFlat();
const auto geometryTag = "$cube." + 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" ) );
AddBind( Texture::Resolve( gfx,"Images\\brickwall_normal.jpg",1u ) );
auto pvs = VertexShader::Resolve( gfx,"PhongVS.cso" );
auto pvsbc = pvs->GetBytecode();
AddBind( std::move( pvs ) );
AddBind( PixelShader::Resolve( gfx,"PhongPSNormalMap.cso" ) );
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<TransformCbufDoubleboi>( gfx,*this,0u,2u ) );
}
void TestCube::SetPos( DirectX::XMFLOAT3 pos ) noexcept
{
this->pos = pos;
}
void TestCube::SetRotation( float roll,float pitch,float yaw ) noexcept
{
this->roll = roll;
this->pitch = pitch;
this->yaw = yaw;
}
DirectX::XMMATRIX TestCube::GetTransformXM() const noexcept
{
return DirectX::XMMatrixRotationRollPitchYaw( roll,pitch,yaw ) *
DirectX::XMMatrixTranslation( pos.x,pos.y,pos.z );
}
void TestCube::SpawnControlWindow( Graphics& gfx ) noexcept
{
if( ImGui::Begin( "Cube" ) )
{
ImGui::Text( "Position" );
ImGui::SliderFloat( "X",&pos.x,-80.0f,80.0f,"%.1f" );
ImGui::SliderFloat( "Y",&pos.y,-80.0f,80.0f,"%.1f" );
ImGui::SliderFloat( "Z",&pos.z,-80.0f,80.0f,"%.1f" );
ImGui::Text( "Orientation" );
ImGui::SliderAngle( "Roll",&roll,-180.0f,180.0f );
ImGui::SliderAngle( "Pitch",&pitch,-180.0f,180.0f );
ImGui::SliderAngle( "Yaw",&yaw,-180.0f,180.0f );
ImGui::Text( "Shading" );
bool changed0 = ImGui::SliderFloat( "Spec. Int.",&pmc.specularIntensity,0.0f,1.0f );
bool changed1 = ImGui::SliderFloat( "Spec. Power",&pmc.specularPower,0.0f,100.0f );
bool checkState = pmc.normalMappingEnabled == TRUE;
bool changed2 = ImGui::Checkbox( "Enable Normal Map",&checkState );
pmc.normalMappingEnabled = checkState ? TRUE : FALSE;
if( changed0 || changed1 || changed2 )
{
QueryBindable<Bind::PixelConstantBuffer<PSMaterialConstant>>()->Update( gfx,pmc );
}
}
ImGui::End();
}
#pragma once
#include "Drawable.h"
class TestCube : public Drawable
{
public:
TestCube( 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;
void SpawnControlWindow( Graphics& gfx ) noexcept;
private:
struct PSMaterialConstant
{
float specularIntensity = 0.1f;
float specularPower = 20.0f;
BOOL normalMappingEnabled = TRUE;
float padding[1];
} pmc;
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
......@@ -146,10 +146,20 @@ namespace Dvtx
// VertexBuffer
VertexBuffer::VertexBuffer( VertexLayout layout ) noxnd
VertexBuffer::VertexBuffer( VertexLayout layout,size_t size ) noxnd
:
layout( std::move( layout ) )
{}
{
Resize( size );
}
void VertexBuffer::Resize( size_t newSize ) noxnd
{
const auto size = Size();
if( size < newSize )
{
buffer.resize( buffer.size() + layout.Size() * (newSize - size) );
}
}
const char* VertexBuffer::GetData() const noxnd
{
return buffer.data();
......
......@@ -204,9 +204,10 @@ namespace Dvtx
class VertexBuffer
{
public:
VertexBuffer( VertexLayout layout ) noxnd;
VertexBuffer( VertexLayout layout,size_t size = 0u ) noxnd;
const char* GetData() const noxnd;
const VertexLayout& GetLayout() const noexcept;
void Resize( size_t newSize ) noxnd;
size_t Size() const noxnd;
size_t SizeBytes() const noxnd;
template<typename ...Params>
......
......@@ -118,6 +118,7 @@
<ClCompile Include="Sampler.cpp" />
<ClCompile Include="SolidSphere.cpp" />
<ClCompile Include="Surface.cpp" />
<ClCompile Include="TestCube.cpp" />
<ClCompile Include="TestPlane.cpp" />
<ClCompile Include="Texture.cpp" />
<ClCompile Include="Topology.cpp" />
......@@ -143,6 +144,8 @@
<ClInclude Include="Color.h" />
<ClInclude Include="ConditionalNoexcept.h" />
<ClInclude Include="ConstantBuffers.h" />
<ClInclude Include="Cube.h" />
<ClInclude Include="TestCube.h" />
<ClInclude Include="Drawable.h" />
<ClInclude Include="dxerr.h" />
<ClInclude Include="DxgiInfoManager.h" />
......
......@@ -156,6 +156,9 @@
<ClCompile Include="TransformCbufDoubleboi.cpp">
<Filter>Source Files\Bindable</Filter>
</ClCompile>
<ClCompile Include="TestCube.cpp">
<Filter>Source Files\Drawable</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="WindowsMessageMap.h">
......@@ -314,6 +317,12 @@
<ClInclude Include="TransformCbufDoubleboi.h">
<Filter>Header Files\Bindable</Filter>
</ClInclude>
<ClInclude Include="Cube.h">
<Filter>Header Files\Geometry</Filter>
</ClInclude>
<ClInclude Include="TestCube.h">
<Filter>Header Files\Drawable</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<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