Skip to content

Commit 495d89c

Browse files
committed
Initial commit
0 parents  commit 495d89c

25 files changed

+1121
-0
lines changed

Diff for: .gitignore

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Created by https://www.gitignore.io
2+
3+
### OSX ###
4+
.DS_Store
5+
.AppleDouble
6+
.LSOverride
7+
8+
# Icon must end with two \r
9+
Icon
10+
11+
12+
# Thumbnails
13+
._*
14+
15+
# Files that might appear on external disk
16+
.Spotlight-V100
17+
.Trashes
18+
19+
# Directories potentially created on remote AFP share
20+
.AppleDB
21+
.AppleDesktop
22+
Network Trash Folder
23+
Temporary Items
24+
.apdisk
25+
26+
27+
### Linux ###
28+
*~
29+
30+
# KDE directory preferences
31+
.directory
32+
33+
34+
### C++ ###
35+
# Compiled Object files
36+
*.slo
37+
*.lo
38+
*.o
39+
*.obj
40+
41+
# Precompiled Headers
42+
*.gch
43+
*.pch
44+
45+
# Compiled Dynamic libraries
46+
*.so
47+
*.dylib
48+
*.dll
49+
50+
# Fortran module files
51+
*.mod
52+
53+
# Compiled Static libraries
54+
*.lai
55+
*.la
56+
*.a
57+
*.lib
58+
59+
# Executables
60+
*.exe
61+
*.out
62+
*.app

Diff for: LICENSE

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014 myurtoglu
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Diff for: Makefile

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
2+
3+
CXX = clang++
4+
CXXFLAGS = -std=c++11 -Wall -Wextra -pedantic -O3
5+
6+
SFGUI = -lsfgui
7+
BOX2D = -lBox2D
8+
9+
ifeq ($(uname_S), Darwin)
10+
SF_SYSTEM = -framework sfml-system
11+
SF_WINDOW = -framework sfml-window
12+
SF_GRAPHICS = -framework sfml-graphics
13+
SF_AUDIO = -framework sfml-audio
14+
SF_NETWORK = -framework sfml-network
15+
FOUNDATION = -framework Foundation
16+
LDFLAGS = $(SF_SYSTEM) $(SF_WINDOW) $(SF_GRAPHICS) $(SF_AUDIO) \
17+
$(SF_NETWORK) $(FOUNDATION) $(SFGUI) $(BOX2D)
18+
endif
19+
20+
ifeq ($(uname_S), Linux)
21+
CXX = g++
22+
LDFLAGS = -lsfml-system -lsfml-window -lsfml-graphics -lsfml-audio \
23+
-lsfml-network -lobjc -lgnustep-base \
24+
$(SFGUI) $(BOX2D)
25+
INCLUDE = -I/usr/include/GNUstep
26+
endif
27+
28+
VPATH = src src/*
29+
BUILDDIR = build
30+
CPP_SRC = $(wildcard src/*.cpp src/**/*.cpp)
31+
MM_SRC = $(wildcard src/*.mm src/**/*.mm)
32+
HEADER = $(wildcard src/*.h src/*.hpp src/**/*.h src/**/*.hpp)
33+
OBJ = $(patsubst src/%.cpp, $(BUILDDIR)/%.o, $(CPP_SRC))
34+
OBJ += $(patsubst src/%.mm, $(BUILDDIR)/%.o, $(MM_SRC))
35+
OBJDIR = $(dir $(OBJ))
36+
37+
.PHONY: all clean clobber directories
38+
39+
$(BUILDDIR)/%.o: %.cpp $(HEADER)
40+
$(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -o $@
41+
42+
$(BUILDDIR)/%.o: %.mm $(HEADER)
43+
$(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -o $@
44+
45+
all: directories main.exe
46+
47+
main.exe: $(OBJ)
48+
$(CXX) -o $@ $(OBJ) $(LDFLAGS)
49+
50+
directories:
51+
@mkdir -p $(OBJDIR)
52+
53+
clean:
54+
rm -rf $(BUILDDIR)
55+
56+
clobber: clean
57+
rm -rf *.exe
58+

Diff for: Media/Audio/pause_sound.wav

35.5 KB
Binary file not shown.

Diff for: Media/Fonts/Sansation.ttf

28.2 KB
Binary file not shown.

Diff for: README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## SimpleFastPhysicsSandbox
2+
3+
###About
4+
5+
This is a simple phsyics sandbox written in C++ using [SFML 2.1](http://www.sfml-dev.org). The physics part is handled by [Box2D v2.3.0](http://box2d.org). [SFGUI v0.2.0](http://sfgui.sfml-dev.de) library has also been used for the user interface. This sandbox gives user the capability to create rectangles, disks, and rectangular fixtures of different sizes. Gravity can be changed using the slider. Right-click destroys the selected object, whereas spacebar pauses the sandbox.
6+
7+
### Video
8+
9+
A short video showing the application can be found [here on Youtube](http://youtu.be/EjOszKG9nr8).

Diff for: src/BoxSfmlHelpers.hpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#ifndef BoxSfmlHelpers_HPP_
2+
#define BoxSfmlHelpers_HPP_
3+
4+
#include <SFML/Graphics.hpp>
5+
#include <Box2D/Box2D.h>
6+
7+
// template function to convert sfml vectors to box2d vectors
8+
template <typename T>
9+
inline b2Vec2 ConvSfToB2Vec(const sf::Vector2<T>&, int, float);
10+
11+
// box2d vectors to sfml vectors (float)
12+
inline sf::Vector2f ConvB2VecToSff(const b2Vec2&, int, float);
13+
14+
// box2d vectors to sfml vectors (integer)
15+
inline sf::Vector2i ConvB2VecToSfi(const b2Vec2&, int, float);
16+
17+
#include "BoxSfmlHelpers.inl"
18+
19+
#endif

Diff for: src/BoxSfmlHelpers.inl

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
template <typename T>
2+
b2Vec2 ConvSfToB2Vec(const sf::Vector2<T>& sfVec, int ySize, float PPM)
3+
{
4+
return {sfVec.x / PPM, (ySize - sfVec.y) / PPM};
5+
}
6+
7+
sf::Vector2f ConvB2VecToSff(const b2Vec2& b2Vec, int ySize, float PPM)
8+
{
9+
return {b2Vec.x * PPM, ySize - b2Vec.y * PPM};
10+
}
11+
12+
sf::Vector2i ConvB2VecToSfi(const b2Vec2& b2Vec, int ySize, float PPM)
13+
{
14+
return {static_cast<int>(b2Vec.x * PPM),
15+
static_cast<int>(ySize - b2Vec.y * PPM)};
16+
}

Diff for: src/CircShape.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <memory>
2+
#include "CircShape.hpp"
3+
#include "BoxSfmlHelpers.hpp"
4+
5+
6+
CircShape::CircShape(b2World &world, b2Vec2 initialPos, float radius,
7+
unsigned ySize, float PPM): Shape(world, initialPos,
8+
ySize, PPM)
9+
{
10+
mShape = std::unique_ptr<sf::CircleShape>(new sf::CircleShape(radius));
11+
mShape->setFillColor(sf::Color::Blue);
12+
mShape->setOrigin(radius, radius);
13+
mBodyShape = std::unique_ptr<b2CircleShape>(new b2CircleShape());
14+
mBodyShape->m_radius = radius/mPPM;
15+
setBodyFix(0.3f, 0.5f, 0.25f);
16+
update();
17+
}

Diff for: src/CircShape.hpp

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef CircShape_HPP_
2+
#define CircShape_HPP_
3+
4+
#include "Shape.hpp"
5+
6+
7+
class CircShape : public Shape
8+
{
9+
public:
10+
CircShape(b2World&, b2Vec2, float, unsigned, float);
11+
};
12+
13+
#endif

Diff for: src/FixtureShape.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <memory>
2+
#include "FixtureShape.hpp"
3+
#include "BoxSfmlHelpers.hpp"
4+
5+
6+
FixtureShape::FixtureShape(b2World & world, b2Vec2 initialPos, b2Vec2 size,
7+
unsigned ySize, float PPM, sf::Color color)
8+
: Shape(world, initialPos, ySize, PPM)
9+
{
10+
mShape = std::unique_ptr<sf::RectangleShape>(new sf::RectangleShape(sf::Vector2f(size.x,size.y)));
11+
mShape->setFillColor(color);
12+
mShape->setOrigin(size.x/2.f, size.y/2.f);
13+
world.DestroyBody(mBody);
14+
mBodyDef.type = b2_staticBody;
15+
mBody = world.CreateBody(&mBodyDef);
16+
mBodyShape = std::unique_ptr<b2PolygonShape>(new b2PolygonShape());
17+
static_cast<b2PolygonShape*>(mBodyShape.get())->SetAsBox(size.x/(2*mPPM),
18+
size.y/(2*mPPM));
19+
setBodyFix(0.3f, 0.5f, 0.25f);
20+
update();
21+
}

Diff for: src/FixtureShape.hpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef FixtureShape_HPP_
2+
#define FixtureShape_HPP_
3+
4+
#include "Shape.hpp"
5+
6+
7+
class FixtureShape : public Shape
8+
{
9+
public:
10+
FixtureShape(b2World&, b2Vec2, b2Vec2, unsigned, float,
11+
sf::Color color=sf::Color::Red);
12+
};
13+
14+
#endif
15+

0 commit comments

Comments
 (0)