Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
angeluriot committed May 12, 2021
0 parents commit 94fd480
Show file tree
Hide file tree
Showing 774 changed files with 179,386 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
libs/* linguist-vendored
222 changes: 222 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
#Version of cmake
cmake_minimum_required(VERSION 2.8)

#Name of the project
project(Minecraft_clone)

#Tells where are the destination directories
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

#C++11 in Debug mode
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_CXX_STANDARD 17)

#Some options
#TODO add another option if a new library is to be added (follow this)

#Windows / MINGW (Code::Blocks)
if(MINGW)
MESSAGE(STATUS "Compiling for MINGW")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
SET(GLEW_INCLUDE_PATH ${CMAKE_SOURCE_DIR}/libs/include CACHE PATH "Path to GLEW include location")
SET(SDL2_INCLUDE_PATH ${CMAKE_SOURCE_DIR}/libs/include CACHE PATH "Path to SDL2 library location")
SET(SDL2_LIBRARY_PATH ${CMAKE_SOURCE_DIR}/libs/mingw/x64/bin CACHE PATH "Path to SDL2 include location")
SET(SDL2_IMAGE_LIBRARY_PATH ${CMAKE_SOURCE_DIR}/libs/mingw/x64/bin CACHE PATH "Path to SDL2 IMAGE include location")
SET(SDL2_IMAGE_INCLUDE_PATH ${CMAKE_SOURCE_DIR}/libs/include CACHE PATH "Path to SDL2 IMAGE library location")
SET(GLEW_LIBRARY_PATH ${CMAKE_SOURCE_DIR}/libs/mingw/x64/bin CACHE PATH "Path to GLEW library location")

elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
SET(GLEW_INCLUDE_PATH ${CMAKE_SOURCE_DIR}/libs/include CACHE PATH "Path to GLEW include location")
SET(SDL2_INCLUDE_PATH ${CMAKE_SOURCE_DIR}/libs/include CACHE PATH "Path to SDL2 library location")
SET(SDL2_LIBRARY_PATH ${CMAKE_SOURCE_DIR}/libs/mingw/x86/bin CACHE PATH "Path to SDL2 include location")
SET(SDL2_IMAGE_LIBRARY_PATH ${CMAKE_SOURCE_DIR}/libs/mingw/x86/bin CACHE PATH "Path to SDL2 IMAGE include location")
SET(SDL2_IMAGE_INCLUDE_PATH ${CMAKE_SOURCE_DIR}/libs/include CACHE PATH "Path to SDL2 IMAGE library location")
SET(GLEW_LIBRARY_PATH ${CMAKE_SOURCE_DIR}/libs/mingw/x86/bin CACHE PATH "Path to GLEW library location")
endif()

#Windows / MSVC (Visual Studio)
elseif(MSVC)
MESSAGE(STATUS "Compiling for MSVC")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
SET(SDL2_LIBRARY_PATH ${CMAKE_SOURCE_DIR}/libs/VS/x64 CACHE PATH "Path to SDL2 include location")
SET(GLEW_LIBRARY_PATH ${CMAKE_SOURCE_DIR}/libs/VS/x64 CACHE PATH "Path to GLEW library location")
SET(SDL2_IMAGE_LIBRARY_PATH ${CMAKE_SOURCE_DIR}/libs/VS/x64 CACHE PATH "Path to SDL2 IMAGE include location")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
SET(SDL2_LIBRARY_PATH ${CMAKE_SOURCE_DIR}/libs/VS/x86 CACHE PATH "Path to SDL2 include location")
SET(GLEW_LIBRARY_PATH ${CMAKE_SOURCE_DIR}/libs/VS/x86 CACHE PATH "Path to GLEW library location")
SET(SDL2_IMAGE_LIBRARY_PATH ${CMAKE_SOURCE_DIR}/libs/VS/x86 CACHE PATH "Path to SDL2 IMAGE include location")
endif()

#Linux
else()
MESSAGE(STATUS "Compiling for Linux/Unix")
SET(GLEW_INCLUDE_PATH /usr/include CACHE PATH "Path to GLEW include location")
SET(SDL2_INCLUDE_PATH /usr/include CACHE PATH "Path to SDL2 library location")
SET(SDL2_LIBRARY_PATH /usr/lib CACHE PATH "Path to SDL2 include location")
SET(GLEW_LIBRARY_PATH /usr/lib CACHE PATH "Path to GLEW library location")
SET(GL_LIBRARY_PATH /usr/lib CACHE PATH "Path to GL library location")
SET(GL_INCLUDE_PATH /usr/include CACHE PATH "Path to GL include location")
SET(SDL2_IMAGE_LIBRARY_PATH /usr/lib CACHE PATH "Path to SDL2 IMAGE library location")
SET(SDL2_IMAGE_INCLUDE_PATH /usr/include/ CACHE PATH "Path to SDL2 IMAGE include location")


if((NOT EXISTS "${GL_LIBRARY_PATH}/libGL.so" ) AND (NOT EXISTS "${GL_LIBRARY_PATH}/GL.dll" ))
MESSAGE(FATAL_ERROR "Could not find libGL in ${GL_LIBRARY_PATH}")
endif()
endif()

#Workaround for MSVC not creating DEBUG and RELEASE folder
foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/bin)
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/lib)
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${CMAKE_BINARY_DIR}/lib)
endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES )

if(MSVC)
set(WARNING_FLAGS "${WARNING_FLAGS} /W4")
else()
set(WARNING_FLAGS "${WARNING_FLAGS} -Wall")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS}")

include_directories(SYSTEM include)

if(MSVC OR MINGW)
include_directories(SYSTEM ${CMAKE_SOURCE_DIR}/libs/include)
endif()

#Check paths
if((NOT EXISTS "${SDL2_LIBRARY_PATH}/libSDL2.so" ) AND (NOT EXISTS "${SDL2_LIBRARY_PATH}/SDL2.dll" ))
MESSAGE(FATAL_ERROR "Could not find libSDL2 in ${SDL2_LIBRARY_PATH}")
endif()

if((NOT EXISTS "${GLEW_LIBRARY_PATH}/libGLEW.so" ) AND (NOT EXISTS "${GLEW_LIBRARY_PATH}/glew32.dll" ))
MESSAGE(FATAL_ERROR "Could not find libGLEW in ${GLEW_LIBRARY_PATH}")
endif()

if((NOT EXISTS "${SDL2_IMAGE_LIBRARY_PATH}/libSDL2_image.so" ) AND (NOT EXISTS "${SDL2_IMAGE_LIBRARY_PATH}/SDL2_image.dll" ))
MESSAGE(FATAL_ERROR "Could not find libSDL2_Image in ${SDL2_IMAGE_LIBRARY_PATH}")
endif()

make_directory("bin")

#Configure Minecraft_clone
file(GLOB_RECURSE SOURCES sources/*.cpp sources/*.c)
file(GLOB_RECURSE HEADERS include/*.h include/*.hpp)

#TODO add the library path here
link_directories(${SDL2_LIBRARY_PATH} ${GLEW_LIBRARY_PATH} ${SDL2_IMAGE_LIBRARY_PATH})
add_executable(Minecraft_clone ${SOURCES} ${HEADERS})
target_compile_definitions(Minecraft_clone PUBLIC _USE_MATH_DEFINES)

#TODO add another -I parameter (include directory to take account to) and a -l parameter (libraries to link to)
#Normally you have just to modify the target_compile_options

target_include_directories(Minecraft_clone PUBLIC
${SDL2_INCLUDE_PATH}
${SDL2_IMAGE_INCLUDE_PATH}
${GLEW_INCLUDE_PATH}
${GL_INCLUDE_PATH})

if(MINGW)
target_link_libraries(Minecraft_clone PUBLIC
-lOpenGL32
-lglew32
-lSDL2
-lSDL2_image)

#Scripts to copy to bin/
file(GLOB BINRESOURCES ${CMAKE_SOURCE_DIR}/libs/VS/x86/*.dll ${CMAKE_SOURCE_DIR}/libs/VS/x86/*.lib)

foreach(sourcefile ${BINRESOURCES})
get_filename_component(dirname "${sourcefile}" DIRECTORY)
get_filename_component(filename "${sourcefile}" NAME)
file(RELATIVE_PATH relpath "${CMAKE_CURRENT_SOURCE_DIR}" "${sourcefile}")

set(BinOutput ${BinOutput} "${relpath}")

add_custom_command(
OUTPUT "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${filename}"
DEPENDS ${relpath}
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/${relpath}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${filename}"
COMMENT "Generating ${filename}"
VERBATIM
)
endforeach(sourcefile)

add_custom_target(BinTarget DEPENDS ${BinOutput})
add_dependencies(Minecraft_clone BinTarget)

elseif(MSVC)
target_link_libraries(Minecraft_clone general
"OpenGL32.lib"
"glew32.lib"
"SDL2.lib"
"SDL2main.lib"
"SDL2_image.lib")

#Scripts to copy to bin/
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
file(GLOB BINRESOURCES ${CMAKE_SOURCE_DIR}/libs/VS/x64/*.dll ${CMAKE_SOURCE_DIR}/libs/VS/x64/*.lib)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
file(GLOB BINRESOURCES ${CMAKE_SOURCE_DIR}/libs/VS/x86/*.dll ${CMAKE_SOURCE_DIR}/libs/VS/x86/*.lib)
endif()

foreach(sourcefile ${BINRESOURCES})
get_filename_component(dirname "${sourcefile}" DIRECTORY)
get_filename_component(filename "${sourcefile}" NAME)
file(RELATIVE_PATH relpath "${CMAKE_CURRENT_SOURCE_DIR}" "${sourcefile}")

set(BinOutput ${BinOutput} "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${filename}")

add_custom_command(
OUTPUT "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${filename}"
DEPENDS ${relpath}
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/${relpath}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${filename}"
COMMENT "Generating ${filename}"
VERBATIM
)
endforeach(sourcefile)

add_custom_target(BinTarget DEPENDS ${BinOutput})
add_dependencies(Minecraft_clone BinTarget)
else()
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
target_link_libraries(Minecraft_clone PUBLIC
${OPENGL_gl_LIBRARY}
${GLEW_LIBRARIES}
-lSDL2
-lSDL2_image)
endif()


#Scripts to copy to bin/
file(GLOB SHADERRESOURCES
shaders/*
textures/*)
foreach(sourcefile ${SHADERRESOURCES})
get_filename_component(dirname "${sourcefile}" DIRECTORY)
get_filename_component(filename "${sourcefile}" NAME)
file(RELATIVE_PATH relpath "${CMAKE_CURRENT_SOURCE_DIR}" "${sourcefile}")
file(RELATIVE_PATH dirrelpath "${CMAKE_CURRENT_SOURCE_DIR}" "${dirname}")

set(ShadersOutput ${ShadersOutput} "${relpath}")

add_custom_command(
OUTPUT "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${relpath}"
DEPENDS ${relpath}
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${dirrelpath}"
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/${relpath}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${dirrelpath}/${filename}"
COMMENT "Generating ${relpath}"
VERBATIM
)
endforeach(sourcefile)

add_custom_target(ShaderTarget DEPENDS ${ShadersOutput})
add_dependencies(Minecraft_clone ShaderTarget)
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Projet

![Release](https://img.shields.io/badge/Release-v1.0-blueviolet)
![Language](https://img.shields.io/badge/Language-C%2B%2B-0052cf)
![size](https://img.shields.io/badge/Size-52%20Mo-f12222)
![Open Source](https://badges.frapsoft.com/os/v2/open-source.svg?v=103)
<br/>

Ce dépôt contient le code source d'un clone simplifié de Minecraft.

<br/>

<p align="center">
<img src="https://i.imgur.com/RCGkX52.png" width="700">
</p>

<br/>

# Vidéo

Voici une vidéo présentant le programme :

[<p align="center"><img src="" width="200"></p>](https://www.youtube.com/)

<br/>


# Remarques

Ce programme est un projet scolaire pour Polytech Paris-Saclay dans le cadre d'un cours d'informatique graphique.

# Crédits

* [**Angel Uriot**](https://github.com/angeluriot) : Co-créateur du projet.
* [**Gaétan Renard**]() : Co-créateur du projet.
* [**Arthur Azambre**]() : Co-créateur du projet.
62 changes: 62 additions & 0 deletions include/Block.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#ifndef BLOCK_H
#define BLOCK_H

#include "utils.h"
#include "Mesh.h"

class Chunk;
class World;

typedef std::array<bool, Cube::nb_faces> FacesShown; // 0:Back, 1:Front, 2:Left, 3:Right, 4:Top, 5:Bottom
typedef std::array<uint8_t, Cube::nb_faces> FacesOrientation; // 0:Back, 1:Front, 2:Left, 3:Right, 4:Top, 5:Bottom

// Classe définissant un bloc

class Block
{
public:

// Enum définissant les types de blocs

enum class Type { Air, Grass, Dirt, Stone, Sand, Wood, Leaves, Snow, Weed, TallWeedBottom, TallWeebTop, Tulip, Orchid, Dandelion };

private:

Chunk* chunk; // Pointeur vers le chunk du bloc
FacesShown faces_shown; // Les faces affichées

Type type; // Type du bloc
glm::ivec3 position; // Position
FacesOrientation faces_orientation; // Orientation des faces

static constexpr float total_texture_size = 128.f; // Taille totale de la texture des blocs
static constexpr float texture_size = 16.f; // Taille de la texture d'un bloc
static constexpr float texture_ratio = texture_size / total_texture_size; // Taille de la texture d'un bloc sur la taille totale

public:

static Block air; // Bloc d'air

Block();
Block(const Block& other);
Block(Type type, const glm::ivec3& position, Chunk* chunk);

Block& operator=(const Block& other);

bool is_plant() const;
bool is_transparent(const Block& block) const;
bool is_edge() const;
void set_type(Type type, bool update_block);
void update_face(uint8_t face_id);
void update(bool update_around, uint8_t direction_id = 6);
void add_texcoords(uint8_t face_id, uint8_t x, uint8_t y, std::vector<float>& texcoords) const;
void send_texcoords(uint8_t face_id, std::vector<float>& texcoords) const;
void draw(Mesh& mesh) const;
void draw_plant(Mesh& mesh) const;

const Chunk& get_chunk() const;
Type get_type() const;
glm::ivec3 get_position() const;
};

#endif
42 changes: 42 additions & 0 deletions include/Camera.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef CAMERA_H
#define CAMERA_H

#include "utils.h"

// Classe définissant une caméra

class Camera
{
private:

glm::vec3 position; // Position de la caméra
float sensitivity; // Sensibilité de la souris
float fov; // Champ de vision
glm::mat4 view; // Matrice de vue
glm::mat4 projection; // Matrice de projection
glm::vec3 direction; // Direction de la caméra
float yaw; // Déplacement horizontal de la direction
float pitch; // Déplacement vertical de la direction

public:

static constexpr float default_fov = pi / 4.f; // Champs de vision par défaut
static constexpr float default_sensitivity = 0.2f; // Champs de vision par défaut

Camera(const Camera& other);
Camera(const glm::vec3& position = glm::vec3(0.f, 0.f, 0.f), float sensitivity = default_sensitivity, float fov = default_fov);

Camera& operator=(const Camera& other);

void look(const glm::ivec2& mouse_pos);
glm::mat4 get_matrix() const;
void set_position(const glm::vec3& position);
glm::vec3 get_position() const;
float get_yaw() const;
float get_pitch() const;
glm::vec3 get_direction() const;
void invert(float mirror_level);
void change_resolution(float width, float height);
};

#endif
Loading

0 comments on commit 94fd480

Please sign in to comment.