Physik-Engine angefangen.
Lightmaps implementiert.
This commit is contained in:
parent
f5ef6536cc
commit
1021d32f7c
13 changed files with 141 additions and 100 deletions
|
@ -1,3 +1,3 @@
|
|||
lib_LTLIBRARIES = libneofx.la
|
||||
libneofx_la_SOURCES = math.c collision.c
|
||||
nobase_include_HEADERS = neofx/math.h neofx/collision.h neofx/types.h
|
||||
libneofx_la_SOURCES = math.c collision.c physics.c
|
||||
nobase_include_HEADERS = neofx/math.h neofx/collision.h neofx/types.h neofx/physics.h
|
||||
|
|
10
Makefile.in
10
Makefile.in
|
@ -133,8 +133,8 @@ sharedstatedir = @sharedstatedir@
|
|||
sysconfdir = @sysconfdir@
|
||||
target_alias = @target_alias@
|
||||
lib_LTLIBRARIES = libneofx.la
|
||||
libneofx_la_SOURCES = math.c collision.c
|
||||
nobase_include_HEADERS = neofx/math.h neofx/collision.h neofx/types.h
|
||||
libneofx_la_SOURCES = math.c collision.c physics.c
|
||||
nobase_include_HEADERS = neofx/math.h neofx/collision.h neofx/types.h neofx/physics.h
|
||||
subdir = .
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
|
@ -144,13 +144,14 @@ LTLIBRARIES = $(lib_LTLIBRARIES)
|
|||
|
||||
libneofx_la_LDFLAGS =
|
||||
libneofx_la_LIBADD =
|
||||
am_libneofx_la_OBJECTS = math.lo collision.lo
|
||||
am_libneofx_la_OBJECTS = math.lo collision.lo physics.lo
|
||||
libneofx_la_OBJECTS = $(am_libneofx_la_OBJECTS)
|
||||
|
||||
DEFAULT_INCLUDES = -I. -I$(srcdir) -I.
|
||||
depcomp = $(SHELL) $(top_srcdir)/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/collision.Plo ./$(DEPDIR)/math.Plo
|
||||
@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/collision.Plo ./$(DEPDIR)/math.Plo \
|
||||
@AMDEP_TRUE@ ./$(DEPDIR)/physics.Plo
|
||||
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) \
|
||||
|
@ -245,6 +246,7 @@ distclean-compile:
|
|||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/collision.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/math.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/physics.Plo@am__quote@
|
||||
|
||||
.c.o:
|
||||
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" \
|
||||
|
|
|
@ -27,7 +27,7 @@ int CollisionPointTriangle(VERTEX p, TRIANGLE t) {
|
|||
|
||||
int CollisionRayTriangle(VERTEX p, VECTOR vec, TRIANGLE t, float* f) {
|
||||
VECTOR pvec, tvec, qvec, edge1, edge2;
|
||||
float det, u, v, invDet;
|
||||
float det, u, v;
|
||||
|
||||
edge1 = VectorSub(t.vertices[1], t.vertices[0]);
|
||||
edge2 = VectorSub(t.vertices[2], t.vertices[0]);
|
||||
|
@ -46,11 +46,7 @@ int CollisionRayTriangle(VERTEX p, VECTOR vec, TRIANGLE t, float* f) {
|
|||
v = VectorDot(vec, qvec);
|
||||
if(v < 0.0 || u+v > det) return 0;
|
||||
|
||||
if(f) {
|
||||
*f = VectorDot(edge2, qvec);
|
||||
invDet = 1.0 / det;
|
||||
*f *= invDet;
|
||||
}
|
||||
if(f) *f = VectorDot(edge2, qvec) / det;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
and to 0 otherwise. */
|
||||
#undef HAVE_REALLOC
|
||||
|
||||
/* Define to 1 if you have the `sqrt' function. */
|
||||
#undef HAVE_SQRT
|
||||
/* Define to 1 if you have the `sqrtf' function. */
|
||||
#undef HAVE_SQRTF
|
||||
|
||||
/* Define to 1 if you have the <stddef.h> header file. */
|
||||
#undef HAVE_STDDEF_H
|
||||
|
|
151
configure
vendored
151
configure
vendored
|
@ -19032,6 +19032,79 @@ LIBTOOL='$(SHELL) $(top_builddir)/libtool'
|
|||
|
||||
# Checks for libraries.
|
||||
|
||||
echo "$as_me:$LINENO: checking for sqrt in -lm" >&5
|
||||
echo $ECHO_N "checking for sqrt in -lm... $ECHO_C" >&6
|
||||
if test "${ac_cv_lib_m_sqrt+set}" = set; then
|
||||
echo $ECHO_N "(cached) $ECHO_C" >&6
|
||||
else
|
||||
ac_check_lib_save_LIBS=$LIBS
|
||||
LIBS="-lm $LIBS"
|
||||
cat >conftest.$ac_ext <<_ACEOF
|
||||
/* confdefs.h. */
|
||||
_ACEOF
|
||||
cat confdefs.h >>conftest.$ac_ext
|
||||
cat >>conftest.$ac_ext <<_ACEOF
|
||||
/* end confdefs.h. */
|
||||
|
||||
/* Override any gcc2 internal prototype to avoid an error. */
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
/* We use char because int might match the return type of a gcc2
|
||||
builtin and then its argument prototype would still apply. */
|
||||
char sqrt ();
|
||||
int
|
||||
main ()
|
||||
{
|
||||
sqrt ();
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
rm -f conftest.$ac_objext conftest$ac_exeext
|
||||
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
(eval $ac_link) 2>conftest.er1
|
||||
ac_status=$?
|
||||
grep -v '^ *+' conftest.er1 >conftest.err
|
||||
rm -f conftest.er1
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); }; } &&
|
||||
{ ac_try='test -s conftest$ac_exeext'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); }; }; then
|
||||
ac_cv_lib_m_sqrt=yes
|
||||
else
|
||||
echo "$as_me: failed program was:" >&5
|
||||
sed 's/^/| /' conftest.$ac_ext >&5
|
||||
|
||||
ac_cv_lib_m_sqrt=no
|
||||
fi
|
||||
rm -f conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
LIBS=$ac_check_lib_save_LIBS
|
||||
fi
|
||||
echo "$as_me:$LINENO: result: $ac_cv_lib_m_sqrt" >&5
|
||||
echo "${ECHO_T}$ac_cv_lib_m_sqrt" >&6
|
||||
if test $ac_cv_lib_m_sqrt = yes; then
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define HAVE_LIBM 1
|
||||
_ACEOF
|
||||
|
||||
LIBS="-lm $LIBS"
|
||||
|
||||
fi
|
||||
|
||||
|
||||
# Checks for header files.
|
||||
echo "$as_me:$LINENO: checking for ANSI C header files" >&5
|
||||
echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6
|
||||
|
@ -19878,80 +19951,8 @@ fi
|
|||
|
||||
|
||||
|
||||
echo "$as_me:$LINENO: checking for cos in -lm" >&5
|
||||
echo $ECHO_N "checking for cos in -lm... $ECHO_C" >&6
|
||||
if test "${ac_cv_lib_m_cos+set}" = set; then
|
||||
echo $ECHO_N "(cached) $ECHO_C" >&6
|
||||
else
|
||||
ac_check_lib_save_LIBS=$LIBS
|
||||
LIBS="-lm $LIBS"
|
||||
cat >conftest.$ac_ext <<_ACEOF
|
||||
/* confdefs.h. */
|
||||
_ACEOF
|
||||
cat confdefs.h >>conftest.$ac_ext
|
||||
cat >>conftest.$ac_ext <<_ACEOF
|
||||
/* end confdefs.h. */
|
||||
|
||||
/* Override any gcc2 internal prototype to avoid an error. */
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
/* We use char because int might match the return type of a gcc2
|
||||
builtin and then its argument prototype would still apply. */
|
||||
char cos ();
|
||||
int
|
||||
main ()
|
||||
{
|
||||
cos ();
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
rm -f conftest.$ac_objext conftest$ac_exeext
|
||||
if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
|
||||
(eval $ac_link) 2>conftest.er1
|
||||
ac_status=$?
|
||||
grep -v '^ *+' conftest.er1 >conftest.err
|
||||
rm -f conftest.er1
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); } &&
|
||||
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); }; } &&
|
||||
{ ac_try='test -s conftest$ac_exeext'
|
||||
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
|
||||
(eval $ac_try) 2>&5
|
||||
ac_status=$?
|
||||
echo "$as_me:$LINENO: \$? = $ac_status" >&5
|
||||
(exit $ac_status); }; }; then
|
||||
ac_cv_lib_m_cos=yes
|
||||
else
|
||||
echo "$as_me: failed program was:" >&5
|
||||
sed 's/^/| /' conftest.$ac_ext >&5
|
||||
|
||||
ac_cv_lib_m_cos=no
|
||||
fi
|
||||
rm -f conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
LIBS=$ac_check_lib_save_LIBS
|
||||
fi
|
||||
echo "$as_me:$LINENO: result: $ac_cv_lib_m_cos" >&5
|
||||
echo "${ECHO_T}$ac_cv_lib_m_cos" >&6
|
||||
if test $ac_cv_lib_m_cos = yes; then
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define HAVE_LIBM 1
|
||||
_ACEOF
|
||||
|
||||
LIBS="-lm $LIBS"
|
||||
|
||||
fi
|
||||
|
||||
|
||||
for ac_func in sqrt
|
||||
for ac_func in sqrtf
|
||||
do
|
||||
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
||||
echo "$as_me:$LINENO: checking for $ac_func" >&5
|
||||
|
@ -20049,8 +20050,8 @@ if test `eval echo '${'$as_ac_var'}'` = yes; then
|
|||
_ACEOF
|
||||
|
||||
else
|
||||
{ { echo "$as_me:$LINENO: error: required function sqrt not found" >&5
|
||||
echo "$as_me: error: required function sqrt not found" >&2;}
|
||||
{ { echo "$as_me:$LINENO: error: required function sqrtf not found" >&5
|
||||
echo "$as_me: error: required function sqrtf not found" >&2;}
|
||||
{ (exit 1); exit 1; }; }
|
||||
fi
|
||||
done
|
||||
|
|
|
@ -14,6 +14,7 @@ AC_PROG_CC
|
|||
AC_PROG_LIBTOOL
|
||||
|
||||
# Checks for libraries.
|
||||
AC_CHECK_LIB(m, [sqrt])
|
||||
|
||||
# Checks for header files.
|
||||
AC_HEADER_STDC
|
||||
|
@ -25,8 +26,8 @@ AC_HEADER_TIME
|
|||
# Checks for library functions.
|
||||
AC_FUNC_MALLOC
|
||||
AC_FUNC_REALLOC
|
||||
AC_CHECK_LIB(m, [cos])
|
||||
AC_CHECK_FUNCS([sqrt], , AC_MSG_ERROR([required function sqrt not found]))
|
||||
|
||||
AC_CHECK_FUNCS([sqrtf], , AC_MSG_ERROR([required function sqrtf not found]))
|
||||
|
||||
AC_CONFIG_FILES([Makefile])
|
||||
AC_OUTPUT
|
||||
|
|
4
math.c
4
math.c
|
@ -45,7 +45,7 @@ VECTOR VectorMul(VECTOR v, float f) {
|
|||
}
|
||||
|
||||
VECTOR VectorNormalize(VECTOR v) {
|
||||
float f = sqrt(v.x*v.x + v.y*v.y + v.z*v.z);
|
||||
float f = sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
|
||||
|
||||
v.x /= f;
|
||||
v.y /= f;
|
||||
|
@ -63,7 +63,7 @@ VECTOR VectorNeg(VECTOR v) {
|
|||
}
|
||||
|
||||
float VectorLength(VECTOR v) {
|
||||
return sqrt(v.x*v.x + v.y*v.y + v.z*v.z);
|
||||
return sqrtf(v.x*v.x + v.y*v.y + v.z*v.z);
|
||||
}
|
||||
|
||||
float VectorLengthSq(VECTOR v) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef NEOFX_COLLISION_H
|
||||
#define NEOFX_COLLISION_H
|
||||
|
||||
#include "types.h"
|
||||
#include <neofx/types.h>
|
||||
|
||||
int CollisionPointTriangle(VERTEX, TRIANGLE);
|
||||
int CollisionRayTriangle(VERTEX, VECTOR, TRIANGLE, float*);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef NEOFX_MATH_H
|
||||
#define NEOFX_MATH_H
|
||||
|
||||
#include "types.h"
|
||||
#include <neofx/types.h>
|
||||
|
||||
float VectorDot(VECTOR, VECTOR);
|
||||
VECTOR VectorCross(VECTOR, VECTOR);
|
||||
|
|
9
neofx/physics.h
Normal file
9
neofx/physics.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef NEOFX_PHYSICS_H
|
||||
#define NEOFX_PHYSICS_H
|
||||
|
||||
#include <neofx/types.h>
|
||||
|
||||
void SetGravitation(VECTOR);
|
||||
void ApplyPhysics(OBJECT, float);
|
||||
|
||||
#endif
|
|
@ -1,15 +1,14 @@
|
|||
#ifndef NEOFX_TYPES_H
|
||||
#define NEOFX_TYPES_H
|
||||
|
||||
#pragma pack(push, 2)
|
||||
typedef union _MATRIX {
|
||||
float m[4][4];
|
||||
float f[16];
|
||||
} MATRIX;
|
||||
|
||||
typedef struct _VECTOR_VERTEX {
|
||||
typedef struct _VECTOR_VERTEX_ROTATION {
|
||||
float x, y, z;
|
||||
} VECTOR, VERTEX;
|
||||
} VECTOR, VERTEX, ROTATION;
|
||||
|
||||
typedef struct _TEXCOORDS {
|
||||
float s, t;
|
||||
|
@ -19,6 +18,13 @@ typedef struct _TRIANGLE {
|
|||
VERTEX vertices[3];
|
||||
VECTOR normal;
|
||||
} TRIANGLE;
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef struct _OBJECT {
|
||||
VERTEX pos;
|
||||
VECTOR move;
|
||||
ROTATION rot;
|
||||
float air_resistance;
|
||||
float bounce;
|
||||
} OBJECT;
|
||||
|
||||
#endif
|
||||
|
|
26
physics.c
Normal file
26
physics.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
#include <neofx/physics.h>
|
||||
#include <neofx/math.h>
|
||||
#include <math.h>
|
||||
|
||||
static VECTOR gravitation = {0, -9.8, 0};
|
||||
|
||||
|
||||
void SetGravitation(VECTOR v) {
|
||||
gravitation = v;
|
||||
}
|
||||
|
||||
void ApplyPhysics(OBJECT o, float delta) {
|
||||
VERTEX old_pos = o.pos;
|
||||
VECTOR old_move = o.move;
|
||||
float e;
|
||||
|
||||
e = expf(-o.air_resistance*delta);
|
||||
|
||||
o.move = VectorAdd(VectorMul(gravitation, 1/o.air_resistance),
|
||||
VectorMul(VectorSub(old_move, VectorMul(gravitation, 1/o.air_resistance)),
|
||||
e));
|
||||
|
||||
o.pos = VectorAdd(old_pos, VectorAdd(VectorMul(gravitation, delta/o.air_resistance),
|
||||
VectorMul(VectorSub(old_move, VectorMul(gravitation, 1/o.air_resistance)),
|
||||
(1-e)/o.air_resistance)));
|
||||
}
|
Reference in a new issue