Compare commits
No commits in common. "940c1d706bc5330eead7116d5e006b994f92b707" and "e234dda860068e3d10a5da6ade1d9ec23cdbd41c" have entirely different histories.
940c1d706b
...
e234dda860
6 changed files with 363 additions and 374 deletions
50
World.cpp
50
World.cpp
|
@ -107,9 +107,6 @@ float World::castRay(float originX, float originY, float orientation) const
|
||||||
* the grid for the other one
|
* the grid for the other one
|
||||||
* - Depending on the orientation, signs must be taken into account
|
* - Depending on the orientation, signs must be taken into account
|
||||||
* to work 360°
|
* to work 360°
|
||||||
* - Those formulas consider regular axes (x→,y↑), however the world is
|
|
||||||
* built around left-handed axes (x→,y↓), so the rendered world is
|
|
||||||
* mirrored. This also explains some weird signs for rotations.
|
|
||||||
*/
|
*/
|
||||||
/* Offsets to get back on the grid from the ray's origin. */
|
/* Offsets to get back on the grid from the ray's origin. */
|
||||||
float hOffsetX;
|
float hOffsetX;
|
||||||
|
@ -151,7 +148,7 @@ float World::castRay(float originX, float originY, float orientation) const
|
||||||
if (orientation < 180) {
|
if (orientation < 180) {
|
||||||
vOffsetX = ceilf(originX);
|
vOffsetX = ceilf(originX);
|
||||||
vOffsetY = ceilf(originX) - originX;
|
vOffsetY = ceilf(originX) - originX;
|
||||||
vDir = 1;
|
vDir = +1;
|
||||||
vRound = 0;
|
vRound = 0;
|
||||||
} else {
|
} else {
|
||||||
vOffsetX = floorf(originX);
|
vOffsetX = floorf(originX);
|
||||||
|
@ -242,8 +239,6 @@ void World::render(sf::RenderWindow& window) const
|
||||||
window.draw(ground);
|
window.draw(ground);
|
||||||
window.draw(ceiling);
|
window.draw(ceiling);
|
||||||
|
|
||||||
const float worldToCamera = (player.focalLength*2)/player.sensorSize;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Throw rays and draw walls over the ceiling and ground.
|
* Throw rays and draw walls over the ceiling and ground.
|
||||||
* Only throws in the plane, which doesn't work for levels/3D.
|
* Only throws in the plane, which doesn't work for levels/3D.
|
||||||
|
@ -257,7 +252,7 @@ void World::render(sf::RenderWindow& window) const
|
||||||
} else if (rayAngle > 360) {
|
} else if (rayAngle > 360) {
|
||||||
rayAngle -= 360;
|
rayAngle -= 360;
|
||||||
}
|
}
|
||||||
float obstacleScale = worldToCamera / castRay(player.x, player.y, rayAngle);
|
float obstacleScale = player.focalLength*2/(castRay(player.x, player.y, rayAngle)*player.sensorSize);
|
||||||
/* 2 Is wall height in meters. */
|
/* 2 Is wall height in meters. */
|
||||||
fillColumn(window, i, obstacleScale);
|
fillColumn(window, i, obstacleScale);
|
||||||
}
|
}
|
||||||
|
@ -274,7 +269,7 @@ void World::step(const float& stepTime) {
|
||||||
player.rotate(player.currentRotationSpeed*stepTime);
|
player.rotate(player.currentRotationSpeed*stepTime);
|
||||||
|
|
||||||
#ifdef IMGUI
|
#ifdef IMGUI
|
||||||
if (ImGui::Begin("MapEdit")) {
|
ImGui::Begin("MapEdit");
|
||||||
static int blockToPlace = 1;
|
static int blockToPlace = 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -282,27 +277,27 @@ void World::step(const float& stepTime) {
|
||||||
* Dear ImGui layout an allows adding things on the side.
|
* Dear ImGui layout an allows adding things on the side.
|
||||||
*/
|
*/
|
||||||
ImGui::BeginGroup();
|
ImGui::BeginGroup();
|
||||||
for (int y = 0; y < h; y++) {
|
for (int y = 0 ; y < h ; y++) {
|
||||||
for (int x = 0; x < w; x++) {
|
for (int x = 0 ; x < w ; x++) {
|
||||||
ImGui::PushID(x + y * w);
|
ImGui::PushID(x + y*w);
|
||||||
if (x > 0)
|
if (x > 0)
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
BlockType currentBlock = map[x + w * y];
|
BlockType currentBlock = map[x + w*y];
|
||||||
|
|
||||||
ImVec4 hoverColor;
|
ImVec4 hoverColor;
|
||||||
switch ((BlockType) blockToPlace) {
|
switch ((BlockType)blockToPlace) {
|
||||||
case BlockType::WALL:
|
case BlockType::WALL:
|
||||||
hoverColor = (ImVec4) Colors::Wall;
|
hoverColor = (ImVec4)Colors::Wall;
|
||||||
break;
|
break;
|
||||||
case BlockType::DOOR:
|
case BlockType::DOOR:
|
||||||
hoverColor = (ImVec4) Colors::Door;
|
hoverColor = (ImVec4)Colors::Door;
|
||||||
break;
|
break;
|
||||||
case BlockType::WINDOW:
|
case BlockType::WINDOW:
|
||||||
hoverColor = (ImVec4) Colors::Window;
|
hoverColor = (ImVec4)Colors::Window;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* Default header color, it seems ? */
|
/* Default header color, it seems ? */
|
||||||
hoverColor = (ImVec4) ImColor(188, 120, 32);
|
hoverColor = (ImVec4)ImColor(188, 120, 32);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, hoverColor);
|
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, hoverColor);
|
||||||
|
@ -310,23 +305,22 @@ void World::step(const float& stepTime) {
|
||||||
ImVec4 blockColor;
|
ImVec4 blockColor;
|
||||||
switch (currentBlock) {
|
switch (currentBlock) {
|
||||||
case BlockType::WALL:
|
case BlockType::WALL:
|
||||||
blockColor = (ImVec4) Colors::Wall;
|
blockColor = (ImVec4)Colors::Wall;
|
||||||
break;
|
break;
|
||||||
case BlockType::DOOR:
|
case BlockType::DOOR:
|
||||||
blockColor = (ImVec4) Colors::Door;
|
blockColor = (ImVec4)Colors::Door;
|
||||||
break;
|
break;
|
||||||
case BlockType::WINDOW:
|
case BlockType::WINDOW:
|
||||||
blockColor = (ImVec4) Colors::Window;
|
blockColor = (ImVec4)Colors::Window;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
blockColor = (ImVec4) ImColor(188, 120, 32);
|
blockColor = (ImVec4)ImColor(188, 120, 32);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ImGui::PushStyleColor(ImGuiCol_Header, blockColor);
|
ImGui::PushStyleColor(ImGuiCol_Header, blockColor);
|
||||||
|
|
||||||
if (ImGui::Selectable("", currentBlock != BlockType::AIR, 0, ImVec2(10, 10))) {
|
if(ImGui::Selectable("", currentBlock != BlockType::AIR, 0, ImVec2(10, 10))) {
|
||||||
map[x + w * y] =
|
map[x + w*y] = currentBlock == (BlockType)blockToPlace ? BlockType::AIR : (BlockType)blockToPlace;
|
||||||
currentBlock == (BlockType) blockToPlace ? BlockType::AIR : (BlockType) blockToPlace;
|
|
||||||
}
|
}
|
||||||
ImGui::PopStyleColor(2);
|
ImGui::PopStyleColor(2);
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
|
@ -338,12 +332,12 @@ void World::step(const float& stepTime) {
|
||||||
ImGui::BeginGroup();
|
ImGui::BeginGroup();
|
||||||
ImGui::Indent();
|
ImGui::Indent();
|
||||||
ImGui::Text("Place :");
|
ImGui::Text("Place :");
|
||||||
ImGui::RadioButton("Wall", &blockToPlace, (int) BlockType::WALL);
|
ImGui::RadioButton("Wall", &blockToPlace, (int)BlockType::WALL);
|
||||||
ImGui::RadioButton("Door", &blockToPlace, (int) BlockType::DOOR);
|
ImGui::RadioButton("Door", &blockToPlace, (int)BlockType::DOOR);
|
||||||
ImGui::RadioButton("Window", &blockToPlace, (int) BlockType::WINDOW);
|
ImGui::RadioButton("Window", &blockToPlace, (int)BlockType::WINDOW);
|
||||||
ImGui::Unindent();
|
ImGui::Unindent();
|
||||||
ImGui::EndGroup();
|
ImGui::EndGroup();
|
||||||
}
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
7
main.cpp
7
main.cpp
|
@ -115,12 +115,7 @@ int main()
|
||||||
ImGui::SetNextWindowBgAlpha(0.2f);
|
ImGui::SetNextWindowBgAlpha(0.2f);
|
||||||
ImGui::Begin("FPS", nullptr ,window_flags);
|
ImGui::Begin("FPS", nullptr ,window_flags);
|
||||||
if (fpsDataClock.getElapsedTime().asMilliseconds() > 20) {
|
if (fpsDataClock.getElapsedTime().asMilliseconds() > 20) {
|
||||||
if (frameCount >= 100) {
|
frameTimings[frameCount%100] = static_cast<float>(deltaT.asMicroseconds());
|
||||||
memmove(frameTimings, frameTimings + 1, 99 * sizeof(float));
|
|
||||||
frameTimings[99] = static_cast<float>(deltaT.asMicroseconds());
|
|
||||||
} else [[unlikely]] {
|
|
||||||
frameTimings[frameCount] = static_cast<float>(deltaT.asMicroseconds());
|
|
||||||
}
|
|
||||||
frameCount++;
|
frameCount++;
|
||||||
fpsDataClock.restart();
|
fpsDataClock.restart();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue