fix alignment bug, cleanup
This commit is contained in:
parent
a67c2d19d6
commit
dec83055a4
2
Makefile
2
Makefile
|
@ -4,7 +4,7 @@ BUILD_DIR := build
|
|||
TARGET := $(BUILD_DIR)/holst
|
||||
STD ?= c++23
|
||||
|
||||
CXXFLAGS := -std=$(STD) -Wall -Wextra -O2 -Iinclude
|
||||
CXXFLAGS := -std=$(STD) -g -Wall -Wextra -O2 -Iinclude
|
||||
LDFLAGS :=
|
||||
LDLIBS := -lSDL2
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ struct Canvas {
|
|||
pixels[y * width + x] = color;
|
||||
}
|
||||
}
|
||||
|
||||
void set_pixel(int x, int y, Color color) {
|
||||
if (x >= 0 && x < width && y >= 0 && y < height) {
|
||||
pixels[y * width + x] = to_rgb(color);
|
||||
|
|
|
@ -32,7 +32,7 @@ int main() {
|
|||
void *pixels;
|
||||
int pitch;
|
||||
SDL_LockTexture(texture, nullptr, &pixels, &pitch);
|
||||
memcpy(pixels, canvas.pixels.data(), canvas.pixels.size() * sizeof(Color));
|
||||
memcpy(pixels, canvas.pixels.data(), canvas.pixels.size() * sizeof(Rgb));
|
||||
SDL_UnlockTexture(texture);
|
||||
|
||||
SDL_RenderClear(renderer);
|
||||
|
|
|
@ -16,31 +16,31 @@ std::atomic<bool> running(true);
|
|||
SimulationState initialize_solar_system() {
|
||||
SimulationState state;
|
||||
state.bodies.push_back(Body{"Sol", Vec3(0.0, 0.0, 0.0), Vec3(0.0, 0.0, 0.0),
|
||||
1.989e30, 100.0}); // a star similar to the sun
|
||||
1.989e30, 10.0}); // a star similar to the sun
|
||||
state.bodies.push_back(Body{"Mercury", Vec3(57.909e9, 0.0, 0.0),
|
||||
Vec3(0.0, 47.36e3, 0.0), 0.33011e24,
|
||||
10}); // a planet similar to mercury
|
||||
1}); // a planet similar to mercury
|
||||
state.bodies.push_back(Body{"Venus", Vec3(108.209e9, 0.0, 0.0),
|
||||
Vec3(0.0, 35.02e3, 0.0), 4.8675e24,
|
||||
30}); // a planet similar to venus
|
||||
3}); // a planet similar to venus
|
||||
state.bodies.push_back(Body{"Earth", Vec3(149.596e9, 0.0, 0.0),
|
||||
Vec3(0.0, 29.78e3, 0.0), 5.9724e24,
|
||||
30}); // a planet similar to earth
|
||||
3}); // a planet similar to earth
|
||||
state.bodies.push_back(Body{"Mars", Vec3(227.923e9, 0.0, 0.0),
|
||||
Vec3(0.0, 24.07e3, 0.0), 0.64171e24,
|
||||
20}); // a planet similar to mars
|
||||
2}); // a planet similar to mars
|
||||
state.bodies.push_back(Body{"Jupiter", Vec3(778.570e9, 0.0, 0.0),
|
||||
Vec3(0.0, 13e3, 0.0), 1898.19e24,
|
||||
50}); // a planet similar to jupiter
|
||||
5}); // a planet similar to jupiter
|
||||
state.bodies.push_back(Body{"Saturn", Vec3(1433.529e9, 0.0, 0.0),
|
||||
Vec3(0.0, 9.68e3, 0.0), 568.34e24,
|
||||
40}); // a planet similar to saturn
|
||||
4}); // a planet similar to saturn
|
||||
state.bodies.push_back(Body{"Uranus", Vec3(2872.463e9, 0.0, 0.0),
|
||||
Vec3(0.0, 6.80e3, 0.0), 86.813e24,
|
||||
30}); // a planet similar to uranus
|
||||
3}); // a planet similar to uranus
|
||||
state.bodies.push_back(Body{"Neptune", Vec3(4495.060e9, 0.0, 0.0),
|
||||
Vec3(0.0, 5.43e3, 0.0), 102.413e24,
|
||||
30}); // a planet similar to neptune
|
||||
3}); // a planet similar to neptune
|
||||
return state;
|
||||
}
|
||||
|
||||
|
@ -144,6 +144,7 @@ void render(SimulationState state, Canvas &canvas) {
|
|||
const double SCALE = 1e9;
|
||||
|
||||
for (auto b : state.bodies) {
|
||||
// we need to swap y and z because the raytracter uses opengl style coordinates
|
||||
auto bb = b.position / SCALE;
|
||||
world.add(make_shared<sphere>(Vec3(bb.x(), bb.z(), bb.y()), b.radius));
|
||||
}
|
||||
|
@ -152,7 +153,7 @@ void render(SimulationState state, Canvas &canvas) {
|
|||
auto focal_length = 1.0;
|
||||
auto viewport_height = 2.0;
|
||||
auto viewport_width = viewport_height * (float(canvas.width) / canvas.height);
|
||||
auto camera_center = Point3(0, 0, -100);
|
||||
auto camera_center = Point3(0, 0, 100);
|
||||
|
||||
// Calculate the vectors across the horizontal and down the vertical viewport
|
||||
// edges.
|
||||
|
|
Loading…
Reference in New Issue