Skip to content

Commit

Permalink
Implement simple edge-evasion (PypeBros' suggestion)
Browse files Browse the repository at this point in the history
On  Thu  May  24, 2012 3:48 pm, PypeBros wrote: some edge‐evasion
algorithm (à  la 2D‐Zelda) would be nice so that we’re not  stuck
as soon as we approach a corner.

On  Mon May 28, 2012 7:05 am, PypeBros wrote: In a 3D environment
with freely positioned direction, you could use the projection of
your  intended  velocity against the wall (cos normal_angle * ve‐
locity, iirc) as the collision resulting velocity.
  • Loading branch information
bl0ckeduser committed May 29, 2012
1 parent a7a8c09 commit a046c6e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile.pc
@@ -1,7 +1,7 @@
# now works in BSD `make'

CC ?= cc
CFLAGS =-DPC_TARGET `sdl-config --cflags`
CFLAGS =-DPC_TARGET `sdl-config --cflags` -lGL -lGLU
objects = bullet.o collisions.o door.o ds-trig.o framerate.o gc.o genBoxes.o key.o main.o mem-check.o model-data.o model-draw.o model-load.o objlist.o oop.o player.o require.o string-read.o target.o

headers = headers.h
Expand Down
6 changes: 6 additions & 0 deletions TODO
Expand Up @@ -28,3 +28,9 @@
I suspect maxed out polygon count.

+ Get the default world to load on the real console.


- Fix the collision resolve jitter.
(I must confess that I've seen in it in a professional
3d DS game once though)
- Test the new edge-evasion code
Binary file modified clown3d-DS.nds
Binary file not shown.
35 changes: 32 additions & 3 deletions collisions.c
@@ -1,7 +1,9 @@
/*
* The "Clown" 3D Game Engine
* Designed, debugged and perfected
* by Bl0ckeduser, 2011
* by Bl0ckeduser, 2011.
*
* Edge evasion added May 2012
*
* (i.e. on paper it wasn't this
* complicated and full of workarounds)
Expand All @@ -16,6 +18,8 @@
#include <stdlib.h>
#include "headers.h"

int which;

/* Compares using absolute values, equivalent
to measuring the magnitude of a 1-dimensional
vector. Ignores zero-length values as
Expand Down Expand Up @@ -100,14 +104,23 @@ float smallestOfThree(float a, float b, float c)
y_offs / node->box.move.y, \
z_offs / node->box.move.z); \
\
/* \
* collision axis register used by edge-evasion code \
* ("wall direction") \
*/ \
which = 0; \
if(ratio == x_offs / node->box.move.x) which = 1; \
if(ratio == y_offs / node->box.move.y) which = 2; \
if(ratio == z_offs / node->box.move.z) which = 3; \
\
/* Cheap way to avoid glitches. Normally, \
ratio should be between 0 and 1. */ \
if(ratio < -2.0) ratio = 0.0; \
\
/* Cheap fix for another glitch. Avoid \
inifinite collision-solving loops (player \
infinite collision-solving loops (player \
gets stuck) */ \
ratio *= 1.01; \
ratio *= 1.00001; \
\
react.x = node->box.move.x * ratio; \
react.y = node->box.move.y * ratio; \
Expand Down Expand Up @@ -232,6 +245,9 @@ void resolveCollisions(game_obj* objs, void (*handler)(void*, void*))

node->box.move.y = 0.0;

/* clear the edge-evasion register */
which = 0;

if(stair){
/* stairs mode */
resolveCollisions_checkVertex_stair(min, min, min, collision_found2);
Expand All @@ -254,6 +270,19 @@ void resolveCollisions(game_obj* objs, void (*handler)(void*, void*))
}
collision_found2:

/* Simple edge-evasion, based on PypeBros' suggestion.
When a collision occurs,the projection of the player's
move vector on the "wall direction" (obtained here from
earlier collision calculations) is added for edge evasion. */
if(node->type == PLAYER && which == 3) {
node->box.min.x += move.x;
node->box.max.x += move.x;
}
if(node->type == PLAYER && which == 1) {
node->box.min.z += move.z;
node->box.max.z += move.z;
}

node->box.min.x += react.x;
node->box.max.x += react.x;

Expand Down

0 comments on commit a046c6e

Please sign in to comment.