From bf45af9bab7db60e6df2883e5824e72ae48cd3f4 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Mon, 8 Aug 2016 15:39:36 -0700 Subject: [PATCH] Added the SFML vector class. Need to extend it to have the vector operations I want Changes to be committed: modified: CMakeLists.txt modified: README.md renamed: src/Curses.h -> include/Curses.h new file: include/Vector3.h new file: src/Vector3.cpp --- CMakeLists.txt | 6 +- README.md | 31 ++++++++- {src => include}/Curses.h | 0 include/Vector3.h | 140 ++++++++++++++++++++++++++++++++++++++ src/Vector3.cpp | 5 ++ 5 files changed, 177 insertions(+), 5 deletions(-) rename {src => include}/Curses.h (100%) create mode 100644 include/Vector3.h create mode 100644 src/Vector3.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a12dd3..0d2fa96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,11 +2,11 @@ set(PNAME Game) set(SFML_ROOT root CACHE STRING "User specified path") -set(SFML_VERSION 2.3) +set(SFML_VERSION 2.1) set(SFML_COMPONENTS graphics window system network audio) -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.0) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}) project(${PNAME}) @@ -16,7 +16,7 @@ include_directories(${SFML_INCLUDE_DIR}/include) include_directories(include) file(GLOB SOURCES "src/*.cpp") -add_executable(${PNAME} ${SOURCES}) +add_executable(${PNAME} ${SOURCES} include/Vector3.cpp include/Vector3.h) target_link_libraries(${PNAME} ${SFML_LIBRARIES} ${SFML_DEPENDENCIES}) diff --git a/README.md b/README.md index d286ef3..813a940 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,30 @@ -# Install instructions : +# SFML Template for Windows, Mac, and Linux + +### Requirements +* SFML files for your OS. Found [here](http://www.sfml-dev.org/download.php) + +* CMake + +#### Clone the Repo + +```git clone https://github.com/MitchellHansen/SFML_CMake_Template``` + +### Windows + +* Open the CMake GUI and under "Where is the source code" enter the path that you cloned the repo into. For example ```C:/Users/mrh/Desktop/SFML_CMake_Template``` + +* Under "Where to build the binaries" enter the destination you want you project to build to. Traditionally this is placed in /build. For example ```C:/Users/mrh/Desktop/SFML_CMake_Template/build``` + +* Hit the configure button and choose from the dropdown box your generator. As this is on Windows I'll assume you're using Visual Studio, select your version and the platform you want to build for. ```Visual Studio VV YYYY``` (32 bit) or ```Visual Studio VV YYYY 64``` (64 bit). Press Finish when done. + +* If at any time you want to re-enter this infomation, hit file -> delete cache and then press configure again. + +* CMake will now complain about an error in the configuration process as it can't find where you downloaded SFML to. I usually place libs in a seperate drive, so I would replace ```root``` in the ```SFML_ROOT``` row with ```Z:/cpp_libs/SFML-2.3.2-windows-vc14-32-bit``` + +* Press Generate and CMake will now generate and place all the files required by Visual Studio in your ```build``` directory + +* Open up this directory in your file explorer and open ```Game.sln``` + +* In your solution explorer set Game as the starup project and hit F5 to run the project! + -When I get the chance to write them diff --git a/src/Curses.h b/include/Curses.h similarity index 100% rename from src/Curses.h rename to include/Curses.h diff --git a/include/Vector3.h b/include/Vector3.h new file mode 100644 index 0000000..5232d2f --- /dev/null +++ b/include/Vector3.h @@ -0,0 +1,140 @@ +//////////////////////////////////////////////////////////// +// +// 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 +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 + explicit Vector3(const Vector3& vector); + + // Member data + T x; + T y; + T z; +}; + + // Vector3 + // Overload of unary operator - + // left Vector to negate + // Memberwise opposite of the vector + template + Vector3 operator -(const Vector3& 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 + Vector3& operator +=(Vector3& left, const Vector3& 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 + Vector3& operator -=(Vector3& left, const Vector3& right); + + // Overload of binary operator + + // returns Memberwise addition of both vectors + template + Vector3 operator +(const Vector3& left, const Vector3& right); + // Overload of binary operator - + // returns Memberwise subtraction of both vectors + template + Vector3 operator -(const Vector3& left, const Vector3& right); + + // Overload of binary operator * + // returns Memberwise multiplication by right + template + Vector3 operator *(const Vector3& left, T right); + + // Overload of binary operator * + // returns Memberwise multiplication by left + template + Vector3 operator *(T left, const Vector3& right); + + // Overload of binary operator *= + // This operator performs a memberwise multiplication by right, + // and assigns the result to left. + // returns Reference to left + template + Vector3& operator *=(Vector3& left, T right); + + // Overload of binary operator / + // returns Memberwise division by right + template + Vector3 operator /(const Vector3& 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 + Vector3& operator /=(Vector3& left, T right); + + // Overload of binary operator == + // This operator compares strict equality between two vectors. + // returns True if left is equal to right + template + bool operator ==(const Vector3& left, const Vector3& right); + + // Overload of binary operator != + // This operator compares strict difference between two vectors. + // returns True if left is not equal to right + template + bool operator !=(const Vector3& left, const Vector3& right); + +#include + + // Define the most common types + typedef Vector3 Vector3i; + typedef Vector3 Vector3f; + +} + +#endif + +}; + + +#endif diff --git a/src/Vector3.cpp b/src/Vector3.cpp new file mode 100644 index 0000000..056d8f1 --- /dev/null +++ b/src/Vector3.cpp @@ -0,0 +1,5 @@ +// +// Created by Mitchell Hansen on 8/7/16. +// + +#include "Vector3.h"