Skip to content
Permalink
Browse files

untabbed

  • Loading branch information...
Syntaf committed Jul 11, 2014
1 parent 9a20963 commit 8467ed493b64e33a46242f431914892a3414ab47
Showing with 735 additions and 735 deletions.
  1. +39 −39 CMakeLists.txt
  2. +26 −26 Particle.hpp
  3. +31 −31 cmake_modules/FindGLEW.cmake
  4. +48 −48 common/controls.cpp
  5. +87 −87 common/shader.cpp
  6. +187 −187 common/texture.cpp
  7. +1 −1 console.cpp
  8. +16 −16 kernels/update_particles.cl
  9. +1 −1 main.cpp
  10. +272 −272 opencl/cl_particle_updater.cpp
  11. +13 −13 opencl/cl_tools.hpp
  12. +2 −2 shaders/fragmentshader.frag
  13. +12 −12 shaders/vertexshader.vert
@@ -3,54 +3,54 @@ cmake_minimum_required(VERSION 2.8)
project(ParticleSimulator)

if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message( STATUS "Setting build type to 'Release as none was specified.")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
#set possible values of built type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release" "Debug"
"MinSizeRel" "RelWithDebInfo")
message( STATUS "Setting build type to 'Release as none was specified.")
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
#set possible values of built type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release" "Debug"
"MinSizeRel" "RelWithDebInfo")
endif()

set(EXECUTABLE_NAME "ParticleSimulator")
set(VERSION_MAJOR 0)
set(VERSION_MINOR 2)
configure_file(
"${PROJECT_SOURCE_DIR}/config.h.in"
"${PROJECT_BINARY_DIR}/config.h"
)
"${PROJECT_SOURCE_DIR}/config.h.in"
"${PROJECT_BINARY_DIR}/config.h"
)

#option to enable OpenCL experimental
option (USE_OPENCL
"Use OpenCL experimental implementation" OFF)
"Use OpenCL experimental implementation" OFF)

#include sources
set(HEADERS
common/shader.hpp
common/texture.hpp
common/controls.hpp
console.hpp
Particle.hpp
set(HEADERS
common/shader.hpp
common/texture.hpp
common/controls.hpp
console.hpp
Particle.hpp
)
if(USE_OPENCL)
set(HEADERS ${HEADERS}
opencl/cl_particle_updater.hpp
opencl/cl_tools.hpp
)
set(HEADERS ${HEADERS}
opencl/cl_particle_updater.hpp
opencl/cl_tools.hpp
)
endif()

#include headers
set(SOURCES
main.cpp
console.cpp
common/shader.cpp
common/texture.cpp
common/controls.cpp
main.cpp
console.cpp
common/shader.cpp
common/texture.cpp
common/controls.cpp
)
if(USE_OPENCL)
set(SOURCES ${SOURCES}
opencl/cl_particle_updater.cpp
opencl/cl_tools.cpp
kernels/update_particles.cl
)
set(SOURCES ${SOURCES}
opencl/cl_particle_updater.cpp
opencl/cl_tools.cpp
kernels/update_particles.cl
)
endif()

#include needed directories
@@ -60,7 +60,7 @@ include_directories("${PROJECT_SOURCE_DIR}/textures")
include_directories("${PROJECT_SOURCE_DIR}/common")

if(USE_OPENCL)
include_directories("${PROJECT_SOURCE_DIR}/kernels")
include_directories("${PROJECT_SOURCE_DIR}/kernels")
endif()

#copy shaders and textures into release folder, TEMP solution to ths issue
@@ -72,10 +72,10 @@ file(COPY shaders/vertexshader.vert shaders/fragmentshader.frag DESTINATION ${PR
file(COPY textures/particle.dds DESTINATION ${PROJECT_BINARY_DIR}/Release/textures)
file(COPY textures/particle.dds DESTINATION ${PROJECT_BINARY_DIR}/Debug/textures)
if(USE_OPENCL)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/Release/kernels ${PROJECT_BINARY_DIR}/Debug/kernels)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/Release/kernels ${PROJECT_BINARY_DIR}/Release/kernels)
file(COPY kernels/update_particles.cl DESTINATION ${PROJECT_BINARY_DIR}/Debug/kernels)
file(COPY kernels/update_particles.cl DESTINATION ${PROJECT_BINARY_DIR}/Release/kernels)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/Release/kernels ${PROJECT_BINARY_DIR}/Debug/kernels)
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/Release/kernels ${PROJECT_BINARY_DIR}/Release/kernels)
file(COPY kernels/update_particles.cl DESTINATION ${PROJECT_BINARY_DIR}/Debug/kernels)
file(COPY kernels/update_particles.cl DESTINATION ${PROJECT_BINARY_DIR}/Release/kernels)
endif()


@@ -104,11 +104,11 @@ message(STATUS "GLM included at ${GLM_INCLUDE_DIRS}")

#OpenCL experimental
if(USE_OPENCL)
find_package(OpenCL REQUIRED)
include_directories(${OPENCL_INCLUDE_DIRS})
target_link_libraries(${EXECUTABLE_NAME} ${OPENCL_LIBRARIES})
#enable OpenCL in code
add_definitions("-DUSE_OPENCL")
find_package(OpenCL REQUIRED)
include_directories(${OPENCL_INCLUDE_DIRS})
target_link_libraries(${EXECUTABLE_NAME} ${OPENCL_LIBRARIES})
#enable OpenCL in code
add_definitions("-DUSE_OPENCL")
endif()

#GLEW libraries
@@ -6,36 +6,36 @@

// CPU representation of a particle
struct Particle{
glm::vec3 pos, speed; //position, speed
std::vector<glm::vec3> force; //total force
unsigned char r,g,b,a; //color
float mass,size;
float life; //remaining life of a particle, if <0 it's super dead
float cameradistance; //squared distance to camera : -1.0f if dead
glm::vec3 pos, speed; //position, speed
std::vector<glm::vec3> force; //total force
unsigned char r,g,b,a; //color
float mass,size;
float life; //remaining life of a particle, if <0 it's super dead
float cameradistance; //squared distance to camera : -1.0f if dead

void addForce(glm::vec3 const& m_force)
{
force.push_back(m_force);
}
void addForce(glm::vec3 const& m_force)
{
force.push_back(m_force);
}

glm::vec3 getTotalForce() const
{
glm::vec3 total(0.0,0.0,0.0);
for(auto i=0; i < force.size(); i++) {
total += force[i];
}
return total;
}
glm::vec3 getTotalForce() const
{
glm::vec3 total(0.0,0.0,0.0);
for(auto i=0; i < force.size(); i++) {
total += force[i];
}
return total;
}

void clearForce()
{
force.clear();
}
void clearForce()
{
force.clear();
}

//used for std::sort, needs an overloaded comparison operator
bool operator<(const Particle& that) const {
return this->cameradistance > that.cameradistance;
}
//used for std::sort, needs an overloaded comparison operator
bool operator<(const Particle& that) const {
return this->cameradistance > that.cameradistance;
}
};

#endif
@@ -8,42 +8,42 @@
#

IF (WIN32)
FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
$ENV{GLEW_ROOT}/include
${GLEW_ROOT}/include
${PROJECT_SOURCE_DIR}/src/nvgl/glew/include
DOC "The directory where GL/glew.h resides")
FIND_LIBRARY( GLEW_LIBRARY
NAMES glew GLEW glew32 glew32s
PATHS
$ENV{GLEW_ROOT}/lib/release/x64
${GLEW_ROOT}/lib/release/x64
${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin
${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib
DOC "The GLEW library")
FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
$ENV{GLEW_ROOT}/include
${GLEW_ROOT}/include
${PROJECT_SOURCE_DIR}/src/nvgl/glew/include
DOC "The directory where GL/glew.h resides")
FIND_LIBRARY( GLEW_LIBRARY
NAMES glew GLEW glew32 glew32s
PATHS
$ENV{GLEW_ROOT}/lib/release/x64
${GLEW_ROOT}/lib/release/x64
${PROJECT_SOURCE_DIR}/src/nvgl/glew/bin
${PROJECT_SOURCE_DIR}/src/nvgl/glew/lib
DOC "The GLEW library")
ELSE (WIN32)
FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
/usr/include
/usr/local/include
/sw/include
/opt/local/include
DOC "The directory where GL/glew.h resides")
FIND_LIBRARY( GLEW_LIBRARY
NAMES GLEW glew
PATHS
/usr/lib64
/usr/lib
/usr/local/lib64
/usr/local/lib
/sw/lib
/opt/local/lib
DOC "The GLEW library")
FIND_PATH( GLEW_INCLUDE_PATH GL/glew.h
/usr/include
/usr/local/include
/sw/include
/opt/local/include
DOC "The directory where GL/glew.h resides")
FIND_LIBRARY( GLEW_LIBRARY
NAMES GLEW glew
PATHS
/usr/lib64
/usr/lib
/usr/local/lib64
/usr/local/lib
/sw/lib
/opt/local/lib
DOC "The GLEW library")
ENDIF (WIN32)

IF (GLEW_INCLUDE_PATH)
SET( GLEW_FOUND 1 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise")
SET( GLEW_FOUND 1 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise")
ELSE (GLEW_INCLUDE_PATH)
SET( GLEW_FOUND 0 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise")
SET( GLEW_FOUND 0 CACHE STRING "Set to 1 if GLEW is found, 0 otherwise")
ENDIF (GLEW_INCLUDE_PATH)

MARK_AS_ADVANCED( GLEW_FOUND )
@@ -10,17 +10,17 @@

using namespace glm;

const float speed = 14.0f; // speed of camera moving around
const float lookSpeed = 0.005f; // mouse speed
const float speed = 14.0f; // speed of camera moving around
const float lookSpeed = 0.005f; // mouse speed

glm::mat4 ViewMatrix;
glm::mat4 ProjectionMatrix = glm::perspective(45.0f, 4.0f/3.0f, 0.1f, 100.0f);
glm::mat4 ModelMatrix = glm::mat4(1.0f);
glm::vec3 position = glm::vec3( 0, 0, 5 ); // Initial position : on +Z
float horizontalAngle = 3.14f; // Initial horizontal angle : toward -Z
float verticalAngle = 0.0f; // Initial vertical angle : none
glm::vec3 direction(0.0); // camera direction vector
glm::vec3 right(0.0); // right vector used for lookat()
float horizontalAngle = 3.14f; // Initial horizontal angle : toward -Z
float verticalAngle = 0.0f; // Initial vertical angle : none
glm::vec3 direction(0.0); // camera direction vector
glm::vec3 right(0.0); // right vector used for lookat()


//get matricies
@@ -30,49 +30,49 @@ glm::mat4 getProjectionMatrix(){return ProjectionMatrix;}

void computeMatricesFromInputs(sf::Window& window, float time){

// Looking around, think of just a head pivoting
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){
horizontalAngle += lookSpeed * speed;
}else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)){
horizontalAngle += lookSpeed * speed * -1;
}else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)){
verticalAngle += lookSpeed * speed;
}else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)){
verticalAngle += lookSpeed * speed * -1;
}
// Looking around, think of just a head pivoting
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){
horizontalAngle += lookSpeed * speed;
}else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)){
horizontalAngle += lookSpeed * speed * -1;
}else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)){
verticalAngle += lookSpeed * speed;
}else if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)){
verticalAngle += lookSpeed * speed * -1;
}

// Direction : Spherical coordinates to Cartesian coordinates conversion
direction = glm::vec3(
cos(verticalAngle) * sin(horizontalAngle),
sin(verticalAngle),
cos(verticalAngle) * cos(horizontalAngle)
);
// Right vector
right = glm::vec3(
sin(horizontalAngle - 3.14f/2.0f),
0,
cos(horizontalAngle - 3.14f/2.0f)
);
// Direction : Spherical coordinates to Cartesian coordinates conversion
direction = glm::vec3(
cos(verticalAngle) * sin(horizontalAngle),
sin(verticalAngle),
cos(verticalAngle) * cos(horizontalAngle)
);
// Right vector
right = glm::vec3(
sin(horizontalAngle - 3.14f/2.0f),
0,
cos(horizontalAngle - 3.14f/2.0f)
);

// Up vector
glm::vec3 up = glm::cross( right, direction );
// Camera matrix
ViewMatrix = glm::lookAt(
position, //camera position
position+direction, //look at origin
up //head up
);
// Up vector
glm::vec3 up = glm::cross( right, direction );
// Camera matrix
ViewMatrix = glm::lookAt(
position, //camera position
position+direction, //look at origin
up //head up
);

// moving around, think of a person walking left/right/forward/backward
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)){
position += direction * time * speed;
}else if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)){
position -= direction * time * speed;
}else if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)){
position += right * time * speed;
}else if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)){
position -= right * time * speed;
}
// moving around, think of a person walking left/right/forward/backward
if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)){
position += direction * time * speed;
}else if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)){
position -= direction * time * speed;
}else if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)){
position += right * time * speed;
}else if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)){
position -= right * time * speed;
}
}
Oops, something went wrong.

0 comments on commit 8467ed4

Please sign in to comment.
You can’t perform that action at this time.