Skip to content

Commit

Permalink
Version 0.4 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
alekasm committed Nov 20, 2020
1 parent 8f85d05 commit 90336ec
Show file tree
Hide file tree
Showing 22 changed files with 131 additions and 17 deletions.
2 changes: 1 addition & 1 deletion SC2KRender/Model3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct Model3D

bool visible()
{

}


Expand Down
2 changes: 1 addition & 1 deletion SC2KRender/SC2KRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance
SetConsoleMode(hInput, dwMode & ENABLE_EXTENDED_FLAGS);
ShowWindow(GetConsoleWindow(), SW_HIDE);

printf("SC2KRender (Version 0.3)\n");
printf("SC2KRender (Version 0.4)\n");
printf("Written by Aleksander Krimsky | www.krimsky.net\n");
printf("3D Models by Thomas Nelson\n");
printf("Written with DirectX 11 - Modified DirectXTK\n");
Expand Down
1 change: 0 additions & 1 deletion SC2KRender/SC2KRender.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@
<ClInclude Include="Sprite2D.h" />
<ClInclude Include="Sprite3D.h" />
<ClInclude Include="Types.h" />
<ClInclude Include="utility\RenderThread.h" />
</ItemGroup>
<ItemGroup>
<None Include="DirectXTK\SimpleMath.inl" />
Expand Down
3 changes: 0 additions & 3 deletions SC2KRender/SC2KRender.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,6 @@
<ClInclude Include="menus\MenuContext.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="utility\RenderThread.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="DirectXTK\SimpleMath.inl">
Expand Down
120 changes: 111 additions & 9 deletions SC2KRender/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,18 @@ void Scene::Initialize(MapTile* map_tiles)
model->origin.y = t.height;
}

else if (XBLD_IS_TREES(map_tile->xbld))
{
if (map_tile->xter != XTER_FLAT)
{ //raise the trees on sloped terrains to add extended trunks
model->origin.y = t.height + 1.f;
}
else
{
model->origin.y = t.height;
}
}

else if (XBLD_IS_HYDROELECTRIC(map_tile->xbld))
{
if (map_tile->xter == XTER_WATERFALL)
Expand Down Expand Up @@ -328,6 +340,7 @@ void Scene::CreateResources()

const UINT backBufferWidth = static_cast<UINT>(m_outputWidth);
const UINT backBufferHeight = static_cast<UINT>(m_outputHeight);
m_viewport = DirectX::SimpleMath::Viewport(0.0f, 0.0f, m_outputWidth, m_outputHeight);
const DXGI_FORMAT backBufferFormat = DXGI_FORMAT_B8G8R8A8_UNORM;
const DXGI_FORMAT depthBufferFormat = DXGI_FORMAT_D24_UNORM_S8_UINT;
constexpr UINT backBufferCount = 2;
Expand Down Expand Up @@ -514,20 +527,54 @@ void Scene::MouseClick()
float ray_z = +sin(yaw - (float)M_PI_2);
float ray_y = -sin(pitch);

Vector3 test = m_viewport.Unproject(Vector3(client_cx, client_cy, 0.f), m_proj, m_view, m_world);
if (test.x < 0 || test.x > 127 || test.z < 0 || test.z > 127)
return;

unsigned int x = static_cast<unsigned int>(test.x);
unsigned int y = static_cast<unsigned int>(test.z);
MapSceneTile& t = tiles[x + TILES_DIMENSION * y];
printf("Unprojected Vector: %f %f %f\n", test.x, test.y, test.z);
printf("Unprojected Tile: %d, %d\n", x, y);

t.ColorTile(DirectX::Colors::Crimson);
printf("[Debug] Map Tile(%d, %d): Map Height: %d, XTER: %x, Water Height:%d, ALTM: %d, XBLD: %x, XZON: %x, XUND: %x, XBIT: %x\n",
x, y, t.map_tile->height, t.map_tile->xter, t.map_tile->water_height, t.map_tile->altm, t.map_tile->xbld, t.map_tile->xzon,
t.map_tile->xund, t.map_tile->xbit);

uint8_t mask = 0b10101111;
bool single_tile = (t.map_tile->xzon >> 4) == 0b1111;
bool no_xzon = t.map_tile->xzon == 0;
bool is_multi_tile = (t.map_tile->xbit & mask) == mask;
bool render_tile = single_tile || (no_xzon && !is_multi_tile);
char buffer[256];
snprintf(buffer, sizeof(buffer), "Single Tile: %d, No XZON: %d, Multi Tile: %d, Render Tile: %d\n",
single_tile, no_xzon, is_multi_tile, render_tile);
OutputDebugString(buffer);


//test *= scale;


/*
Vector3 direction(ray_x, ray_y, ray_z);
DirectX::SimpleMath::Ray ray(m_position, direction);
//DirectX::XMVector3Unproject()
for (unsigned int y = 0; y < TILES_DIMENSION; ++y)
{
for (unsigned int x = 0; x < TILES_DIMENSION; ++x)
{
MapSceneTile& t = tiles[x + TILES_DIMENSION * y];

float distance1, distance2;
bool tri1 = ray.Intersects(t.v_pos[VPos::TOP_LEFT] * scale, t.v_pos[VPos::BOTTOM_LEFT] * scale, t.v_pos[VPos::TOP_RIGHT] * scale, distance1);
bool tri2 = ray.Intersects(t.v_pos[VPos::BOTTOM_RIGHT] * scale, t.v_pos[VPos::BOTTOM_LEFT] * scale, t.v_pos[VPos::TOP_RIGHT] * scale, distance2);
if (tri1 || tri2)
bool contains = test.x >= t.v_pos[VPos::TOP_LEFT].x && test.x <= t.v_pos[VPos::BOTTOM_RIGHT].x &&
test.z >= t.v_pos[VPos::TOP_LEFT].z && test.z <= t.v_pos[VPos::BOTTOM_RIGHT].z;
//float distance1, distance2;
//bool tri1 = ray.Intersects(t.v_pos[VPos::TOP_LEFT] * scale, t.v_pos[VPos::BOTTOM_LEFT] * scale, t.v_pos[VPos::TOP_RIGHT] * scale, distance1);
//bool tri2 = ray.Intersects(t.v_pos[VPos::BOTTOM_RIGHT] * scale, t.v_pos[VPos::BOTTOM_LEFT] * scale, t.v_pos[VPos::TOP_RIGHT] * scale, distance2);
//if (tri1 || tri2)
if(contains)
{
t.ColorTile(DirectX::Colors::Crimson);
printf("[Debug] Map Tile(%d, %d): Map Height: %d, XTER: %x, Water Height:%d, ALTM: %d, XBLD: %x, XZON: %x, XUND: %x, XBIT: %x\n",
Expand All @@ -549,6 +596,7 @@ void Scene::MouseClick()
}
exit_loop:
return;
*/
}

void Scene::MultiplyMovementSpeed(float value)
Expand All @@ -569,18 +617,34 @@ void Scene::Render()
m_d3dContext->ClearRenderTargetView(m_renderTargetView.Get(), DirectX::Colors::CornflowerBlue);
m_d3dContext->ClearDepthStencilView(m_depthStencilView.Get(), D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
m_d3dContext->OMSetRenderTargets(1, m_renderTargetView.GetAddressOf(), m_depthStencilView.Get());
m_d3dContext->RSSetViewports(1, &viewport);
m_d3dContext->RSSetViewports(1, &viewport);

if (render_scene)
{

if (render_models)
{
{
for (Model3D* model3d : v_model3d)
{
if (!use_render_distance || Vector3::Distance(m_position, model3d->origin_scaled) < scaled_render_distance)
{
model3d->model->Draw(m_d3dContext.Get(), *m_states, model3d->m_world, m_view, m_proj);
//model3d->model->Draw(m_d3dContext.Get(), *m_states, model3d->m_world, m_view, m_proj);
/*
for (std::shared_ptr<DirectX::ModelMesh> mesh : model3d->model->meshes)
{
Vector3 test = m_viewport.Project(mesh->boundingBox.Center, m_proj, m_view, m_world);
if (test.x > 0 && test.x < m_outputWidth && test.y > 0 && test.y < m_outputHeight)
{
model3d->model->Draw(m_d3dContext.Get(), *m_states, model3d->m_world, m_view, m_proj);
break;
}
}
*/

//Vector3 test = m_viewport.Project(model3d->origin, m_proj, m_view, m_world);
//if (test.x > -64 && test.x < m_outputWidth + 64 && test.y > -48 && test.y < m_outputHeight + 48)
model3d->model->Draw(m_d3dContext.Get(), *m_states, model3d->m_world, m_view, m_proj);

}

/*
Expand Down Expand Up @@ -699,6 +763,18 @@ void Scene::Render()
device_context->DrawTextLayout(D2D1::Point2F(2.0f, 2.0f + 30.f), text_layout5.Get(), whiteBrush.Get());
//Account for text size, currently set to size of 10.f
device_context->DrawTextLayout(D2D1::Point2F(client_cx - 2.5f, client_cy - 5.f), text_layout4.Get(), whiteBrush.Get());

/*
Microsoft::WRL::ComPtr<IDWriteTextLayout> text_layout6;
wfactory->CreateTextLayout(L"X", 1, format, m_outputWidth, m_outputHeight, &text_layout6);
Vector3 v = m_viewport.Project(v_model3d.at(0)->origin, m_proj, m_view, m_world);
device_context->DrawTextLayout(D2D1::Point2F(v.x, v.y), text_layout6.Get(), whiteBrush.Get());
*/





device_context->EndDraw();
}
}
Expand Down Expand Up @@ -863,10 +939,36 @@ void Scene::TransformHighwayOnRamp(const MapTile* map_tile, Model3D* model)
*/
void Scene::AddSecondaryModel(const MapSceneTile& t, const Model3D* rmodel)
{
if (t.map_tile->xter == XTER_FLAT && XBLD_IS_TREE(t.map_tile->xbld))
{ //only add trunks if on a slope
return;
}

int32_t model_id = 0;
bool repeat_y = false;
switch (t.map_tile->xbld)
{
case XBLD_TREES_1:
model_id = SceneryObject::TREE_TRUNKS_1;
break;
case XBLD_TREES_2:
model_id = SceneryObject::TREE_TRUNKS_2;
break;
case XBLD_TREES_3:
model_id = SceneryObject::TREE_TRUNKS_3;
break;
case XBLD_TREES_4:
model_id = SceneryObject::TREE_TRUNKS_4;
break;
case XBLD_TREES_5:
model_id = SceneryObject::TREE_TRUNKS_5;
break;
case XBLD_TREES_6:
model_id = SceneryObject::TREE_TRUNKS_6;
break;
case XBLD_TREES_7:
model_id = SceneryObject::TREE_TRUNKS_7;
break;
case XBLD_HIGHWAY_CROSSOVER_1:
model_id = XBLD_ROAD_2;
break;
Expand Down
1 change: 1 addition & 0 deletions SC2KRender/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class Scene
DirectX::SimpleMath::Matrix m_world;
DirectX::SimpleMath::Matrix m_view;
DirectX::SimpleMath::Matrix m_proj;
DirectX::SimpleMath::Viewport m_viewport;
DX::StepTimer m_timer;
float rotation_x = 0.0f;
float rotation_y = 0.8f;
Expand Down
10 changes: 9 additions & 1 deletion SC2KRender/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ enum XTERType
#define XBLD_IS_HYDROELECTRIC(v) (v >= XBLD_HYDROELECTRIC_1 && v <= XBLD_HYDROELECTRIC_2)
#define XBLD_IS_NON_BUILDING(v) (v >= XBLD_CLEAR && v <= 0x6F)
#define XBLD_IS_BUILDING(v) (v >= XBLD_LOWER_CLASS_1)
#define XBLD_IS_TREES(v) (v >= XBLD_TREES_1 && v <= XBLD_TREES_7)

enum XBLDType
{
Expand Down Expand Up @@ -231,5 +232,12 @@ enum XBLDType

enum SceneryObject
{
PILLAR = 300
PILLAR = 300,
TREE_TRUNKS_1 = 306,
TREE_TRUNKS_2 = 307,
TREE_TRUNKS_3 = 308,
TREE_TRUNKS_4 = 309,
TREE_TRUNKS_5 = 310,
TREE_TRUNKS_6 = 311,
TREE_TRUNKS_7 = 312
};
9 changes: 8 additions & 1 deletion SC2KRender/assets/assetmap.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,11 @@
213,213_big_park
214,214_school
215,215_stadium
300,000_pillar2
300,000_pillar2
306,306_tree_trunks
307,307_tree_trunks
308,308_tree_trunks
309,309_tree_trunks
310,310_tree_trunks
311,311_tree_trunks
312,312_tree_trunks
Binary file modified SC2KRender/assets/models/006_trees.cmo
Binary file not shown.
Binary file modified SC2KRender/assets/models/007_trees.cmo
Binary file not shown.
Binary file modified SC2KRender/assets/models/008_trees.cmo
Binary file not shown.
Binary file modified SC2KRender/assets/models/009_trees.cmo
Binary file not shown.
Binary file modified SC2KRender/assets/models/010_trees.cmo
Binary file not shown.
Binary file modified SC2KRender/assets/models/011_trees.cmo
Binary file not shown.
Binary file modified SC2KRender/assets/models/012_trees.cmo
Binary file not shown.
Binary file added SC2KRender/assets/models/306_tree_trunks.cmo
Binary file not shown.
Binary file added SC2KRender/assets/models/307_tree_trunks.cmo
Binary file not shown.
Binary file added SC2KRender/assets/models/308_tree_trunks.cmo
Binary file not shown.
Binary file added SC2KRender/assets/models/309_tree_trunks.cmo
Binary file not shown.
Binary file added SC2KRender/assets/models/310_tree_trunks.cmo
Binary file not shown.
Binary file added SC2KRender/assets/models/311_tree_trunks.cmo
Binary file not shown.
Binary file added SC2KRender/assets/models/312_tree_trunks.cmo
Binary file not shown.

0 comments on commit 90336ec

Please sign in to comment.