Would help if I actually added the files
This commit is contained in:
@@ -38,11 +38,12 @@ public:
|
|||||||
int create_shared_context();
|
int create_shared_context();
|
||||||
int create_command_queue();
|
int create_command_queue();
|
||||||
int compile_kernel(std::string kernel_source, bool is_path, std::string kernel_name);
|
int compile_kernel(std::string kernel_source, bool is_path, std::string kernel_name);
|
||||||
|
int create_buffer(std::string buffer_name, cl_uint size, void* data);
|
||||||
|
int create_buffer(std::string buffer_name, cl_uint size, void* data, cl_mem_flags flags);
|
||||||
int set_kernel_arg(std::string kernel_name, int index, std::string buffer_name);
|
int set_kernel_arg(std::string kernel_name, int index, std::string buffer_name);
|
||||||
int store_buffer(cl_mem, std::string buffer_name);
|
int store_buffer(cl_mem, std::string buffer_name);
|
||||||
int run_kernel(std::string kernel_name, const int work_size);
|
int run_kernel(std::string kernel_name, const int work_size);
|
||||||
|
|
||||||
|
|
||||||
bool assert(int error_code, std::string function_name);
|
bool assert(int error_code, std::string function_name);
|
||||||
|
|
||||||
cl_device_id getDeviceID();
|
cl_device_id getDeviceID();
|
||||||
|
|||||||
45
include/Camera.h
Normal file
45
include/Camera.h
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <SFML/System/Vector3.hpp>
|
||||||
|
#include <SFML/System/Vector2.hpp>
|
||||||
|
#include "util.hpp"
|
||||||
|
|
||||||
|
class Camera {
|
||||||
|
public:
|
||||||
|
|
||||||
|
enum DIRECTION { FORWARD, REARWARD, LEFT, RIGHT, UP, DOWN };
|
||||||
|
|
||||||
|
Camera();
|
||||||
|
Camera(sf::Vector3f position, sf::Vector2f direction);
|
||||||
|
~Camera();
|
||||||
|
|
||||||
|
int set_position(sf::Vector3f position);
|
||||||
|
|
||||||
|
int add_static_impulse(sf::Vector3f impulse);
|
||||||
|
int add_relative_impulse(DIRECTION direction);
|
||||||
|
|
||||||
|
int slew_camera(sf::Vector2f input);
|
||||||
|
|
||||||
|
int update();
|
||||||
|
|
||||||
|
void* get_direction_pointer();
|
||||||
|
void* get_position_pointer();
|
||||||
|
|
||||||
|
sf::Vector3f get_movement();
|
||||||
|
sf::Vector3f get_position();
|
||||||
|
sf::Vector2f get_direction();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
float friction_coefficient = 0.1;
|
||||||
|
float default_impulse = 1.0;
|
||||||
|
|
||||||
|
// 3D vector
|
||||||
|
sf::Vector3f movement;
|
||||||
|
|
||||||
|
// XYZ
|
||||||
|
sf::Vector3f position;
|
||||||
|
|
||||||
|
// These are spherical coords
|
||||||
|
sf::Vector2f direction;
|
||||||
|
};
|
||||||
|
|
||||||
@@ -1,139 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2016 Laurent Gomila (laurent@sfml-dev.org)
|
|
||||||
//
|
|
||||||
// This software is provided 'as-is', without any express or implied warranty.
|
|
||||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
|
||||||
//
|
|
||||||
// Permission is granted to anyone to use this software for any purpose,
|
|
||||||
// including commercial applications, and to alter it and redistribute it freely,
|
|
||||||
// subject to the following restrictions:
|
|
||||||
//
|
|
||||||
// 1. The origin of this software must not be misrepresented;
|
|
||||||
// you must not claim that you wrote the original software.
|
|
||||||
// If you use this software in a product, an acknowledgment
|
|
||||||
// in the product documentation would be appreciated but is not required.
|
|
||||||
//
|
|
||||||
// 2. Altered source versions must be plainly marked as such,
|
|
||||||
// and must not be misrepresented as being the original software.
|
|
||||||
//
|
|
||||||
// 3. This notice may not be removed or altered from any source distribution.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#ifndef GAME_VECTOR3_H
|
|
||||||
#define GAME_VECTOR3_H
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
class Vector3
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
// Default constructor
|
|
||||||
// Creates a Vector3(0, 0, 0).
|
|
||||||
Vector3();
|
|
||||||
|
|
||||||
|
|
||||||
// Construct the vector from its coordinates
|
|
||||||
Vector3(T X, T Y, T Z);
|
|
||||||
|
|
||||||
|
|
||||||
// Construct the vector from another type of vector
|
|
||||||
// This constructor doesn't replace the copy constructor,
|
|
||||||
// it's called only when U != T.
|
|
||||||
// A call to this constructor will fail to compile if U
|
|
||||||
// is not convertible to T.
|
|
||||||
template <typename U>
|
|
||||||
explicit Vector3(const Vector3<U>& vector);
|
|
||||||
|
|
||||||
// Member data
|
|
||||||
T x;
|
|
||||||
T y;
|
|
||||||
T z;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Vector3
|
|
||||||
// Overload of unary operator -
|
|
||||||
// left Vector to negate
|
|
||||||
// Memberwise opposite of the vector
|
|
||||||
template <typename T>
|
|
||||||
Vector3<T> operator -(const Vector3<T>& left);
|
|
||||||
|
|
||||||
// Overload of binary operator +=
|
|
||||||
// This operator performs a memberwise addition of both vectors,
|
|
||||||
// and assigns the result to left.
|
|
||||||
// returns Reference to left
|
|
||||||
template <typename T>
|
|
||||||
Vector3<T>& operator +=(Vector3<T>& left, const Vector3<T>& right);
|
|
||||||
|
|
||||||
// Overload of binary operator -=
|
|
||||||
// This operator performs a memberwise subtraction of both vectors,
|
|
||||||
// and assigns the result to left.
|
|
||||||
// returns Reference to left
|
|
||||||
template <typename T>
|
|
||||||
Vector3<T>& operator -=(Vector3<T>& left, const Vector3<T>& right);
|
|
||||||
|
|
||||||
// Overload of binary operator +
|
|
||||||
// returns Memberwise addition of both vectors
|
|
||||||
template <typename T>
|
|
||||||
Vector3<T> operator +(const Vector3<T>& left, const Vector3<T>& right);
|
|
||||||
// Overload of binary operator -
|
|
||||||
// returns Memberwise subtraction of both vectors
|
|
||||||
template <typename T>
|
|
||||||
Vector3<T> operator -(const Vector3<T>& left, const Vector3<T>& right);
|
|
||||||
|
|
||||||
// Overload of binary operator *
|
|
||||||
// returns Memberwise multiplication by right
|
|
||||||
template <typename T>
|
|
||||||
Vector3<T> operator *(const Vector3<T>& left, T right);
|
|
||||||
|
|
||||||
// Overload of binary operator *
|
|
||||||
// returns Memberwise multiplication by left
|
|
||||||
template <typename T>
|
|
||||||
Vector3<T> operator *(T left, const Vector3<T>& right);
|
|
||||||
|
|
||||||
// Overload of binary operator *=
|
|
||||||
// This operator performs a memberwise multiplication by right,
|
|
||||||
// and assigns the result to left.
|
|
||||||
// returns Reference to left
|
|
||||||
template <typename T>
|
|
||||||
Vector3<T>& operator *=(Vector3<T>& left, T right);
|
|
||||||
|
|
||||||
// Overload of binary operator /
|
|
||||||
// returns Memberwise division by right
|
|
||||||
template <typename T>
|
|
||||||
Vector3<T> operator /(const Vector3<T>& left, T right);
|
|
||||||
|
|
||||||
// Overload of binary operator /=
|
|
||||||
// This operator performs a memberwise division by right,
|
|
||||||
// and assigns the result to left.
|
|
||||||
// returns Reference to left
|
|
||||||
template <typename T>
|
|
||||||
Vector3<T>& operator /=(Vector3<T>& left, T right);
|
|
||||||
|
|
||||||
// Overload of binary operator ==
|
|
||||||
// This operator compares strict equality between two vectors.
|
|
||||||
// returns True if left is equal to right
|
|
||||||
template <typename T>
|
|
||||||
bool operator ==(const Vector3<T>& left, const Vector3<T>& right);
|
|
||||||
|
|
||||||
// Overload of binary operator !=
|
|
||||||
// This operator compares strict difference between two vectors.
|
|
||||||
// returns True if left is not equal to right
|
|
||||||
template <typename T>
|
|
||||||
bool operator !=(const Vector3<T>& left, const Vector3<T>& right);
|
|
||||||
|
|
||||||
#include <SFML/System/Vector3.inl>
|
|
||||||
|
|
||||||
// Define the most common types
|
|
||||||
typedef Vector3<int> Vector3i;
|
|
||||||
typedef Vector3<float> Vector3f;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
474
include/Vector4.hpp
Normal file
474
include/Vector4.hpp
Normal file
@@ -0,0 +1,474 @@
|
|||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
// SFML - Simple and Fast Multimedia Library
|
||||||
|
// Copyright (C) 2007-2016 Laurent Gomila (laurent@sfml-dev.org)
|
||||||
|
//
|
||||||
|
// This software is provided 'as-is', without any express or implied warranty.
|
||||||
|
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||||
|
//
|
||||||
|
// Permission is granted to anyone to use this software for any purpose,
|
||||||
|
// including commercial applications, and to alter it and redistribute it freely,
|
||||||
|
// subject to the following restrictions:
|
||||||
|
//
|
||||||
|
// 1. The origin of this software must not be misrepresented;
|
||||||
|
// you must not claim that you wrote the original software.
|
||||||
|
// If you use this software in a product, an acknowledgment
|
||||||
|
// in the product documentation would be appreciated but is not required.
|
||||||
|
//
|
||||||
|
// 2. Altered source versions must be plainly marked as such,
|
||||||
|
// and must not be misrepresented as being the original software.
|
||||||
|
//
|
||||||
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#ifndef SFML_VECTOR4_H
|
||||||
|
#define SFML_VECTOR4_H
|
||||||
|
|
||||||
|
namespace sf {
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Utility template class for manipulating
|
||||||
|
/// 2-dimensional vectors
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
class Vector4 {
|
||||||
|
public:
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Default constructor
|
||||||
|
///
|
||||||
|
/// Creates a Vector4(0, 0).
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
Vector4();
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Construct the vector from its coordinates
|
||||||
|
///
|
||||||
|
/// \param X X coordinate
|
||||||
|
/// \param Y Y coordinate
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
Vector4(T X, T Y, T Z, T W);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Construct the vector from another type of vector
|
||||||
|
///
|
||||||
|
/// This constructor doesn't replace the copy constructor,
|
||||||
|
/// it's called only when U != T.
|
||||||
|
/// A call to this constructor will fail to compile if U
|
||||||
|
/// is not convertible to T.
|
||||||
|
///
|
||||||
|
/// \param vector Vector to convert
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename U>
|
||||||
|
explicit Vector4(const Vector4<U>& vector);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
// Member data
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
T x; ///< X coordinate of the vector
|
||||||
|
T y; ///< Y coordinate of the vector
|
||||||
|
T z; ///< Z coordinate of the vector
|
||||||
|
T w; ///< W coordinate of the vector
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \relates Vector4
|
||||||
|
/// \brief Overload of unary operator -
|
||||||
|
///
|
||||||
|
/// \param right Vector to negate
|
||||||
|
///
|
||||||
|
/// \return Memberwise opposite of the vector
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
Vector4<T> operator -(const Vector4<T>& right);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \relates Vector4
|
||||||
|
/// \brief Overload of binary operator +=
|
||||||
|
///
|
||||||
|
/// This operator performs a memberwise addition of both vectors,
|
||||||
|
/// and assigns the result to \a left.
|
||||||
|
///
|
||||||
|
/// \param left Left operand (a vector)
|
||||||
|
/// \param right Right operand (a vector)
|
||||||
|
///
|
||||||
|
/// \return Reference to \a left
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
Vector4<T>& operator +=(Vector4<T>& left, const Vector4<T>& right);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \relates Vector4
|
||||||
|
/// \brief Overload of binary operator -=
|
||||||
|
///
|
||||||
|
/// This operator performs a memberwise subtraction of both vectors,
|
||||||
|
/// and assigns the result to \a left.
|
||||||
|
///
|
||||||
|
/// \param left Left operand (a vector)
|
||||||
|
/// \param right Right operand (a vector)
|
||||||
|
///
|
||||||
|
/// \return Reference to \a left
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
Vector4<T>& operator -=(Vector4<T>& left, const Vector4<T>& right);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \relates Vector4
|
||||||
|
/// \brief Overload of binary operator +
|
||||||
|
///
|
||||||
|
/// \param left Left operand (a vector)
|
||||||
|
/// \param right Right operand (a vector)
|
||||||
|
///
|
||||||
|
/// \return Memberwise addition of both vectors
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
Vector4<T> operator +(const Vector4<T>& left, const Vector4<T>& right);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \relates Vector4
|
||||||
|
/// \brief Overload of binary operator -
|
||||||
|
///
|
||||||
|
/// \param left Left operand (a vector)
|
||||||
|
/// \param right Right operand (a vector)
|
||||||
|
///
|
||||||
|
/// \return Memberwise subtraction of both vectors
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
Vector4<T> operator -(const Vector4<T>& left, const Vector4<T>& right);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \relates Vector4
|
||||||
|
/// \brief Overload of binary operator *
|
||||||
|
///
|
||||||
|
/// \param left Left operand (a vector)
|
||||||
|
/// \param right Right operand (a scalar value)
|
||||||
|
///
|
||||||
|
/// \return Memberwise multiplication by \a right
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
Vector4<T> operator *(const Vector4<T>& left, T right);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \relates Vector4
|
||||||
|
/// \brief Overload of binary operator *
|
||||||
|
///
|
||||||
|
/// \param left Left operand (a scalar value)
|
||||||
|
/// \param right Right operand (a vector)
|
||||||
|
///
|
||||||
|
/// \return Memberwise multiplication by \a left
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
Vector4<T> operator *(T left, const Vector4<T>& right);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \relates Vector4
|
||||||
|
/// \brief Overload of binary operator *=
|
||||||
|
///
|
||||||
|
/// This operator performs a memberwise multiplication by \a right,
|
||||||
|
/// and assigns the result to \a left.
|
||||||
|
///
|
||||||
|
/// \param left Left operand (a vector)
|
||||||
|
/// \param right Right operand (a scalar value)
|
||||||
|
///
|
||||||
|
/// \return Reference to \a left
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
Vector4<T>& operator *=(Vector4<T>& left, T right);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \relates Vector4
|
||||||
|
/// \brief Overload of binary operator /
|
||||||
|
///
|
||||||
|
/// \param left Left operand (a vector)
|
||||||
|
/// \param right Right operand (a scalar value)
|
||||||
|
///
|
||||||
|
/// \return Memberwise division by \a right
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
Vector4<T> operator /(const Vector4<T>& left, T right);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \relates Vector4
|
||||||
|
/// \brief Overload of binary operator /=
|
||||||
|
///
|
||||||
|
/// This operator performs a memberwise division by \a right,
|
||||||
|
/// and assigns the result to \a left.
|
||||||
|
///
|
||||||
|
/// \param left Left operand (a vector)
|
||||||
|
/// \param right Right operand (a scalar value)
|
||||||
|
///
|
||||||
|
/// \return Reference to \a left
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
Vector4<T>& operator /=(Vector4<T>& left, T right);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \relates Vector4
|
||||||
|
/// \brief Overload of binary operator ==
|
||||||
|
///
|
||||||
|
/// This operator compares strict equality between two vectors.
|
||||||
|
///
|
||||||
|
/// \param left Left operand (a vector)
|
||||||
|
/// \param right Right operand (a vector)
|
||||||
|
///
|
||||||
|
/// \return True if \a left is equal to \a right
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
bool operator ==(const Vector4<T>& left, const Vector4<T>& right);
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \relates Vector4
|
||||||
|
/// \brief Overload of binary operator !=
|
||||||
|
///
|
||||||
|
/// This operator compares strict difference between two vectors.
|
||||||
|
///
|
||||||
|
/// \param left Left operand (a vector)
|
||||||
|
/// \param right Right operand (a vector)
|
||||||
|
///
|
||||||
|
/// \return True if \a left is not equal to \a right
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
bool operator !=(const Vector4<T>& left, const Vector4<T>& right);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
inline Vector4<T>::Vector4() :
|
||||||
|
x(0),
|
||||||
|
y(0),
|
||||||
|
z(0),
|
||||||
|
w(0){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
inline Vector4<T>::Vector4(T X, T Y, T Z, T W) :
|
||||||
|
x(X),
|
||||||
|
y(Y),
|
||||||
|
z(Z),
|
||||||
|
w(W) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
template <typename U>
|
||||||
|
inline Vector4<T>::Vector4(const Vector4<U>& vector) :
|
||||||
|
x(static_cast<T>(vector.x)),
|
||||||
|
y(static_cast<T>(vector.y)),
|
||||||
|
z(static_cast<T>(vector.z)),
|
||||||
|
w(static_cast<T>(vector.w)) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
inline Vector4<T> operator -(const Vector4<T>& right) {
|
||||||
|
return Vector4<T>(
|
||||||
|
-right.x,
|
||||||
|
-right.y,
|
||||||
|
-right.z,
|
||||||
|
-right.w
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
inline Vector4<T>& operator +=(Vector4<T>& left, const Vector4<T>& right) {
|
||||||
|
left.x += right.x;
|
||||||
|
left.y += right.y;
|
||||||
|
left.z += right.z;
|
||||||
|
left.w += right.w;
|
||||||
|
|
||||||
|
return left;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
inline Vector4<T>& operator -=(Vector4<T>& left, const Vector4<T>& right) {
|
||||||
|
left.x -= right.x;
|
||||||
|
left.y -= right.y;
|
||||||
|
left.z -= right.z;
|
||||||
|
left.w -= right.w;
|
||||||
|
|
||||||
|
return left;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
inline Vector4<T> operator +(const Vector4<T>& left, const Vector4<T>& right) {
|
||||||
|
return Vector4<T>(
|
||||||
|
left.x + right.x,
|
||||||
|
left.y + right.y,
|
||||||
|
left.z + right.z,
|
||||||
|
left.w + right.w
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
inline Vector4<T> operator -(const Vector4<T>& left, const Vector4<T>& right) {
|
||||||
|
return Vector4<T>(
|
||||||
|
left.x - right.x,
|
||||||
|
left.y - right.y,
|
||||||
|
left.z - right.z,
|
||||||
|
left.w - right.w
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
inline Vector4<T> operator *(const Vector4<T>& left, T right) {
|
||||||
|
return Vector4<T>(
|
||||||
|
left.x * right,
|
||||||
|
left.y * right,
|
||||||
|
left.z * right,
|
||||||
|
left.w * right
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
inline Vector4<T> operator *(T left, const Vector4<T>& right) {
|
||||||
|
return Vector4<T>(
|
||||||
|
right.x * left,
|
||||||
|
right.y * left,
|
||||||
|
right.z * left,
|
||||||
|
right.w * left
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
inline Vector4<T>& operator *=(Vector4<T>& left, T right) {
|
||||||
|
left.x *= right;
|
||||||
|
left.y *= right;
|
||||||
|
left.z *= right;
|
||||||
|
left.w *= right;
|
||||||
|
|
||||||
|
return left;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
inline Vector4<T> operator /(const Vector4<T>& left, T right) {
|
||||||
|
return Vector4<T>(
|
||||||
|
left.x / right,
|
||||||
|
left.y / right,
|
||||||
|
left.z / right,
|
||||||
|
left.w / right
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
inline Vector4<T>& operator /=(Vector4<T>& left, T right) {
|
||||||
|
left.x /= right;
|
||||||
|
left.y /= right;
|
||||||
|
left.z /= right;
|
||||||
|
left.w /= right;
|
||||||
|
|
||||||
|
return left;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
inline bool operator ==(const Vector4<T>& left, const Vector4<T>& right) {
|
||||||
|
return
|
||||||
|
(left.x == right.x) &&
|
||||||
|
(left.y == right.y) &&
|
||||||
|
(left.z == right.z) &&
|
||||||
|
(left.w == right.w);;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
template <typename T>
|
||||||
|
inline bool operator !=(const Vector4<T>& left, const Vector4<T>& right) {
|
||||||
|
return
|
||||||
|
(left.x != right.x) ||
|
||||||
|
(left.y != right.y) ||
|
||||||
|
(left.z != right.z) ||
|
||||||
|
(left.w != right.w);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define the most common types
|
||||||
|
typedef Vector4<int> Vector4i;
|
||||||
|
typedef Vector4<unsigned int> Vector4u;
|
||||||
|
typedef Vector4<float> Vector4f;
|
||||||
|
|
||||||
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
|
#endif // SFML_Vector4_HPP
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \class sf::Vector4
|
||||||
|
/// \ingroup system
|
||||||
|
///
|
||||||
|
/// sf::Vector4 is a simple class that defines a mathematical
|
||||||
|
/// vector with two coordinates (x and y). It can be used to
|
||||||
|
/// represent anything that has two dimensions: a size, a point,
|
||||||
|
/// a velocity, etc.
|
||||||
|
///
|
||||||
|
/// The template parameter T is the type of the coordinates. It
|
||||||
|
/// can be any type that supports arithmetic operations (+, -, /, *)
|
||||||
|
/// and comparisons (==, !=), for example int or float.
|
||||||
|
///
|
||||||
|
/// You generally don't have to care about the templated form (sf::Vector4<T>),
|
||||||
|
/// the most common specializations have special typedefs:
|
||||||
|
/// \li sf::Vector4<float> is sf::Vector4f
|
||||||
|
/// \li sf::Vector4<int> is sf::Vector4i
|
||||||
|
/// \li sf::Vector4<unsigned int> is sf::Vector4u
|
||||||
|
///
|
||||||
|
/// The sf::Vector4 class has a small and simple interface, its x and y members
|
||||||
|
/// can be accessed directly (there are no accessors like setX(), getX()) and it
|
||||||
|
/// contains no mathematical function like dot product, cross product, length, etc.
|
||||||
|
///
|
||||||
|
/// Usage example:
|
||||||
|
/// \code
|
||||||
|
/// sf::Vector4f v1(16.5f, 24.f);
|
||||||
|
/// v1.x = 18.2f;
|
||||||
|
/// float y = v1.y;
|
||||||
|
///
|
||||||
|
/// sf::Vector4f v2 = v1 * 5.f;
|
||||||
|
/// sf::Vector4
|
||||||
|
/// v3 = v1 + v2;
|
||||||
|
///
|
||||||
|
/// bool different = (v2 != v3);
|
||||||
|
/// \endcode
|
||||||
|
///
|
||||||
|
/// Note: for 3-dimensional vectors, see sf::Vector3.
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
@@ -40,6 +40,16 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inline sf::Vector3f SphereToCart(sf::Vector2f i) {
|
||||||
|
|
||||||
|
auto r = sf::Vector3f(
|
||||||
|
(1 * sin(i.y) * cos(i.x)),
|
||||||
|
(1 * sin(i.y) * sin(i.x)),
|
||||||
|
(1 * cos(i.y))
|
||||||
|
);
|
||||||
|
return r;
|
||||||
|
};
|
||||||
|
|
||||||
inline sf::Vector3f SphereToCart(sf::Vector3f i) {
|
inline sf::Vector3f SphereToCart(sf::Vector3f i) {
|
||||||
|
|
||||||
auto r = sf::Vector3f(
|
auto r = sf::Vector3f(
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ __kernel void min_kern(
|
|||||||
global int3* map_dim,
|
global int3* map_dim,
|
||||||
global int2* resolution,
|
global int2* resolution,
|
||||||
global float3* projection_matrix,
|
global float3* projection_matrix,
|
||||||
global float3* cam_dir,
|
global float2* cam_dir,
|
||||||
global float3* cam_pos,
|
global float3* cam_pos,
|
||||||
global float* lights,
|
global float* lights,
|
||||||
global int* light_count,
|
global int* light_count,
|
||||||
@@ -26,18 +26,18 @@ __kernel void min_kern(
|
|||||||
){
|
){
|
||||||
|
|
||||||
size_t id = get_global_id(0);
|
size_t id = get_global_id(0);
|
||||||
int2 pixel = {id % resolution->x, id / resolution->x};
|
int2 pixel = {id % (*resolution).x, id / (*resolution).x};
|
||||||
float3 ray_dir = projection_matrix[pixel.x + resolution->x * pixel.y];
|
float3 ray_dir = projection_matrix[pixel.x + (*resolution).x * pixel.y];
|
||||||
|
|
||||||
ray_dir = (float3)(
|
ray_dir = (float3)(
|
||||||
ray_dir.z * sin(cam_dir->y) + ray_dir.x * cos(cam_dir->y),
|
ray_dir.z * sin((*cam_dir).x) + ray_dir.x * cos((*cam_dir).x),
|
||||||
ray_dir.y,
|
ray_dir.y,
|
||||||
ray_dir.z * cos(cam_dir->y) - ray_dir.x * sin(cam_dir->y)
|
ray_dir.z * cos((*cam_dir).x) - ray_dir.x * sin((*cam_dir).x)
|
||||||
);
|
);
|
||||||
|
|
||||||
ray_dir = (float3)(
|
ray_dir = (float3)(
|
||||||
ray_dir.x * cos(cam_dir->z) - ray_dir.y * sin(cam_dir->z),
|
ray_dir.x * cos((*cam_dir).y) - ray_dir.y * sin((*cam_dir).y),
|
||||||
ray_dir.x * sin(cam_dir->z) + ray_dir.y * cos(cam_dir->z),
|
ray_dir.x * sin((*cam_dir).y) + ray_dir.y * cos((*cam_dir).y),
|
||||||
ray_dir.z
|
ray_dir.z
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ __kernel void min_kern(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we hit a voxel
|
// If we hit a voxel
|
||||||
int index = voxel.x + map_dim->x * (voxel.y + map_dim->z * voxel.z);
|
int index = voxel.x + (*map_dim).x * (voxel.y + (*map_dim).z * voxel.z);
|
||||||
int voxel_data = map[index];
|
int voxel_data = map[index];
|
||||||
|
|
||||||
if (voxel_data != 0) {
|
if (voxel_data != 0) {
|
||||||
|
|||||||
@@ -233,6 +233,38 @@ int CL_Wrapper::set_kernel_arg(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CL_Wrapper::create_buffer(std::string buffer_name, cl_uint size, void* data, cl_mem_flags flags) {
|
||||||
|
|
||||||
|
cl_mem buff = clCreateBuffer(
|
||||||
|
getContext(), flags,
|
||||||
|
size, data, &error
|
||||||
|
);
|
||||||
|
|
||||||
|
if (assert(error, "clCreateBuffer"))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
store_buffer(buff, buffer_name);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int CL_Wrapper::create_buffer(std::string buffer_name, cl_uint size, void* data) {
|
||||||
|
|
||||||
|
cl_mem buff = clCreateBuffer(
|
||||||
|
getContext(), CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
||||||
|
size, data, &error
|
||||||
|
);
|
||||||
|
|
||||||
|
if (assert(error, "clCreateBuffer"))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
store_buffer(buff, buffer_name);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int CL_Wrapper::store_buffer(cl_mem buffer, std::string buffer_name){
|
int CL_Wrapper::store_buffer(cl_mem buffer, std::string buffer_name){
|
||||||
buffer_map.emplace(std::make_pair(buffer_name, buffer));
|
buffer_map.emplace(std::make_pair(buffer_name, buffer));
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
67
src/Camera.cpp
Normal file
67
src/Camera.cpp
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
#include "Camera.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Camera::Camera() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Camera::Camera(sf::Vector3f position, sf::Vector2f direction) :
|
||||||
|
position(position), direction(direction)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Camera::~Camera() {
|
||||||
|
}
|
||||||
|
|
||||||
|
int Camera::set_position(sf::Vector3f position) {
|
||||||
|
this->position = position;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Camera::add_static_impulse(sf::Vector3f impulse) {
|
||||||
|
movement += impulse;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Camera::add_relative_impulse(DIRECTION impulse_direction) {
|
||||||
|
|
||||||
|
SphereToCart(direction);
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Camera::slew_camera(sf::Vector2f input) {
|
||||||
|
direction -= input;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Camera::update() {
|
||||||
|
|
||||||
|
position += movement;
|
||||||
|
|
||||||
|
movement *= friction_coefficient;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* Camera::get_direction_pointer() {
|
||||||
|
return &direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
void* Camera::get_position_pointer() {
|
||||||
|
return &position;
|
||||||
|
}
|
||||||
|
|
||||||
|
sf::Vector3f Camera::get_movement() {
|
||||||
|
return movement;
|
||||||
|
}
|
||||||
|
|
||||||
|
sf::Vector3f Camera::get_position() {
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
sf::Vector2f Camera::get_direction() {
|
||||||
|
return direction;
|
||||||
|
}
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by Mitchell Hansen on 8/7/16.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "Vector3.h"
|
|
||||||
168
src/main.cpp
168
src/main.cpp
@@ -31,9 +31,12 @@
|
|||||||
#include "util.hpp"
|
#include "util.hpp"
|
||||||
#include "RayCaster.h"
|
#include "RayCaster.h"
|
||||||
#include "CL_Wrapper.h"
|
#include "CL_Wrapper.h"
|
||||||
|
#include "Vector4.hpp"
|
||||||
|
#include <Camera.h>
|
||||||
|
|
||||||
const int WINDOW_X = 1000;
|
const int WINDOW_X = 1000;
|
||||||
const int WINDOW_Y = 1000;
|
const int WINDOW_Y = 1000;
|
||||||
|
const int WORK_SIZE = WINDOW_X * WINDOW_Y;
|
||||||
|
|
||||||
const int MAP_X = 1024;
|
const int MAP_X = 1024;
|
||||||
const int MAP_Y = 1024;
|
const int MAP_Y = 1024;
|
||||||
@@ -65,9 +68,7 @@ int main() {
|
|||||||
sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "SFML");
|
sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "SFML");
|
||||||
|
|
||||||
|
|
||||||
sf::Sprite s;
|
// Setup CL, instantiate and pass in values to the kernel
|
||||||
sf::Texture t;
|
|
||||||
|
|
||||||
CL_Wrapper c;
|
CL_Wrapper c;
|
||||||
query_platform_devices();
|
query_platform_devices();
|
||||||
c.acquire_platform_and_device();
|
c.acquire_platform_and_device();
|
||||||
@@ -82,35 +83,21 @@ int main() {
|
|||||||
std::cout << "map...";
|
std::cout << "map...";
|
||||||
sf::Vector3i map_dim(MAP_X, MAP_Y, MAP_Z);
|
sf::Vector3i map_dim(MAP_X, MAP_Y, MAP_Z);
|
||||||
Map* map = new Map(map_dim);
|
Map* map = new Map(map_dim);
|
||||||
std::cout << "done...";
|
|
||||||
|
|
||||||
map->setVoxel(sf::Vector3i(77, 50, 85), 5);
|
c.create_buffer("map_buffer", sizeof(char) * map_dim.x * map_dim.y * map_dim.z, map->list);
|
||||||
|
c.create_buffer("dim_buffer", sizeof(int) * 3, &map_dim);
|
||||||
|
|
||||||
cl_mem map_buff = clCreateBuffer(
|
sf::Vector2i view_res(WINDOW_X, WINDOW_Y);
|
||||||
c.getContext(), CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
c.create_buffer("res_buffer", sizeof(int) * 2, &view_res);
|
||||||
sizeof(char) * map_dim.x * map_dim.y * map_dim.z, map->list, NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
cl_mem dim_buff = clCreateBuffer(
|
|
||||||
c.getContext(), CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
||||||
sizeof(int) * 3, &map_dim, NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
sf::Vector2i view_res(WINDOW_X, WINDOW_Y);
|
|
||||||
|
|
||||||
cl_mem res_buff = clCreateBuffer(
|
|
||||||
c.getContext(), CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
||||||
sizeof(int) * 2, &view_res, NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
double y_increment_radians = DegreesToRadians(50.0 / view_res.y);
|
double y_increment_radians = DegreesToRadians(50.0 / view_res.y);
|
||||||
double x_increment_radians = DegreesToRadians(80.0 / view_res.x);
|
double x_increment_radians = DegreesToRadians(80.0 / view_res.x);
|
||||||
|
|
||||||
// SFML 2.4 has Vector4 datatypes.......
|
|
||||||
|
|
||||||
std::cout << "view matrix...";
|
std::cout << "view matrix...";
|
||||||
float* view_matrix = new float[WINDOW_X * WINDOW_Y * 4];
|
|
||||||
|
sf::Vector4f* view_matrix = new sf::Vector4f[WINDOW_X * WINDOW_Y * 4];
|
||||||
|
|
||||||
for (int y = -view_res.y / 2; y < view_res.y / 2; y++) {
|
for (int y = -view_res.y / 2; y < view_res.y / 2; y++) {
|
||||||
for (int x = -view_res.x / 2; x < view_res.x / 2; x++) {
|
for (int x = -view_res.x / 2; x < view_res.x / 2; x++) {
|
||||||
|
|
||||||
@@ -133,51 +120,34 @@ int main() {
|
|||||||
|
|
||||||
int index = (x + view_res.x / 2) + view_res.x * (y + view_res.y / 2);
|
int index = (x + view_res.x / 2) + view_res.x * (y + view_res.y / 2);
|
||||||
ray = Normalize(ray);
|
ray = Normalize(ray);
|
||||||
view_matrix[index * 4 + 0] = ray.x;
|
|
||||||
view_matrix[index * 4 + 1] = ray.y;
|
view_matrix[index] = sf::Vector4f(
|
||||||
view_matrix[index * 4 + 2] = ray.z;
|
ray.x,
|
||||||
view_matrix[index * 4 + 3] = 0;
|
ray.y,
|
||||||
|
ray.z,
|
||||||
|
0
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << "done\n";
|
|
||||||
int ind = 367;
|
|
||||||
printf("%i === %f, %f, %f\n", ind, view_matrix[ind * 4 + 0], view_matrix[ind * 4 + 1], view_matrix[ind * 4 + 2]);
|
|
||||||
|
|
||||||
cl_mem view_matrix_buff = clCreateBuffer(
|
c.create_buffer("view_matrix_buffer", sizeof(float) * 4 * view_res.x * view_res.y, view_matrix);
|
||||||
c.getContext(), CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
||||||
sizeof(float) * 3 * view_res.x * view_res.y, view_matrix, NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
sf::Vector3f cam_dir(1.0f, 0.0f, 1.00f);
|
Camera camera(
|
||||||
|
sf::Vector3f(55, 50, 50),
|
||||||
|
sf::Vector2f(0.0f, 1.00f)
|
||||||
|
);
|
||||||
|
|
||||||
cl_mem cam_dir_buff = clCreateBuffer(
|
c.create_buffer("cam_dir_buffer", sizeof(float) * 4, camera.get_direction_pointer(), CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR);
|
||||||
c.getContext(), CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
|
c.create_buffer("cam_pos_buffer", sizeof(float) * 4, camera.get_position_pointer(), CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR);
|
||||||
sizeof(float) * 4, &cam_dir, NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
sf::Vector3f cam_pos(55, 50, 50);
|
|
||||||
|
|
||||||
cl_mem cam_pos_buff = clCreateBuffer(
|
|
||||||
c.getContext(), CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,
|
|
||||||
sizeof(float) * 4, &cam_pos, NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
// {r, g, b, i, x, y, z, x', y', z'}
|
// {r, g, b, i, x, y, z, x', y', z'}
|
||||||
float light[] = { 0.4, 0.8, 0.1, 1, 50, 50, 50, 1.1, 0.4, 0.7};
|
float light[] = { 0.4, 0.8, 0.1, 1, 50, 50, 50, 1.1, 0.4, 0.7};
|
||||||
|
c.create_buffer("light_buffer", sizeof(float) * 10, light);
|
||||||
cl_mem light_buff = clCreateBuffer(
|
|
||||||
c.getContext(), CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
||||||
sizeof(float) * 10, light, NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
int light_count = 1;
|
int light_count = 1;
|
||||||
|
c.create_buffer("light_count_buffer", sizeof(int), &light_count);
|
||||||
|
|
||||||
cl_mem light_cnt_buff = clCreateBuffer(
|
// The drawing canvas
|
||||||
c.getContext(), CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,
|
|
||||||
sizeof(int), &light_count, NULL
|
|
||||||
);
|
|
||||||
|
|
||||||
unsigned char* pixel_array = new sf::Uint8[WINDOW_X * WINDOW_Y * 4];
|
unsigned char* pixel_array = new sf::Uint8[WINDOW_X * WINDOW_Y * 4];
|
||||||
|
|
||||||
for (int i = 0; i < WINDOW_X * WINDOW_Y * 4; i += 4) {
|
for (int i = 0; i < WINDOW_X * WINDOW_Y * 4; i += 4) {
|
||||||
@@ -188,12 +158,11 @@ int main() {
|
|||||||
pixel_array[i + 3] = 100; // A?
|
pixel_array[i + 3] = 100; // A?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sf::Texture t;
|
||||||
t.create(WINDOW_X, WINDOW_Y);
|
t.create(WINDOW_X, WINDOW_Y);
|
||||||
t.update(pixel_array);
|
t.update(pixel_array);
|
||||||
|
|
||||||
|
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
cl_mem image_buff = clCreateFromGLTexture(
|
cl_mem image_buff = clCreateFromGLTexture(
|
||||||
c.getContext(), CL_MEM_WRITE_ONLY, GL_TEXTURE_2D,
|
c.getContext(), CL_MEM_WRITE_ONLY, GL_TEXTURE_2D,
|
||||||
0, t.getNativeHandle(), &error);
|
0, t.getNativeHandle(), &error);
|
||||||
@@ -201,14 +170,6 @@ int main() {
|
|||||||
if (c.assert(error, "clCreateFromGLTexture"))
|
if (c.assert(error, "clCreateFromGLTexture"))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
c.store_buffer(map_buff, "map_buffer");
|
|
||||||
c.store_buffer(dim_buff, "dim_buffer");
|
|
||||||
c.store_buffer(res_buff, "res_buffer");
|
|
||||||
c.store_buffer(view_matrix_buff, "view_matrix_buffer");
|
|
||||||
c.store_buffer(cam_dir_buff, "cam_dir_buffer");
|
|
||||||
c.store_buffer(cam_pos_buff, "cam_pos_buffer");
|
|
||||||
c.store_buffer(light_buff, "light_buffer");
|
|
||||||
c.store_buffer(light_cnt_buff, "light_count_buffer");
|
|
||||||
c.store_buffer(image_buff, "image_buffer");
|
c.store_buffer(image_buff, "image_buffer");
|
||||||
|
|
||||||
c.set_kernel_arg("min_kern", 0, "map_buffer");
|
c.set_kernel_arg("min_kern", 0, "map_buffer");
|
||||||
@@ -221,9 +182,9 @@ int main() {
|
|||||||
c.set_kernel_arg("min_kern", 7, "light_count_buffer");
|
c.set_kernel_arg("min_kern", 7, "light_count_buffer");
|
||||||
c.set_kernel_arg("min_kern", 8, "image_buffer");
|
c.set_kernel_arg("min_kern", 8, "image_buffer");
|
||||||
|
|
||||||
const int size = WINDOW_X * WINDOW_Y;
|
sf::Sprite s;
|
||||||
|
s.setTexture(t);
|
||||||
s.setTexture(t);
|
s.setPosition(0, 0);
|
||||||
|
|
||||||
// The step size in milliseconds between calls to Update()
|
// The step size in milliseconds between calls to Update()
|
||||||
// Lets set it to 16.6 milliseonds (60FPS)
|
// Lets set it to 16.6 milliseonds (60FPS)
|
||||||
@@ -258,6 +219,8 @@ int main() {
|
|||||||
sf::Vector2i fixed(window.getSize());
|
sf::Vector2i fixed(window.getSize());
|
||||||
bool mouse_enabled = true;
|
bool mouse_enabled = true;
|
||||||
|
|
||||||
|
sf::Vector3f cam_mov_vec;
|
||||||
|
|
||||||
while (window.isOpen()) {
|
while (window.isOpen()) {
|
||||||
|
|
||||||
// Poll for events from the user
|
// Poll for events from the user
|
||||||
@@ -299,18 +262,8 @@ int main() {
|
|||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
|
||||||
cam_vec.x = -1;
|
cam_vec.x = -1;
|
||||||
}
|
}
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
|
|
||||||
cam_dir.z = -0.1f;
|
camera.add_static_impulse(cam_vec);
|
||||||
}
|
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
|
|
||||||
cam_vec.z = +0.1f;
|
|
||||||
}
|
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
|
|
||||||
cam_vec.y = +0.1f;
|
|
||||||
}
|
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
|
|
||||||
cam_vec.y = -0.1f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mouse_enabled) {
|
if (mouse_enabled) {
|
||||||
deltas = fixed - sf::Mouse::getPosition();
|
deltas = fixed - sf::Mouse::getPosition();
|
||||||
@@ -318,16 +271,12 @@ int main() {
|
|||||||
|
|
||||||
// Mouse movement
|
// Mouse movement
|
||||||
sf::Mouse::setPosition(fixed);
|
sf::Mouse::setPosition(fixed);
|
||||||
cam_dir.y -= deltas.y / 300.0f;
|
camera.slew_camera(sf::Vector2f(
|
||||||
cam_dir.z -= deltas.x / 300.0f;
|
deltas.y / 300.0f,
|
||||||
|
deltas.x / 300.0f
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cam_pos.x += cam_vec.x / 1.0;
|
|
||||||
cam_pos.y += cam_vec.y / 1.0;
|
|
||||||
cam_pos.z += cam_vec.z / 1.0;
|
|
||||||
|
|
||||||
std::cout << cam_vec.x << " : " << cam_vec.y << " : " << cam_vec.z << std::endl;
|
|
||||||
|
|
||||||
|
|
||||||
// Time keeping
|
// Time keeping
|
||||||
elapsed_time = elap_time();
|
elapsed_time = elap_time();
|
||||||
@@ -339,32 +288,20 @@ int main() {
|
|||||||
while ((accumulator_time - step_size) >= step_size) {
|
while ((accumulator_time - step_size) >= step_size) {
|
||||||
accumulator_time -= step_size;
|
accumulator_time -= step_size;
|
||||||
|
|
||||||
// Update cycle
|
|
||||||
|
// ==== DELTA TIME LOCKED ====
|
||||||
|
camera.update();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fps cycle
|
// ==== FPS LOCKED ====
|
||||||
// map->moveLight(sf::Vector2f(0.3, 0));
|
|
||||||
|
|
||||||
window.clear(sf::Color::Black);
|
|
||||||
|
|
||||||
// Cast the rays and get the image
|
|
||||||
//sf::Color* pixel_colors = ray_caster.CastRays(cam_dir, cam_pos);
|
|
||||||
|
|
||||||
// Cast it to an array of Uint8's
|
|
||||||
//auto out = (sf::Uint8*)pixel_colors;
|
|
||||||
|
|
||||||
//window_texture.update(out);
|
|
||||||
//window_sprite.setTexture(window_texture);
|
|
||||||
//window.draw(window_sprite);
|
|
||||||
|
|
||||||
// Give the frame counter the frame time and draw the average frame time
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Run the raycast
|
||||||
error = clEnqueueAcquireGLObjects(c.getCommandQueue(), 1, &image_buff, 0, 0, 0);
|
error = clEnqueueAcquireGLObjects(c.getCommandQueue(), 1, &image_buff, 0, 0, 0);
|
||||||
if (c.assert(error, "clEnqueueAcquireGLObjects"))
|
if (c.assert(error, "clEnqueueAcquireGLObjects"))
|
||||||
return -1;
|
return -1;
|
||||||
c.run_kernel("min_kern", size);
|
|
||||||
|
c.run_kernel("min_kern", WORK_SIZE);
|
||||||
|
|
||||||
clFinish(c.getCommandQueue());
|
clFinish(c.getCommandQueue());
|
||||||
|
|
||||||
@@ -372,14 +309,19 @@ int main() {
|
|||||||
if (c.assert(error, "clEnqueueReleaseGLObjects"))
|
if (c.assert(error, "clEnqueueReleaseGLObjects"))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
s.setPosition(0, 0);
|
|
||||||
|
// ==== RENDER ====
|
||||||
|
|
||||||
|
window.clear(sf::Color::Black);
|
||||||
|
|
||||||
window.draw(s);
|
window.draw(s);
|
||||||
|
|
||||||
|
// Give the frame counter the frame time and draw the average frame time
|
||||||
fps.frame(delta_time);
|
fps.frame(delta_time);
|
||||||
fps.draw(&window);
|
fps.draw(&window);
|
||||||
|
|
||||||
window.display();
|
window.display();
|
||||||
|
|
||||||
//std::cin.get();
|
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user