Skip to content

Commit

Permalink
no rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
klavins committed Mar 12, 2020
1 parent ad16c09 commit 1ecf163
Show file tree
Hide file tree
Showing 19 changed files with 484 additions and 6 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ This method returns the angular velocity of the agent in radians per second and
> `int id()`<br>
This method returns a unique id of the agent.
> `void prevent_rotation()`<br>
Prevents the agent from rotating. Probably best to call in the init function. Good for platformer type movement. Technically sets the moment of inertia to infinity. &#x246D; New in 1.4.
> `void allow_rotation()` <br>
Allows the agent to rotate, setting the moment of inertia to the default number (based on the mass and shape of the agent). &#x246D; New in 1.4.
Motion Control for Oriented Agents
---
Expand Down
10 changes: 10 additions & 0 deletions examples/platformer/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
TARGET := bin/enviro

all:
$(MAKE) -C src all

clean:
$(MAKE) -C src clean



119 changes: 119 additions & 0 deletions examples/platformer/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{

"name": "My Enviro Project",
"ip": "0.0.0.0",
"port": 8765,

"buttons": [],

"agents": [
{
"definition": "defs/guy.json",
"style": { "fill": "lightblue", "stroke": "black" },
"position": {
"x": 0,
"y": 135,
"theta": 0
}
},
{
"definition": "defs/bumper.json",
"style": { "fill": "red", "stroke": "none" },
"position": {
"x": -145,
"y": 68,
"theta": 0
}
},
{
"definition": "defs/bumper.json",
"style": { "fill": "red", "stroke": "none" },
"position": {
"x": 145,
"y": 68,
"theta": 0
}
},
{
"definition": "defs/ghost.json",
"style": { "fill": "lightgreen", "stroke": "black" },
"position": {
"x": 0,
"y": 80,
"theta": 0
}
}

],

"statics": [
{
"style": { "fill": "gray", "stroke": "none" },
"shape": [
{ "x": -350, "y": -200 },
{ "x": -350, "y": 200 },
{ "x": -340, "y": 200 },
{ "x": -340, "y": -200 }
]
},
{
"style": { "fill": "gray", "stroke": "none" },
"shape": [
{ "x": 350, "y": -200 },
{ "x": 350, "y": 200 },
{ "x": 340, "y": 200 },
{ "x": 340, "y": -200 }
]
},
{
"style": { "fill": "gray", "stroke": "none" },
"shape": [
{ "x": -350, "y": 200 },
{ "x": 350, "y": 200 },
{ "x": 350, "y": 190 },
{ "x": -350, "y": 190 }
]
},
{
"style": { "fill": "gray", "stroke": "none" },
"shape": [
{ "x": -350, "y": -200 },
{ "x": 350, "y": -200 },
{ "x": 350, "y": -190 },
{ "x": -350, "y": -190 }
]
},

{
"style": { "fill": "gray", "stroke": "none" },
"shape": [
{ "x": -350, "y": 125 },
{ "x": -250, "y": 125 },
{ "x": -250, "y": 115 },
{ "x": -350, "y": 115 }
]
},

{
"style": { "fill": "gray", "stroke": "none" },
"shape": [
{ "x": -150, "y": 90 },
{ "x": 150, "y": 90 },
{ "x": 150, "y": 80 },
{ "x": -150, "y": 80 }
]
},

{
"style": { "fill": "gray", "stroke": "none" },
"shape": [
{ "x": 350, "y": 55 },
{ "x": 250, "y": 55 },
{ "x": 250, "y": 45 },
{ "x": 350, "y": 45 }
]
}

]

}
1 change: 1 addition & 0 deletions examples/platformer/defs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Put agent definitions in this folder.
19 changes: 19 additions & 0 deletions examples/platformer/defs/bumper.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "Bumper",
"type": "static",
"description": "Replace this string with a description",
"shape": [
{ "x": -5, "y": 10 },
{ "x": 5, "y": 10 },
{ "x": 5, "y": -10 },
{ "x": -5, "y": -10 }
],
"friction": {
"collision": 5,
"linear": 40,
"rotational": 600
},
"sensors": [],
"mass": 1,
"controller": "lib/bumper.so"
}
21 changes: 21 additions & 0 deletions examples/platformer/defs/ghost.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "Ghost",
"type": "dynamic",
"description": "Replace this string with a description",
"shape": [
{ "x": -10, "y": 15 },
{ "x": 10, "y": 15 },
{ "x": 10, "y": -15 },
{ "x": 0, "y": -17 },
{ "x": -10, "y": -15 }

],
"friction": {
"collision": 5,
"linear": 40,
"rotational": 600
},
"sensors": [],
"mass": 1,
"controller": "lib/ghost.so"
}
30 changes: 30 additions & 0 deletions examples/platformer/defs/guy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "Guy",
"type": "dynamic",
"description": "Replace this string with a description",
"shape": [
{ "x": -10, "y": 15 },
{ "x": 10, "y": 15 },
{ "x": 10, "y": -15 },
{ "x": -10, "y": -15 }
],
"friction": {
"collision": 0,
"linear": 0,
"rotational": 0
},
"sensors": [
{
"type": "range",
"location": { "x": 10, "y": 15 },
"direction": 1.57
},
{
"type": "range",
"location": { "x": -10, "y": 15 },
"direction": 1.57
}
],
"mass": 1,
"controller": "lib/guy.so"
}
1 change: 1 addition & 0 deletions examples/platformer/lib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Shared object libraries will be place here by make.
38 changes: 38 additions & 0 deletions examples/platformer/src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#Architecture
ARCH := $(shell uname -m)

#Compilers
CC := g++ -std=c++17 -Wno-psabi

#The Target Library

#The Directories, Source, Includes, Objects, Binary and Resources
SRCEXT := cc

# Directories
CHIPDIR := /usr/local/src/Chipmunk2D
ENVIRODIR := ../../../server/include

#Flags, Libraries and Includes
CFLAGS := -ggdb -shared -fPIC
INCLUDE := -I $(ENVIRODIR) -I $(CHIPDIR)/include/chipmunk

#Files

TARGETDIR := ../lib
SOURCES := $(wildcard *.cc)
HEADERS := $(wildcard *.h)
TARGETS := $(patsubst %.cc,%.so,$(wildcard *.cc))
FULL_TARGETS := $(addprefix $(TARGETDIR)/, $(TARGETS))

#Default Make
all: $(FULL_TARGETS)

#Clean only Objects
clean:
@$(RM) -rf $(TARGETDIR)/*.so

# Compile
$(TARGETDIR)/%.so: %.cc %.h
$(CC) $(CFLAGS) $(INCLUDE) $< -o $@

6 changes: 6 additions & 0 deletions examples/platformer/src/bumper.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>
#include "bumper.h"

using namespace enviro;

// Put your implementations here
31 changes: 31 additions & 0 deletions examples/platformer/src/bumper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef __BUMPER_AGENT__H
#define __BUMPER_AGENT__H

#include "enviro.h"

using namespace enviro;

class BumperController : public Process, public AgentInterface {

public:
BumperController() : Process(), AgentInterface() {}

void init() {}
void start() {}
void update() {}
void stop() {}

};

class Bumper : public Agent {
public:
Bumper(json spec, World& world) : Agent(spec, world) {
add_process(c);
}
private:
BumperController c;
};

DECLARE_INTERFACE(Bumper)

#endif
6 changes: 6 additions & 0 deletions examples/platformer/src/ghost.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>
#include "ghost.h"

using namespace enviro;

// Put your implementations here
54 changes: 54 additions & 0 deletions examples/platformer/src/ghost.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifndef __GHOST_AGENT__H
#define __GHOST_AGENT__H

#include "enviro.h"

using namespace enviro;

class GhostController : public Process, public AgentInterface {

public:
GhostController() : Process(), AgentInterface(), vx(20) {}

void init() {
prevent_rotation();
notice_collisions_with("Bumper", [&](Event &e) {
if ( counter == 0 ) {
vx = -vx;
counter = 10;
}
});
decorate(R"(<g>
<circle cx=-5 cy=-3 r=2 style='fill:black'></circle>
<circle cx=5 cy=-3 r=2 style='fill:black'></circle></g>)");
}

void start() {}

void update() {
double fx = -30*(velocity().x-vx);
omni_apply_force(fx,0);
if ( counter > 0 ) {
counter--;
}
}

void stop() {}

double vx;
int counter;

};

class Ghost : public Agent {
public:
Ghost(json spec, World& world) : Agent(spec, world) {
add_process(c);
}
private:
GhostController c;
};

DECLARE_INTERFACE(Ghost)

#endif
6 changes: 6 additions & 0 deletions examples/platformer/src/guy.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <iostream>
#include "guy.h"

using namespace enviro;

// Put your implementations here
Loading

0 comments on commit 1ecf163

Please sign in to comment.