generated from Kaweees/cpp-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
61 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include <cuda_runtime.h> | ||
#include <device_launch_parameters.h> | ||
#include "../include/vector3d.hpp" | ||
#include "../include/vector2d.hpp" | ||
#include "../include/constants.hpp" | ||
|
||
namespace graphics { | ||
__device__ __host__ void cudaRotate(Vector3D* vertex, double roll, double pitch, double yaw); | ||
__device__ __host__ void cudaTranslate(Vector3D* vertex, double x, double y, double z); | ||
__device__ __host__ void cudaProject(const Vector3D* vertex, Vector2D* projectedVertex); | ||
} // namespace graphics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
#include "../include/display.metal" | ||
#endif | ||
|
||
|
||
#include <SDL2/SDL.h> | ||
|
||
#include "../include/constants.hpp" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include "../include/vector3d.cuh" | ||
#include <math.h> | ||
|
||
namespace graphics { | ||
|
||
__device__ __host__ void cudaRotate(Vector3D* vertex, double roll, double pitch, double yaw) { | ||
// Roll (rotation around X-axis) | ||
double cosR = cos(roll); | ||
double sinR = sin(roll); | ||
double y = vertex->y; | ||
double z = vertex->z; | ||
vertex->y = y * cosR - z * sinR; | ||
vertex->z = z * cosR + y * sinR; | ||
|
||
// Pitch (rotation around Y-axis) | ||
double cosP = cos(pitch); | ||
double sinP = sin(pitch); | ||
double x = vertex->x; | ||
z = vertex->z; | ||
vertex->x = x * cosP + z * sinP; | ||
vertex->z = z * cosP - x * sinP; | ||
|
||
// Yaw (rotation around Z-axis) | ||
double cosY = cos(yaw); | ||
double sinY = sin(yaw); | ||
x = vertex->x; | ||
y = vertex->y; | ||
vertex->x = x * cosY - y * sinY; | ||
vertex->y = y * cosY + x * sinY; | ||
} | ||
|
||
__device__ __host__ void cudaTranslate(Vector3D* vertex, double x, double y, double z) { | ||
vertex->x += x; | ||
vertex->y += y; | ||
vertex->z += z; | ||
} | ||
|
||
__device__ __host__ void cudaProject(const Vector3D* vertex, Vector2D* projectedVertex) { | ||
projectedVertex->x = (vertex->x * FOV) / vertex->z; | ||
projectedVertex->y = (vertex->y * FOV) / vertex->z; | ||
} | ||
|
||
} // namespace graphics |