[Add] Added MathBox and Finished Vector shit! I'm on FIRE!!!!
This commit is contained in:
parent
b94cfb69fa
commit
75b71a8f8c
@ -1,6 +1,6 @@
|
|||||||
#############################################################################
|
#############################################################################
|
||||||
# Makefile for building: Unuk-QT
|
# Makefile for building: Unuk-QT
|
||||||
# Generated by qmake (2.01a) (Qt 4.7.4) on: Wed Feb 1 18:06:22 2012
|
# Generated by qmake (2.01a) (Qt 4.7.4) on: Wed Feb 1 19:11:29 2012
|
||||||
# Project: Unuk-QT.pro
|
# Project: Unuk-QT.pro
|
||||||
# Template: app
|
# Template: app
|
||||||
# Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug -o Makefile Unuk-QT.pro
|
# Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug -o Makefile Unuk-QT.pro
|
||||||
@ -208,7 +208,7 @@ qmake: FORCE
|
|||||||
|
|
||||||
dist:
|
dist:
|
||||||
@$(CHK_DIR_EXISTS) .tmp/Unuk-QT1.0.0 || $(MKDIR) .tmp/Unuk-QT1.0.0
|
@$(CHK_DIR_EXISTS) .tmp/Unuk-QT1.0.0 || $(MKDIR) .tmp/Unuk-QT1.0.0
|
||||||
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/Libs/wglext.h ../src/Libs/glxext.h ../src/libUnuk/Engine/WorldManager.h ../src/libUnuk/Engine/ParticleEmitter.h ../src/libUnuk/Engine/NPC.h ../src/libUnuk/Engine/MemManager.h ../src/libUnuk/Engine/MemClass.h ../src/libUnuk/Engine/Collision.h ../src/libUnuk/Engine/Character.h ../src/libUnuk/Engine/AStarBase.h ../src/libUnuk/Engine/AStar.h ../src/libUnuk/Sprite/TextureManager.h ../src/libUnuk/Sprite/Texture.h ../src/libUnuk/Sprite/ImageLoader.h ../src/libUnuk/Sprite/ApplySurface.h ../src/libUnuk/System/Rect.h ../src/libUnuk/System/Input.h ../src/libUnuk/System/FPS.h ../src/libUnuk/System/Debug.h ../src/libUnuk/System/Timer.h ../src/libUnuk/UI/MainMenu.h ../src/libUnuk/UI/IngameMenu.h ../src/libUnuk/UI/Font.h ../src/libUnuk/UI/ButtonToggle.h ../src/libUnuk/UI/ButtonGroup.h ../src/libUnuk/UI/Button.h ../src/libUnuk/UI/Text.h ../src/Unuk/Globals.h ../src/Unuk/Game.h ../src/Unuk/Constants.h ../src/Unuk/Player.h ../src/libUnuk/LevelGen/LevelGen.h ../src/libUnuk/LevelGen/MapEntities.h ../src/libUnuk/LevelGen/MapElement.h ../src/libUnuk/LevelGen/MapTile.h ../src/libUnuk/UI/EventHistory.h ../src/libUnuk/UI/Bar.h ../src/libUnuk/System/Vec2.h .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Engine/WorldManager.cpp ../src/libUnuk/Engine/ParticleEmitter.cpp ../src/libUnuk/Engine/NPC.cpp ../src/libUnuk/Engine/MemManager.cpp ../src/libUnuk/Engine/Collision.cpp ../src/libUnuk/Engine/Character.cpp ../src/libUnuk/Engine/AStar.cpp ../src/libUnuk/Sprite/TextureManager.cpp ../src/libUnuk/Sprite/Texture.cpp ../src/libUnuk/Sprite/ImageLoader.cpp ../src/libUnuk/Sprite/ApplySurface.cpp ../src/libUnuk/System/Timer.cpp ../src/libUnuk/System/Rect.cpp ../src/libUnuk/System/Input.cpp ../src/libUnuk/System/FPS.cpp ../src/libUnuk/System/Debug.cpp ../src/libUnuk/UI/Text.cpp ../src/libUnuk/UI/MainMenu.cpp ../src/libUnuk/UI/IngameMenu.cpp ../src/libUnuk/UI/Font.cpp ../src/libUnuk/UI/ButtonToggle.cpp ../src/libUnuk/UI/ButtonGroup.cpp ../src/libUnuk/UI/Button.cpp ../src/Unuk/Player.cpp ../src/Unuk/main.cpp ../src/Unuk/Globals.cpp ../src/Unuk/Game.cpp ../src/libUnuk/LevelGen/LevelGen.cpp ../src/libUnuk/LevelGen/MapEntities.cpp ../src/libUnuk/LevelGen/MapElement.cpp ../src/libUnuk/UI/EventHistory.cpp ../src/libUnuk/UI/Bar.cpp ../src/libUnuk/System/Vec2.cpp .tmp/Unuk-QT1.0.0/ && (cd `dirname .tmp/Unuk-QT1.0.0` && $(TAR) Unuk-QT1.0.0.tar Unuk-QT1.0.0 && $(COMPRESS) Unuk-QT1.0.0.tar) && $(MOVE) `dirname .tmp/Unuk-QT1.0.0`/Unuk-QT1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/Unuk-QT1.0.0
|
$(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/Libs/wglext.h ../src/Libs/glxext.h ../src/libUnuk/Engine/WorldManager.h ../src/libUnuk/Engine/ParticleEmitter.h ../src/libUnuk/Engine/NPC.h ../src/libUnuk/Engine/MemManager.h ../src/libUnuk/Engine/MemClass.h ../src/libUnuk/Engine/Collision.h ../src/libUnuk/Engine/Character.h ../src/libUnuk/Engine/AStarBase.h ../src/libUnuk/Engine/AStar.h ../src/libUnuk/Sprite/TextureManager.h ../src/libUnuk/Sprite/Texture.h ../src/libUnuk/Sprite/ImageLoader.h ../src/libUnuk/Sprite/ApplySurface.h ../src/libUnuk/System/Rect.h ../src/libUnuk/System/Input.h ../src/libUnuk/System/FPS.h ../src/libUnuk/System/Debug.h ../src/libUnuk/System/Timer.h ../src/libUnuk/UI/MainMenu.h ../src/libUnuk/UI/IngameMenu.h ../src/libUnuk/UI/Font.h ../src/libUnuk/UI/ButtonToggle.h ../src/libUnuk/UI/ButtonGroup.h ../src/libUnuk/UI/Button.h ../src/libUnuk/UI/Text.h ../src/Unuk/Globals.h ../src/Unuk/Game.h ../src/Unuk/Constants.h ../src/Unuk/Player.h ../src/libUnuk/LevelGen/LevelGen.h ../src/libUnuk/LevelGen/MapEntities.h ../src/libUnuk/LevelGen/MapElement.h ../src/libUnuk/LevelGen/MapTile.h ../src/libUnuk/UI/EventHistory.h ../src/libUnuk/UI/Bar.h ../src/libUnuk/System/Vec2.h ../src/libUnuk/System/MathBox.h .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Engine/WorldManager.cpp ../src/libUnuk/Engine/ParticleEmitter.cpp ../src/libUnuk/Engine/NPC.cpp ../src/libUnuk/Engine/MemManager.cpp ../src/libUnuk/Engine/Collision.cpp ../src/libUnuk/Engine/Character.cpp ../src/libUnuk/Engine/AStar.cpp ../src/libUnuk/Sprite/TextureManager.cpp ../src/libUnuk/Sprite/Texture.cpp ../src/libUnuk/Sprite/ImageLoader.cpp ../src/libUnuk/Sprite/ApplySurface.cpp ../src/libUnuk/System/Timer.cpp ../src/libUnuk/System/Rect.cpp ../src/libUnuk/System/Input.cpp ../src/libUnuk/System/FPS.cpp ../src/libUnuk/System/Debug.cpp ../src/libUnuk/UI/Text.cpp ../src/libUnuk/UI/MainMenu.cpp ../src/libUnuk/UI/IngameMenu.cpp ../src/libUnuk/UI/Font.cpp ../src/libUnuk/UI/ButtonToggle.cpp ../src/libUnuk/UI/ButtonGroup.cpp ../src/libUnuk/UI/Button.cpp ../src/Unuk/Player.cpp ../src/Unuk/main.cpp ../src/Unuk/Globals.cpp ../src/Unuk/Game.cpp ../src/libUnuk/LevelGen/LevelGen.cpp ../src/libUnuk/LevelGen/MapEntities.cpp ../src/libUnuk/LevelGen/MapElement.cpp ../src/libUnuk/UI/EventHistory.cpp ../src/libUnuk/UI/Bar.cpp ../src/libUnuk/System/Vec2.cpp .tmp/Unuk-QT1.0.0/ && (cd `dirname .tmp/Unuk-QT1.0.0` && $(TAR) Unuk-QT1.0.0.tar Unuk-QT1.0.0 && $(COMPRESS) Unuk-QT1.0.0.tar) && $(MOVE) `dirname .tmp/Unuk-QT1.0.0`/Unuk-QT1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/Unuk-QT1.0.0
|
||||||
|
|
||||||
|
|
||||||
clean:compiler_clean
|
clean:compiler_clean
|
||||||
|
@ -42,7 +42,8 @@ HEADERS += ../src/Libs/wglext.h \
|
|||||||
../src/libUnuk/LevelGen/MapTile.h \
|
../src/libUnuk/LevelGen/MapTile.h \
|
||||||
../src/libUnuk/UI/EventHistory.h \
|
../src/libUnuk/UI/EventHistory.h \
|
||||||
../src/libUnuk/UI/Bar.h \
|
../src/libUnuk/UI/Bar.h \
|
||||||
../src/libUnuk/System/Vec2.h
|
../src/libUnuk/System/Vec2.h \
|
||||||
|
../src/libUnuk/System/MathBox.h
|
||||||
SOURCES += ../src/libUnuk/Engine/WorldManager.cpp \
|
SOURCES += ../src/libUnuk/Engine/WorldManager.cpp \
|
||||||
../src/libUnuk/Engine/ParticleEmitter.cpp \
|
../src/libUnuk/Engine/ParticleEmitter.cpp \
|
||||||
../src/libUnuk/Engine/NPC.cpp \
|
../src/libUnuk/Engine/NPC.cpp \
|
||||||
|
@ -37,8 +37,8 @@ public:
|
|||||||
void SetHealth(int health) { _health = health; }
|
void SetHealth(int health) { _health = health; }
|
||||||
int GetHealth(void) { return _health; }
|
int GetHealth(void) { return _health; }
|
||||||
|
|
||||||
int GetDirectionFacing(void) { return directionFacing; }
|
int GetDirectionFacing(void) { return directionFacing; }
|
||||||
void SetDirectionFacing(int dir) { directionFacing = dir; }
|
void SetDirectionFacing(int dir) { directionFacing = dir; }
|
||||||
|
|
||||||
void AddSpeachBubble(string text);
|
void AddSpeachBubble(string text);
|
||||||
|
|
||||||
|
38
src/libUnuk/System/MathBox.h
Normal file
38
src/libUnuk/System/MathBox.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Vec2.h"
|
||||||
|
|
||||||
|
class MathBox {
|
||||||
|
public:
|
||||||
|
// A templated max function that returns none other than the max of two values.
|
||||||
|
template<typename T>
|
||||||
|
static T Max(T value1, T value2) {
|
||||||
|
return value1 > value2 ? value1 : value2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A templated min function that returns none other than the min of two values.
|
||||||
|
template<typename T>
|
||||||
|
static T Min(T value1, T value2) {
|
||||||
|
return value1 < value2 ? value1 : value2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Linear interpolation between two values.
|
||||||
|
template<typename T>
|
||||||
|
static T Lerp(T value1, T value2, float amount) {
|
||||||
|
return T(value1 + ((T)(value2 - value1) * amount));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clamp an integer to a specified range.
|
||||||
|
static int Clamp(int value, int min, int max) {
|
||||||
|
return Max(min, Min(max, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clamp a float to a specified range.
|
||||||
|
static float Clamp(float value, float min, float max) {
|
||||||
|
return Max(min, Min(max, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clamp a double-precision to a specified range.
|
||||||
|
static double Clamp(double value, double min, double max) {
|
||||||
|
return Max(min, Min(max, value));
|
||||||
|
}
|
||||||
|
};
|
@ -40,7 +40,7 @@ float Vec2::DistanceSquared(const Vec2& value1, const Vec2& value2) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Static.
|
// Static.
|
||||||
float Vec2::Dot(const Vec2& value1, Vec2& value2) {
|
float Vec2::Dot(const Vec2& value1, const Vec2& value2) {
|
||||||
return (value1.x * value2.x) - (value1.y * value2.y);
|
return (value1.x * value2.x) - (value1.y * value2.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,6 +68,42 @@ Vec2 Vec2::Normalize(const Vec2& value) {
|
|||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Static.
|
||||||
|
Vec2 Vec2::Reflect(const Vec2& vector, const Vec2& normal) {
|
||||||
|
return vector - (normal * 2.0f * Dot(vector, normal));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Static.
|
||||||
|
Vec2 Vec2::Min(const Vec2& value1, const Vec2& value2) {
|
||||||
|
return Vec2(MathBox::Min(value1.x, value2.x), MathBox::Min(value1.y, value2.y));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Static.
|
||||||
|
Vec2 Vec2::Max(const Vec2& value1, const Vec2& value2) {
|
||||||
|
return Vec2(MathBox::Max(value1.x, value2.x), MathBox::Max(value1.y, value2.y));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Static.
|
||||||
|
Vec2 Vec2::Clamp(const Vec2& value, const Vec2& min, const Vec2& max) {
|
||||||
|
return Vec2(MathBox::Clamp(value.x, min.x, max.x), MathBox::Clamp(value.y, min.y, max.y));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Static.
|
||||||
|
Vec2 Vec2::Lerp(const Vec2& value1, const Vec2& value2, float amount) {
|
||||||
|
return Vec2(MathBox::Lerp(value1.x, value2.x, amount), MathBox::Lerp(value1.y, value2.y, amount));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Static.
|
||||||
|
Vec2 Vec2::Negate(const Vec2& value) {
|
||||||
|
return -value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Static.
|
||||||
|
Vec2 Vec2::Rotate(const Vec2& value, const float radians) {
|
||||||
|
float c = cos(radians);
|
||||||
|
float s = sin(radians);
|
||||||
|
return Vec2(value.x * c - value.y * s, value.y * c + value.x * s);
|
||||||
|
}
|
||||||
|
|
||||||
// Overload some operators..
|
// Overload some operators..
|
||||||
bool Vec2::operator==(const Vec2& v) const {
|
bool Vec2::operator==(const Vec2& v) const {
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
#include "MathBox.h"
|
||||||
|
|
||||||
// A handy structure for passing around 2D integer coords.
|
// A handy structure for passing around 2D integer coords.
|
||||||
struct Vec2i {
|
struct Vec2i {
|
||||||
int x, y;
|
int x, y;
|
||||||
@ -46,7 +48,7 @@ struct Vec2 {
|
|||||||
static float DistanceSquared(const Vec2& value1, const Vec2& value2);
|
static float DistanceSquared(const Vec2& value1, const Vec2& value2);
|
||||||
|
|
||||||
// Get the dot product of two vectors.
|
// Get the dot product of two vectors.
|
||||||
static float Dot(const Vec2& value1, Vec2& value2);
|
static float Dot(const Vec2& value1, const Vec2& value2);
|
||||||
|
|
||||||
/* Get the cross product of two vectors. Note that the \b mathmatical
|
/* Get the cross product of two vectors. Note that the \b mathmatical
|
||||||
* definition of a cross product results in another vector oeroendicular
|
* definition of a cross product results in another vector oeroendicular
|
||||||
@ -66,10 +68,10 @@ struct Vec2 {
|
|||||||
static Vec2 Reflect(const Vec2& vector, const Vec2& normal);
|
static Vec2 Reflect(const Vec2& vector, const Vec2& normal);
|
||||||
|
|
||||||
// Get a new vector from the minimum x and y.
|
// Get a new vector from the minimum x and y.
|
||||||
static Vec2 Min(Vec2& value1, Vec2& value2);
|
static Vec2 Min(const Vec2& value1, const Vec2& value2);
|
||||||
|
|
||||||
// Get a new vector from the maximum x and y.
|
// Get a new vector from the maximum x and y.
|
||||||
static Vec2 Max(Vec2& value1, Vec2& value2);
|
static Vec2 Max(const Vec2& value1, const Vec2& value2);
|
||||||
|
|
||||||
// Clamp a vector to a given min and max.
|
// Clamp a vector to a given min and max.
|
||||||
static Vec2 Clamp(const Vec2& value, const Vec2& min, const Vec2& max);
|
static Vec2 Clamp(const Vec2& value, const Vec2& min, const Vec2& max);
|
||||||
@ -80,7 +82,7 @@ struct Vec2 {
|
|||||||
// Get a negated vector.
|
// Get a negated vector.
|
||||||
static Vec2 Negate(const Vec2& value);
|
static Vec2 Negate(const Vec2& value);
|
||||||
|
|
||||||
static Vec2 Rotate(const Vec2& value, Vec2& radians);
|
static Vec2 Rotate(const Vec2& value, const float radians);
|
||||||
|
|
||||||
bool operator==(const Vec2& v) const;
|
bool operator==(const Vec2& v) const;
|
||||||
bool operator!=(const Vec2& v) const;
|
bool operator!=(const Vec2& v) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user