mirror of
https://github.com/MartinOpat/cuda-based-raytrace.git
synced 2025-06-07 02:13:10 +02:00
Refactored functionality into separate files
This commit is contained in:
9
linalg/linalg.h
Normal file
9
linalg/linalg.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef LINALG_H
|
||||
#define LINALG_H
|
||||
|
||||
#include "vec.h"
|
||||
#include "mat.h"
|
||||
|
||||
#endif // LINALG_H
|
||||
1
linalg/mat.h
Normal file
1
linalg/mat.h
Normal file
@@ -0,0 +1 @@
|
||||
#pragma once
|
||||
18
linalg/vec.h
Normal file
18
linalg/vec.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
#include <cmath>
|
||||
|
||||
struct Vec3 { // TODO: Maybe make this into a class
|
||||
double x, y, z;
|
||||
|
||||
__host__ __device__ Vec3() : x(0), y(0), z(0) {}
|
||||
__host__ __device__ Vec3(double x, double y, double z) : x(x), y(y), z(z) {}
|
||||
|
||||
__host__ __device__ Vec3 operator+(const Vec3& b) const { return Vec3(x + b.x, y + b.y, z + b.z); }
|
||||
__host__ __device__ Vec3 operator-(const Vec3& b) const { return Vec3(x - b.x, y - b.y, z - b.z); }
|
||||
__host__ __device__ Vec3 operator*(double b) const { return Vec3(x * b, y * b, z * b); }
|
||||
__host__ __device__ Vec3 operator-() const { return Vec3(-x, -y, -z); }
|
||||
__host__ __device__ double dot(const Vec3& b) const { return x * b.x + y * b.y + z * b.z; }
|
||||
__host__ __device__ Vec3 normalize() const { double len = sqrt(x * x + y * y + z * z); return Vec3(x / len, y / len, z / len); }
|
||||
};
|
||||
Reference in New Issue
Block a user