[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog gui/Makefile.am libgeometry/Mak...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog gui/Makefile.am libgeometry/Mak... |
Date: |
Sat, 01 Dec 2007 23:21:49 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 07/12/01 23:21:49
Modified files:
. : ChangeLog
gui : Makefile.am
libgeometry : Makefile.am
server/asobj : Makefile.am
server/parser : Makefile.am
testsuite/libgeometry: Makefile.am
Removed files:
libgeometry : axial_box.cpp axial_box.h bsp.cpp bsp.h
collision.cpp collision.h cull.cpp cull.h
geometry.cpp geometry.h loose_octree.cpp
tqt.cpp tqt.h view_state.h visual.h
Log message:
drop libgnashgeo.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.5048&r2=1.5049
http://cvs.savannah.gnu.org/viewcvs/gnash/gui/Makefile.am?cvsroot=gnash&r1=1.113&r2=1.114
http://cvs.savannah.gnu.org/viewcvs/gnash/libgeometry/Makefile.am?cvsroot=gnash&r1=1.33&r2=1.34
http://cvs.savannah.gnu.org/viewcvs/gnash/libgeometry/axial_box.cpp?cvsroot=gnash&r1=1.3&r2=0
http://cvs.savannah.gnu.org/viewcvs/gnash/libgeometry/axial_box.h?cvsroot=gnash&r1=1.6&r2=0
http://cvs.savannah.gnu.org/viewcvs/gnash/libgeometry/bsp.cpp?cvsroot=gnash&r1=1.10&r2=0
http://cvs.savannah.gnu.org/viewcvs/gnash/libgeometry/bsp.h?cvsroot=gnash&r1=1.2&r2=0
http://cvs.savannah.gnu.org/viewcvs/gnash/libgeometry/collision.cpp?cvsroot=gnash&r1=1.11&r2=0
http://cvs.savannah.gnu.org/viewcvs/gnash/libgeometry/collision.h?cvsroot=gnash&r1=1.3&r2=0
http://cvs.savannah.gnu.org/viewcvs/gnash/libgeometry/cull.cpp?cvsroot=gnash&r1=1.8&r2=0
http://cvs.savannah.gnu.org/viewcvs/gnash/libgeometry/cull.h?cvsroot=gnash&r1=1.5&r2=0
http://cvs.savannah.gnu.org/viewcvs/gnash/libgeometry/geometry.cpp?cvsroot=gnash&r1=1.9&r2=0
http://cvs.savannah.gnu.org/viewcvs/gnash/libgeometry/geometry.h?cvsroot=gnash&r1=1.6&r2=0
http://cvs.savannah.gnu.org/viewcvs/gnash/libgeometry/loose_octree.cpp?cvsroot=gnash&r1=1.3&r2=0
http://cvs.savannah.gnu.org/viewcvs/gnash/libgeometry/tqt.cpp?cvsroot=gnash&r1=1.4&r2=0
http://cvs.savannah.gnu.org/viewcvs/gnash/libgeometry/tqt.h?cvsroot=gnash&r1=1.3&r2=0
http://cvs.savannah.gnu.org/viewcvs/gnash/libgeometry/view_state.h?cvsroot=gnash&r1=1.3&r2=0
http://cvs.savannah.gnu.org/viewcvs/gnash/libgeometry/visual.h?cvsroot=gnash&r1=1.2&r2=0
http://cvs.savannah.gnu.org/viewcvs/gnash/server/asobj/Makefile.am?cvsroot=gnash&r1=1.46&r2=1.47
http://cvs.savannah.gnu.org/viewcvs/gnash/server/parser/Makefile.am?cvsroot=gnash&r1=1.40&r2=1.41
http://cvs.savannah.gnu.org/viewcvs/gnash/testsuite/libgeometry/Makefile.am?cvsroot=gnash&r1=1.5&r2=1.6
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.5048
retrieving revision 1.5049
diff -u -b -r1.5048 -r1.5049
--- ChangeLog 1 Dec 2007 22:49:17 -0000 1.5048
+++ ChangeLog 1 Dec 2007 23:21:46 -0000 1.5049
@@ -1,3 +1,7 @@
+2007-12-01 Sandro Santilli <address@hidden>
+
+ * libgeometry: drop libgnashgeo.
+
2007-12-01 Bastiaan Jacques <address@hidden>
* backend/render_handler_tri.{cpp,h}: Remove these unused
Index: gui/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/gui/Makefile.am,v
retrieving revision 1.113
retrieving revision 1.114
diff -u -b -r1.113 -r1.114
--- gui/Makefile.am 28 Nov 2007 22:39:08 -0000 1.113
+++ gui/Makefile.am 1 Dec 2007 23:21:46 -0000 1.114
@@ -92,7 +92,6 @@
$(top_builddir)/libamf/libgnashamf.la \
$(top_builddir)/libmedia/libgnashmedia.la \
$(top_builddir)/server/libgnashserver.la \
- $(top_builddir)/libgeometry/libgnashgeo.la \
$(top_builddir)/libbase/libgnashbase.la
# Only build loadable modules unless statically linking
Index: libgeometry/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/libgeometry/Makefile.am,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -b -r1.33 -r1.34
--- libgeometry/Makefile.am 1 Dec 2007 22:11:24 -0000 1.33
+++ libgeometry/Makefile.am 1 Dec 2007 23:21:46 -0000 1.34
@@ -18,64 +18,12 @@
#
#
-# $Id: Makefile.am,v 1.33 2007/12/01 22:11:24 strk Exp $
+# $Id: Makefile.am,v 1.34 2007/12/01 23:21:46 strk Exp $
AUTOMAKE_OPTIONS =
-# AM_CXXFLAGS = $(CXXFLAGS) $(SDL_CFLAGS) $(AM_CPPFLAGS)
-# AM_CPPFLAGS = #-Wall
-# AM_LDFLAGS = $(OPENGL_LIBNS) $(SDL_LIBS)
-
-# noinst_LTLIBRARIES = libgeometry.la
-pkglib_LTLIBRARIES = libgnashgeo.la
-# noinst_LIBRARIES = libgeometry.a
-
-# These headers get installed
-# include_HEADERS = log.h err.h proc.h serial.h xantrex.h outback.h
-
-AM_CPPFLAGS = -I.. -I$(srcdir) \
- -I$(top_srcdir)/libbase \
- $(BOOST_CFLAGS) \
- $(PTHREAD_CFLAGS) \
- $(NULL)
-
-# -I$(top_srcdir) \
-# $(PTHREAD_CFLAGS) \
-# $(SDL_CFLAGS) \
-# $(OPENGL_CFLAGS) \
-#
-
-libgnashgeo_la_SOURCES = \
- axial_box.cpp \
- bsp.cpp \
- collision.cpp \
- cull.cpp \
- geometry.cpp \
- tqt.cpp
-
noinst_HEADERS = \
Range2d.h \
Point2d.h \
snappingrange.h \
- axial_box.h \
- bsp.h \
- collision.h \
- cull.h \
- geometry.h \
- tqt.h \
- view_state.h \
- visual.h
-
-#libgeometry_la_LIBDADD = address@hidden@ # $(LIBLTDL)
-libgnashgeo_la_LIBADD = $(top_builddir)/libbase/libgnashbase.la
-libgnashgeo_la_LDFLAGS = -release $(VERSION)
-
-
-# Rebuild with GCC 4.x Mudflap support
-mudflap:
- @echo "Rebuilding with GCC Mudflap support"
- $(MAKE) CXXFLAGS="$(CXXFLAGS) -fmudflap" LDFLAGS="$(LDFLAGS) -lmudflap"
-
-clean-hook:
- -rm -f core.*
-
+ axial_box.h
Index: server/asobj/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/server/asobj/Makefile.am,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -b -r1.46 -r1.47
--- server/asobj/Makefile.am 27 Sep 2007 23:59:56 -0000 1.46
+++ server/asobj/Makefile.am 1 Dec 2007 23:21:49 -0000 1.47
@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-# $Id: Makefile.am,v 1.46 2007/09/27 23:59:56 tgc Exp $
+# $Id: Makefile.am,v 1.47 2007/12/01 23:21:49 strk Exp $
AUTOMAKE_OPTIONS =
@@ -141,7 +141,6 @@
libgnashasobjs_la_LIBADD = \
$(top_builddir)/libamf/libgnashamf.la \
- $(top_builddir)/libgeometry/libgnashgeo.la \
$(top_builddir)/libbase/libgnashbase.la \
$(LIBXML_LIBS)
Index: server/parser/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/server/parser/Makefile.am,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -b -r1.40 -r1.41
--- server/parser/Makefile.am 27 Sep 2007 23:59:56 -0000 1.40
+++ server/parser/Makefile.am 1 Dec 2007 23:21:49 -0000 1.41
@@ -15,7 +15,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-# $Id: Makefile.am,v 1.40 2007/09/27 23:59:56 tgc Exp $
+# $Id: Makefile.am,v 1.41 2007/12/01 23:21:49 strk Exp $
AUTOMAKE_OPTIONS =
@@ -85,7 +85,6 @@
libgnashparser_la_LIBADD = \
$(top_builddir)/libamf/libgnashamf.la \
- $(top_builddir)/libgeometry/libgnashgeo.la \
$(top_builddir)/libbase/libgnashbase.la \
$(top_builddir)/libmedia/libgnashmedia.la
Index: testsuite/libgeometry/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/testsuite/libgeometry/Makefile.am,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- testsuite/libgeometry/Makefile.am 10 Nov 2007 09:46:54 -0000 1.5
+++ testsuite/libgeometry/Makefile.am 1 Dec 2007 23:21:49 -0000 1.6
@@ -22,7 +22,6 @@
AUTOMAKE_OPTIONS = dejagnu
AM_LDFLAGS = \
- $(top_builddir)/libgeometry/libgnashgeo.la \
$(NULL)
# AM_CPPFLAGS isn't right here since per-program *_CPPFLAGS override global
Index: libgeometry/axial_box.cpp
===================================================================
RCS file: libgeometry/axial_box.cpp
diff -N libgeometry/axial_box.cpp
--- libgeometry/axial_box.cpp 26 Feb 2006 15:49:30 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,69 +0,0 @@
-// axial_box.cpp -- by Thatcher Ulrich <address@hidden>
-
-// This source code has been donated to the Public Domain. Do
-// whatever you want with it.
-
-// Simple AABB structure
-
-
-#include "axial_box.h"
-#include "tu_random.h"
-#include "utility.h"
-
-
-vec3 axial_box::get_random_point() const
-// Return a random point inside this box.
-{
- return vec3(
- flerp(m_min[0], m_max[0], tu_random::get_unit_float()),
- flerp(m_min[1], m_max[1], tu_random::get_unit_float()),
- flerp(m_min[2], m_max[2], tu_random::get_unit_float()));
-}
-
-
-void axial_box::set_enclosing(const axial_box& a)
-// Ensure that the box encloses the box.
-{
- m_min.x = fmin(m_min.x, a.get_min().x);
- m_min.y = fmin(m_min.y, a.get_min().y);
- m_min.z = fmin(m_min.z, a.get_min().z);
- m_max.x = fmax(m_max.x, a.get_max().x);
- m_max.y = fmax(m_max.y, a.get_max().y);
- m_max.z = fmax(m_max.z, a.get_max().z);
-
- assert(is_valid());
-}
-
-
-int axial_box::get_longest_axis() const
-// Return axis with the largest size.
-{
- vec3 size = get_size();
- if (size.x > size.y)
- {
- if (size.x > size.z)
- {
- return 0; // x is longest
- }
- return 2; // z is longest
- }
- else
- {
- if (size.y > size.z)
- {
- return 1; // y is longest
- }
- else return 2; // z is longest
- }
-}
-
-
-
-
-
-// local Variables:
-// mode: C++
-// c-basic-offset: 8
-// tab-width: 8
-// indent-tabs-mode: t
-// End:
Index: libgeometry/axial_box.h
===================================================================
RCS file: libgeometry/axial_box.h
diff -N libgeometry/axial_box.h
--- libgeometry/axial_box.h 30 Aug 2006 14:03:37 -0000 1.6
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,265 +0,0 @@
-// axial_box.h -- by Thatcher Ulrich <address@hidden>
-
-// This source code has been donated to the Public Domain. Do
-// whatever you want with it.
-
-// simple AABB structure
-
-
-#ifndef AXIAL_BOX_H
-#define AXIAL_BOX_H
-
-
-#include "geometry.h"
-
-
-class axial_box
-{
-public:
- axial_box(); // zero box
- axial_box(const vec3& min, const vec3& max);
-
- enum invalid_ctor
- {
- INVALID
- };
- axial_box(invalid_ctor e, const vec3& min, const vec3& max);
-
- //
- // Getters
- //
-
- inline bool is_valid() const;
-
- vec3 get_center() const { return (m_min + m_max) * 0.5f; }
- vec3 get_extent() const { return (m_max - m_min) * 0.5f; }
- vec3 get_size() const { return m_max - m_min; }
-
- const vec3& get_min() const { return m_min; }
- const vec3& get_max() const { return m_max; }
-
- // Get one of the 8 corner verts.
- vec3 get_corner(int i) const;
-
- float get_surface_area() const;
-
- vec3 get_random_point() const;
-
- //
- // Setters
- //
-
- inline void set_min_max(const vec3& min, const vec3& max);
-
- // No validity check -- for intentionally setting an invalid box.
- inline void set_min_max_invalid(const vec3& min, const vec3& max);
-
- void set_center_extent(const vec3& center, const vec3& extent);
-
- // preserve center
- void set_extent(const vec3& extent);
-
- // preserve extent
- void set_center(const vec3& center);
-
- // adjust bounds along one axis.
- void set_axis_min(int axis, float new_min);
- void set_axis_max(int axis, float new_max);
-
- // Expand the box.
- void set_enclosing(const vec3& v);
- void set_enclosing(const axial_box& a);
-
- //
- // Etc
- //
-
- bool encloses(const vec3& v, float tolerance = 1e-6f) const;
- bool encloses(const axial_box& b, float tolerance = 1e-6f) const;
-
- // this = intersection(this, b)
- void set_intersection(const axial_box& b);
-
- int get_longest_axis() const;
-
-private:
- vec3 m_min, m_max;
-};
-
-
-inline axial_box::axial_box()
-// Construct a zero box.
-{
- m_min = vec3::zero;
- m_max = vec3::zero;
-
- assert(is_valid());
-}
-
-
-inline axial_box::axial_box(const vec3& min, const vec3& max)
-// Init from extremes.
-{
- set_min_max(min, max);
-}
-
-
-inline axial_box::axial_box(invalid_ctor /* e */, const vec3& min, const vec3&
max)
-// Init from extremes, don't check validity.
-{
- set_min_max_invalid(min, max);
-}
-
-
-inline bool axial_box::is_valid() const
-// Return true if we're OK.
-{
- return
- m_min.x <= m_max.x
- && m_min.y <= m_max.y
- && m_min.z <= m_max.z;
-}
-
-
-inline vec3 axial_box::get_corner(int i) const
-{
- assert(is_valid());
- assert(i >= 0 && i < 8);
-
- return vec3(
- i & 1 ? m_min.x : m_max.x,
- i & 2 ? m_min.y : m_max.y,
- i & 4 ? m_min.z : m_max.z);
-}
-
-
-inline float axial_box::get_surface_area() const
-{
- assert(is_valid());
-
- vec3 sides(m_max);
- sides -= m_min;
-
- return
- (sides.x * sides.y
- + sides.x * sides.z
- + sides.y * sides.z) * 2;
-}
-
-
-inline void axial_box::set_min_max(const vec3& min, const vec3& max)
-{
- m_min = min;
- m_max = max;
-
- assert(is_valid());
-}
-
-
-inline void axial_box::set_min_max_invalid(const vec3& min, const vec3& max)
-// Don't check validity.
-{
- m_min = min;
- m_max = max;
-}
-
-
-inline void axial_box::set_center_extent(const vec3& center, const vec3&
extent)
-{
- set_min_max(center - extent, center + extent);
-}
-
-
-inline void axial_box::set_extent(const vec3& extent)
-{
- set_center_extent(get_center(), extent);
-}
-
-
-inline void axial_box::set_center(const vec3& center)
-{
- set_center_extent(center, get_extent());
-}
-
-
-inline void axial_box::set_axis_min(int axis, float new_min)
-{
- assert(is_valid());
-
- m_min.set(axis, new_min);
-
- assert(is_valid());
-}
-
-
-inline void axial_box::set_axis_max(int axis, float new_max)
-{
- assert(is_valid());
-
- m_max.set(axis, new_max);
-
- assert(is_valid());
-}
-
-
-// @@ should probably un-inline this...
-inline void axial_box::set_enclosing(const vec3& v)
-// Ensure that the box encloses the point.
-{
- m_min.x = fmin(m_min.x, v.x);
- m_min.y = fmin(m_min.y, v.y);
- m_min.z = fmin(m_min.z, v.z);
- m_max.x = fmax(m_max.x, v.x);
- m_max.y = fmax(m_max.y, v.y);
- m_max.z = fmax(m_max.z, v.z);
-
- assert(is_valid());
-}
-
-
-inline bool axial_box::encloses(const vec3& v, float tolerance) const
-// Return true if the given point is inside this box.
-{
- assert(is_valid());
-
- return
- m_min.x <= v.x + tolerance
- && m_min.y <= v.y + tolerance
- && m_min.z <= v.z + tolerance
- && m_max.x >= v.x - tolerance
- && m_max.y >= v.y - tolerance
- && m_max.z >= v.z - tolerance;
-}
-
-
-inline bool axial_box::encloses(const axial_box& b, float tolerance) const
-// Return true if this box encloses the given box.
-{
- assert(is_valid());
-
- return encloses(b.m_min, tolerance) && encloses(b.m_max, tolerance);
-}
-
-
-inline void axial_box::set_intersection(const axial_box& b)
-// Set this to intersection(this, b)
-{
- if (b.m_min.x > m_min.x) m_min.x = b.m_min.x;
- if (b.m_min.y > m_min.y) m_min.y = b.m_min.y;
- if (b.m_min.z > m_min.z) m_min.z = b.m_min.z;
-
- if (b.m_max.x < m_max.x) m_max.x = b.m_max.x;
- if (b.m_max.y < m_max.y) m_max.y = b.m_max.y;
- if (b.m_max.z < m_max.z) m_max.z = b.m_max.z;
-}
-
-
-#endif // AXIAL_BOX_H
-
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 8
-// tab-width: 8
-// indent-tabs-mode: t
-// End:
Index: libgeometry/bsp.cpp
===================================================================
RCS file: libgeometry/bsp.cpp
diff -N libgeometry/bsp.cpp
--- libgeometry/bsp.cpp 30 Oct 2007 18:55:41 -0000 1.10
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,451 +0,0 @@
-// bsp.cpp -- by Thatcher Ulrich <address@hidden> 2001
-
-// This code is in the public domain.
-
-// Code to make a collision-bsp tree out of triangle soup.
-
-#include <cstdio>
-#include <cmath>
-
-#ifdef HAVE_MALLOC_H
- #include <malloc.h>
-#else
- #include <cstdlib>
-#endif
-
-using namespace std;
-
-#include "utility.h"
-#include "bsp.h"
-
-const bool print_debug = 0;
-
-/*
-sort faces by size? Or order them randomly?;
-make root bsp node w/ the first face;
-for rest of faces {
- root->add_face( a, b, c, plane( normal, d ) );
-}
-*/
-
-
-enum plane_class {
- INSIDE = -1,
- ON = 0,
- OUTSIDE = 1
-};
-
-
-////const float BSP_SLOP = 1.1923435f;
-//const float BSP_SLOP = 0.1f;
-
-plane_class classify_point( const plane_info& p, vec3 a, float slop )
-// Classify the given point with respect to the given plane; use a tolerance
-// of +/- slop to determine when a point is ON the plane.
-{
- float distance = p.normal * a - p.d;
-
- if ( distance < -slop ) {
- return INSIDE;
- } else if ( distance > slop ) {
- if ( print_debug ) {
- printf( "d = %f, pn = %f %f %f, pd = %f, a = %f %f %f,
p*a = %f\n",
- distance, p.normal.get_x(),
p.normal.get_y(), p.normal.get_z(), p.d,
- a.get_x(), a.get_y(), a.get_z(),
- p.normal * a
- ); //xxxx
- }
- return OUTSIDE;
- } else {
- return ON;
- }
-}
-
-
-vec3 intersect( const plane_info& p, const vec3& a, const vec3& b )
-// Returns the point of intersection between the plane p and the
-// line segment defined by a and b.
-//
-// NB: does not check to ensure that a & b intersects p!
-{
- float da = p.normal * a - p.d;
- float db = p.normal * b - p.d;
-
- float diff = db - da;
-
- if ( fabs( diff ) < 0.000001f ) {
- // Segment is parallel to plane. Just pick the midpoint of
- // the segment as the intersection point.
- return ( a + b ) * 0.5f;
-
- } else {
- // Compute how far along the segment the intersection is.
- float f = ( 0 - da ) / diff;
-// printf( "f = %f\n", f );//xxxxx
- return a + ( b - a ) * f;
- }
-}
-
-
-bsp_node::bsp_node( const plane_info& p )
-// Constructor. Make a root node using the given plane info.
-{
- m_plane = p;
- m_inside = m_outside = 0;
- m_partitioning_plane = true;
-
- m_face_list = 0;
- m_face_count = 0;
-}
-
-
-bsp_node::~bsp_node()
-// Destructor. Delete our child trees recursively.
-{
- if ( m_inside ) {
- delete m_inside;
- }
- if ( m_outside ) {
- delete m_outside;
- }
- if ( m_face_list ) {
- free( m_face_list ); // using malloc/free because of
realloc...
- }
-}
-
-
-void bsp_node::add_partition( const plane_info& p )
-// Add a partitioning plane to this bsp tree. Basically propagates
-// the plane and adds it to all leaf nodes.
-//
-// NB: VERY IMPORTANT: You must add partitioning planes before adding
-// faces. Otherwise volume queries will be wrong.
-{
- if ( m_partitioning_plane != true ) {
- abort();
- // Trying to add a partitioning plane to a tree that already
- // contains faces. Refuse to add the plane.
- return;
- }
-
- if ( m_inside ) {
- m_inside->add_partition( p );
- } else {
- m_inside = new bsp_node( p );
- }
-
- if ( m_outside ) {
- m_outside->add_partition( p );
- } else {
- m_outside = new bsp_node( p );
- }
-}
-
-
-void bsp_node::add_face( const vec3& a, const vec3& b, const vec3& c, const
plane_info& p, int face_index, float slop )
-// Inserts the given triangle into this node's bsp tree. face_index
-// is a reference to the original face, which is passed back during
-// ray_cast() if the caller gives a pointer to a face_test_callback
-// function.
-//
-// The slop parameter determines how far a vertex may be from a
-// splitting plane and still be considered "on" the plane.
-//
-// @@ slop could possibly be replaced by using a fraction of the
-// longest face edge length.
-{
- // Classify the three verts of the triangle w/r/t this node's plane.
- plane_class ca = classify_point( m_plane, a, slop );
- plane_class cb = classify_point( m_plane, b, slop );
- plane_class cc = classify_point( m_plane, c, slop );
-
- if ( print_debug ) {
-//x printf( "ca = %d, cb = %d, cc = %d\n", ca, cb, cc );//xxx
- }
-
- if ( ca == ON && cb == ON && cc == ON ) {
- // All points are in this node's plane.
-
- if ( p.normal * m_plane.normal < 0 ) {
- // Face's plane and our node plane are opposite each
other.
- // Add the face on the outside of this plane.
- add_outside_face( a, b, c, p, face_index, slop );
- } else {
- // This face fits in this node. Add the face index to
our list.
- if ( print_debug ) printf( "o\n" );//xxxxx
-
- insert_into_face_list( face_index );
- }
- return;
-
- } else if ( ( ca && cb && ( ca != cb ) )
- || ( cb && cc && ( cb != cc ) )
- || ( cc && ca && ( cc != ca ) ) )
- {
-// printf( "*\n" );
-// return; //xxxxxxxx
-
- // This triangle straddles the plane.
-
- // Make references to the verts, so we can sort them.
- const vec3* pa = &a;
- const vec3* pb = &b;
- const vec3* pc = &c;
-
- // Sort the vert references so that *pa is the most inside, and
*pc is the most outside.
- const vec3* t;
- plane_class ct;
- if ( ca > cb ) {
- t = pa; pa = pb; pb = t; // swap( &a, &b );
- ct = ca; ca = cb; cb = ct;
- }
- if ( cb > cc ) {
- t = pb; pb = pc; pc = t; // swap( &b, &c );
- ct = cb; cb = cc; cc = ct;
- }
- if ( ca > cb ) {
- t = pa; pa = pb; pb = t; // swap( &a, &b );
- ct = ca; ca = cb; cb = ct;
- }
-
- if ( cb == INSIDE ) {
- if ( print_debug ) printf( "^" );//xxxx
-
- // a and b are INSIDE the plane, c is OUTSIDE.
- vec3 d = intersect( m_plane, *pa, *pc );
- vec3 e = intersect( m_plane, *pb, *pc );
-
- add_inside_face( *pa, *pb, d, p, face_index, slop );
- add_inside_face( *pb, d, e, p, face_index, slop );
- add_outside_face( d, e, *pc, p, face_index, slop );
-
- } else if ( cb == ON ) {
- if ( print_debug ) printf( "<" );//xxxx
-
- // a is INSIDE, b is ON, c is OUTSIDE.
- vec3 d = intersect( m_plane, *pa, *pc );
-
- add_inside_face( *pa, *pb, d, p, face_index, slop );
- add_outside_face( *pb, d, *pc, p, face_index, slop );
-
- } else {
- if ( print_debug ) printf( "V: " );//xxxx
-
- // a is INSIDE, b and c are OUTSIDE.
- vec3 d = intersect( m_plane, *pa, *pb );
- vec3 e = intersect( m_plane, *pa, *pc );
-
- add_inside_face( *pa, d, e, p, face_index, slop );
- add_outside_face( d, e, *pb, p, face_index, slop );
- add_outside_face( e, *pb, *pc, p, face_index, slop );
- }
-
- } else {
- // This triangle is fully on one side of the plane or the other.
- if ( ca == INSIDE || cb == INSIDE || cc == INSIDE ) {
- add_inside_face( a, b, c, p, face_index, slop );
-
- } else {
- add_outside_face( a, b, c, p, face_index, slop );
- }
- }
-}
-
-
-void bsp_node::add_inside_face( const vec3& a, const vec3& b, const vec3& c,
const plane_info& p, int face_index, float slop )
-// Adds the given triangle with the specified plane info to the inside
-// half of this node. Creates a new inside node if necessary.
-{
- if ( print_debug ) printf( "/" );//xxxx
- if ( m_inside ) {
- m_inside->add_face( a, b, c, p, face_index, slop );
- } else {
- if ( print_debug ) printf( "x\n" );//xxxxx
- m_inside = new bsp_node( p );
- m_inside->insert_into_face_list( face_index );
- }
-}
-
-
-void bsp_node::add_outside_face( const vec3& a, const vec3& b, const vec3&
c, const plane_info& p, int face_index, float slop )
-// Adds the given triangle with the specified plane info to the outside
-// half-space of this node. Creates a new outside node if necessary.
-{
- if ( print_debug ) printf( "\\" );//xxxx
- if ( m_outside ) {
- m_outside->add_face( a, b, c, p, face_index, slop );
- } else {
- if ( print_debug ) printf( "y\n" );//xxxxx
- m_outside = new bsp_node( p );
- m_outside->insert_into_face_list( face_index );
- }
-}
-
-
-void bsp_node::insert_into_face_list( int face_index )
-// Adds the given face index into our array of face lists.
-{
- m_face_count++;
-
- // Make storage for the new face index.
- if ( m_face_list ) {
- m_face_list = (int*) realloc( m_face_list, m_face_count *
sizeof( face_index ) );
- } else {
- m_face_list = (int*) malloc( m_face_count * sizeof( face_index
) );
- }
-
- m_face_list[ m_face_count - 1 ] = face_index;
-
- // Mark this node as having geometry.
- m_partitioning_plane = false;
-}
-
-
-bool bsp_node::ray_cast( collision_info* result, const vec3& p0, const vec3&
dir, float distance, bool (*face_test_callback)( const vec3& normal, const
vec3& pt, int face_index ) )
-// Cast the specified ray through this BSP tree. Finds the nearest
-// hit, if any. If a hit is found, the results are put in *result and
-// returns true; otherwise returns false and leaves *result alone.
-//
-// If face_test_callback is not null, then use it to verify hits.
-// This function will call face_test_callback() with candidate
-// intersection points and a face_index. The candidate point is
-// guaranteed to be in the plane of the face, so the callback just
-// needs to determine if the point is within the triangle, and return
-// true if it is.
-{
- float dot = dir * m_plane.normal;
-
- float d0 = p0 * m_plane.normal - m_plane.d;
- float delta_n = dot * distance;
- float d1 = d0 + delta_n;
-
- bool parallel = fabs( dot ) < 0.000001f;
-
-// printf( "%f %f %f %f\n", d0, d1, dot, distance ); //xxxxx
-
- if ( parallel == false ) {
- // The ray might cross our plane.
-
- float hit_distance = -d0 / dot;
-// printf( "hd = %f\n", hit_distance );//xxxxx
-
- if ( d0 > 0 && d1 <= 0 ) {
- //
- // Ray crosses from the outside to the inside of this
half-space.
- //
-// printf( "+" ); //xxxxxx
-
- // Check the first half of the ray against the outside.
- if ( m_outside
- && m_outside->ray_cast( result, p0, dir,
hit_distance, face_test_callback ) )
- {
- return true;
- }
-
- vec3 hit_point = p0 + dir * hit_distance;
-
- if ( m_partitioning_plane == false ) {
- // If the crossing point is on the inside of
our inside
- // tree, then we have a potential hit.
-// if ( m_inside == 0
-// || m_inside->test_point( hit_point ) )
-// {
- // Check the faces for a hit.
- int i;
- for ( i = 0; i < m_face_count; i++ ) {
- if ( face_test_callback == 0
- || face_test_callback(
m_plane.normal, hit_point, m_face_list[ i ] ) )
- {
- result->point =
hit_point;
- result->normal =
m_plane.normal;
- // get face properties
from callback?
- return true;
- }
- }
-// }
- }
-
- // No hits so far... check the inside portion of the
ray.
- return m_inside &&
- m_inside->ray_cast( result, hit_point, dir,
distance - hit_distance, face_test_callback );
- }
-
- if ( d0 <= 0 && d1 > 0 ) {
- //
- // Ray crosses from the inside to the outside of this
half-space.
- //
-
- // Check the first half of the ray against the inside.
- if ( m_inside
- && m_inside->ray_cast( result, p0, dir,
hit_distance, face_test_callback ) )
- {
- return true;
- }
-
- vec3 hit_point = p0 + dir * hit_distance;
-
- // If no hit, check the second half against the outside.
- return m_outside
- && m_outside->ray_cast( result, hit_point, dir,
distance - hit_distance, face_test_callback );
- }
- }
-
- //
- // Ray does not cross our plane. Check which side of the plane
- // the ray is on, and only check that side.
- //
-
-// printf( "O\n" ); //xxxx
-
- if ( d0 <= 0 ) {
-// printf( "/" );//xxx
- return m_inside
- && m_inside->ray_cast( result, p0, dir, distance,
face_test_callback );
- } else {
-// printf( "\\" );//xxx
- return m_outside
- && m_outside->ray_cast( result, p0, dir, distance,
face_test_callback );
- }
-}
-
-
-bool bsp_node::test_point( const vec3& a )
-// Return true if the given point is inside our volume; false otherwise.
-{
- float d = m_plane.normal * a - m_plane.d;
-
- if ( d <= 0 ) {
- // Point is inside this node.
-
- if ( m_inside == 0 && m_partitioning_plane == true ) {
- // Point is in an empty partitioning volume. Assume
we're
- // outside any volume.
- //
- // @@ This is not strictly correct, because we could be
- // inside a volume defined by faces which entirely
enclose
- // the partitioning volume, without intersecting it.
Such
- // volumes will have hollow cells inside them defined by
- // the partitioning planes. However, this shouldn't be
a
- // practical problem for ray tracing, because valid test
- // points will be on a real volume plane.
- //
- // There is one potential failure case: if a ray hits a
- // big volume very near a point where the corner or edge
- // of an internal partitioning volume touches the big
- // volume, it's conceivable that the raycast will miss
due
- // to the test_point() call returning false for that
- // point. Hm. One solution would be to mark leaf
- // partitioning planes that are inside such volumes with
- // an "inside" flag; in which case we'd return "true"
- // here, and everything would be hunky-dory.
- return false;
- }
-
- return m_inside == 0
- || m_inside->test_point( a );
- } else {
- // Point is on the outside of this node...
- return m_outside
- && m_outside->test_point( a );
- }
-}
Index: libgeometry/bsp.h
===================================================================
RCS file: libgeometry/bsp.h
diff -N libgeometry/bsp.h
--- libgeometry/bsp.h 1 Feb 2006 23:58:32 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,46 +0,0 @@
-// bsp.h -- by Thatcher Ulrich <address@hidden> 2001
-
-// This code is in the public domain.
-
-// Code to make a collision-bsp tree out of triangle soup.
-
-
-#ifndef BSP_H
-#define BSP_H
-
-
-#include "geometry.h"
-
-
-class bsp_node {
-// Class for representing polygonal volumes using a bsp tree. Can
-// build a tree using the constructor and bsp_node::add_face(). Can
-// test points and rays against the resulting volume.
-public:
- bsp_node( const plane_info& p );
- ~bsp_node();
-
- void add_face( const vec3& a, const vec3& b, const vec3& c, const
plane_info& p, int face_index, float plane_slop = 0.001f );
- void add_partition( const plane_info& p );
-
- bool ray_cast( collision_info* result, const vec3& p0, const vec3&
dir, float distance, bool (*face_test_callback)( const vec3& normal, const
vec3& pt, int face_index ) );
- bool test_point( const vec3& a );
-
- // need some utility functions for setting the child nodes?
-
-private:
- void add_inside_face( const vec3& a, const vec3& b, const vec3& c,
const plane_info& p, int face_index, float slop );
- void add_outside_face( const vec3& a, const vec3& b, const vec3& c,
const plane_info& p, int face_index, float slop );
- void insert_into_face_list( int face_index );
-
- plane_info m_plane;
- bsp_node* m_inside;
- bsp_node* m_outside;
- bool m_partitioning_plane; // true if this plane is strictly for
partitioning; i.e. has no faces associated with it.
-
- int* m_face_list;
- int m_face_count;
-};
-
-
-#endif // BSP_H
Index: libgeometry/collision.cpp
===================================================================
RCS file: libgeometry/collision.cpp
diff -N libgeometry/collision.cpp
--- libgeometry/collision.cpp 10 Feb 2007 18:33:03 -0000 1.11
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,93 +0,0 @@
-// collision.cpp -- by Thatcher Ulrich <address@hidden>
-
-// This source code has been donated to the Public Domain. Do
-// whatever you want with it.
-
-// Misc helper code for doing collision tests.
-
-/* $Id: collision.cpp,v 1.11 2007/02/10 18:33:03 nihilus Exp $ */
-
-#include <cfloat>
-
-#include "collision.h"
-
-using namespace std;
-
-ray_query::ray_query(const vec3& start_pos, const vec3& unit_direction, float
distance)
- :
- m_start(start_pos),
- m_end(start_pos + unit_direction * distance),
- m_dir(unit_direction),
- m_length(distance)
-{
- assert(m_length > 0);
-
- compute_inverses();
-}
-
-
-ray_query::ray_query(start_end_enum /* e */, const vec3& start_pos, const
vec3& end_pos)
- :
- m_start(start_pos),
- m_end(end_pos)
-{
- vec3 disp = m_end - m_start;
- m_length = disp.magnitude();
- assert(m_length > 0);
-
- if (m_length > 0)
- {
- m_dir = disp;
- m_dir /= m_length;
- }
-
- compute_inverses();
-}
-
-
-void ray_query::compute_inverses()
-// Compute m_inv_dir and m_inv_displacement
-{
- vec3 disp(m_end);
- disp -= m_start;
-
- // Threshold, below which we don't want to compute 1/x.
- static const float DANGER_LIMIT_MIN = 1e-25f;
-
- for (int i = 0; i < 3; i++)
- {
- // m_inv_dir
- float comp = m_dir[i];
- if (fabsf(comp) <= DANGER_LIMIT_MIN)
- {
- m_inv_dir[i] = -FLT_MAX; // arbitrary crap
- m_dir[i] = 0; // don't tolerate tiny tiny component.
Client code will know not to use this axis.
- }
- else
- {
- m_inv_dir[i] = 1.0f / comp;
- }
-
- // m_inv_displacement
- comp = disp[i];
- if (fabsf(comp) <= DANGER_LIMIT_MIN)
- {
- m_inv_displacement[i] = -FLT_MAX; // arbitrary
crap
- m_dir[i] = 0; // don't tolerate tiny tiny component.
Client code will know not to use this axis.
- }
- else
- {
- m_inv_displacement[i] = 1.0f / comp;
- }
- }
-}
-
-
-
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 8
-// tab-width: 8
-// indent-tabs-mode: t
-// End:
Index: libgeometry/collision.h
===================================================================
RCS file: libgeometry/collision.h
diff -N libgeometry/collision.h
--- libgeometry/collision.h 26 Feb 2006 15:49:30 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,45 +0,0 @@
-// collision.h -- by Thatcher Ulrich <address@hidden>
-
-// This source code has been donated to the Public Domain. Do
-// whatever you want with it.
-
-// Basic types needed for doing collision queries.
-
-
-#ifndef COLLISION_H
-#define COLLISION_H
-
-
-#include "geometry.h"
-
-
-// Actually a line-segment query.
-struct ray_query
-{
- ray_query(const vec3& start_pos, const vec3& unit_direction, float
distance);
-
- enum start_end_enum { start_end };
- ray_query(start_end_enum e, const vec3& start_pos, const vec3& end_pos);
-
- // Internal helper to compute m_inv_*
- void compute_inverses();
-
- vec3 m_start;
- vec3 m_end;
- vec3 m_dir;
- vec3 m_inv_dir; // 1/x for each component of m_dir
- vec3 m_inv_displacement; // 1/x for each component of (m_end -
m_start)
- float m_length;
-};
-
-
-#endif // COLLISION_H
-
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 8
-// tab-width: 8
-// indent-tabs-mode: t
-// End:
-
Index: libgeometry/cull.cpp
===================================================================
RCS file: libgeometry/cull.cpp
diff -N libgeometry/cull.cpp
--- libgeometry/cull.cpp 10 Feb 2007 18:40:20 -0000 1.8
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,63 +0,0 @@
-// cull.cpp -- by Thatcher Ulrich <address@hidden> 16 June 2001
-
-// This source code has been donated to the Public Domain.
-
-
-#include "cull.h"
-#include "tu_math.h"
-#include "utility.h"
-
-using namespace std;
-
-namespace cull {
-
-
-result_info compute_box_visibility(const vec3& center, const vec3& extent,
const plane_info frustum[6], result_info in)
-// Returns a visibility code indicating the culling status of the
-// given axis-aligned box. The result_info passed in should indicate
-// which planes might cull the box, by setting the corresponding
-// bit in in.active_planes.
-{
-// if (in.culled) return in; // This check should be done by caller.
-
- // Check the box against each active frustum plane.
- int bit = 1;
- for (int i = 0; i < 6; i++, bit <<= 1) {
- if ((bit & in.active_planes) == 0) {
- // This plane is already known to not cull the box.
- continue;
- }
-
- const plane_info& p = frustum[i];
- // Check box against this plane.
- float d = p.normal * center - p.d;
- float extent_toward_plane = fabsf(extent.get_x() *
p.normal.get_x())
- + fabsf(extent.get_y() * p.normal.get_y())
- + fabsf(extent.get_z() * p.normal.get_z());
- if (d < 0) {
- if (-d > extent_toward_plane) {
- // Box is culled by plane; it's not visible.
- return result_info(true, 0);
- } // else this plane is ambiguous so leave it active.
- } else {
- if (d > extent_toward_plane) {
- // Box is accepted by this plane, so
- // deactivate it, since neither this
- // box or any contained part of it can
- // ever be culled by this plane.
- in.active_planes &= ~bit;
- if (in.active_planes == 0) {
- // This box is definitively inside all
the culling
- // planes, so there's no need to
continue.
- return in;
- }
- } // else this plane is ambigious so leave it active.
- }
- }
-
- return in; // Box not definitively culled. Return updated active
plane flags.
-}
-
-
-} // end namespace cull
-
Index: libgeometry/cull.h
===================================================================
RCS file: libgeometry/cull.h
diff -N libgeometry/cull.h
--- libgeometry/cull.h 26 Aug 2006 18:45:50 -0000 1.5
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,32 +0,0 @@
-// cull.h -- by Thatcher Ulrich <address@hidden> 16 June 2001
-
-// This source code has been donated to the Public Domain. Do
-// whatever you want with it.
-
-// Routines for frustum culling.
-
-
-#ifndef CULL_H
-#define CULL_H
-
-
-#include "geometry.h"
-
-
-namespace cull {
-
- class result_info {
- public:
- bool culled; // true when the volume is not visible
- uint8_t active_planes; // one bit per frustum plane
-
- result_info(bool c = false, uint8_t a = 0x3f) : culled(c),
active_planes(a) {}
- };
-
-
- result_info compute_box_visibility(const vec3& center, const vec3&
extent,
- const plane_info frustum[6],
result_info in);
-}
-
-
-#endif // CULL_H
Index: libgeometry/geometry.cpp
===================================================================
RCS file: libgeometry/geometry.cpp
diff -N libgeometry/geometry.cpp
--- libgeometry/geometry.cpp 11 Apr 2007 17:54:21 -0000 1.9
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,645 +0,0 @@
-// geometry.cpp -- address@hidden Copyright 1998 Thatcher Ulrich
-
-// Implementations for the basic geometric types.
-
-
-#include "tu_math.h"
-#include <cfloat>
-#include "geometry.h"
-#include "tu_file.h"
-
-using namespace std;
-
-const vec3 vec3::zero(0, 0, 0);
-const vec3 vec3::x_axis(1, 0, 0);
-const vec3 vec3::y_axis(0, 1, 0);
-const vec3 vec3::z_axis(0, 0, 1);
-const vec3 vec3::flt_max(FLT_MAX, FLT_MAX, FLT_MAX);
-const vec3 vec3::minus_flt_max(-FLT_MAX, -FLT_MAX, -FLT_MAX);
-
-
-vec3 vec3::operator+(const vec3& v) const
-// Adds two vec3s. Creates a temporary for the return value.
-{
- vec3 result;
- result.x = x + v.x;
- result.y = y + v.y;
- result.z = z + v.z;
- return result;
-}
-
-
-vec3 vec3::operator-(const vec3& v) const
-// Subtracts two vectors. Creates a temporary for the return value.
-{
- vec3 result;
- result.x = x - v.x;
- result.y = y - v.y;
- result.z = z - v.z;
- return result;
-}
-
-
-vec3 vec3::operator-() const
-// Returns the negative of *this. Creates a temporary for the return value.
-{
- vec3 result;
- result.x = -x;
- result.y = -y;
- result.z = -z;
- return result;
-}
-
-
-#ifndef INLINE_VEC3
-
-
-float vec3::operator*(const vec3& v) const
-// Dot product.
-{
- float result;
- result = x * v.x;
- result += y * v.y;
- result += z * v.z;
- return result;
-}
-
-
-vec3& vec3::operator+=(const vec3& v)
-// Adds a vec3 to *this.
-{
- x += v.x;
- y += v.y;
- z += v.z;
- return *this;
-}
-
-
-vec3& vec3::operator-=(const vec3& v)
-// Subtracts a vec3 from *this.
-{
- x -= v.x;
- y -= v.y;
- z -= v.z;
- return *this;
-}
-
-
-void vec3::set_cross(const vec3& a, const vec3& b) const
-// Cross product.
-{
- assert(this != &a);
- assert(this != &b);
-
- x = a.y * b.z - a.z * b.y;
- y = a.z * b.x - a.x * b.z;
- z = a.x * b.y - a.y * b.x;
-}
-
-
-#endif // INLINE_VEC3
-
-
-vec3 vec3::operator*(float f) const
-// Scale a vec3 by a scalar. Creates a temporary for the return value.
-{
- vec3 result;
- result.x = x * f;
- result.y = y * f;
- result.z = z * f;
- return result;
-}
-
-
-vec3 vec3::cross(const vec3& v) const
-// Cross product. Creates a temporary for the return value.
-{
- vec3 result;
- result.set_cross(*this, v);
- return result;
-}
-
-
-float vec3::normalize(const vec3& fallback /* = vec3::x_axis */)
-// Scales the vec3 to unit length. Preserves its direction. Returns
-// the original length of the vector. If the length was (effectively)
-// zero, then returns 0.0f and sets our value to fallback.
-{
- float f = magnitude();
- if (f < 0.0000001) {
- // Punt.
- *this = fallback;
- return 0.0f;
- } else {
- this->operator/=(f);
- }
- return f;
-}
-
-
-vec3& vec3::operator*=(float f)
-// Scales *this by the given scalar.
-{
- x *= f;
- y *= f;
- z *= f;
- return *this;
-}
-
-
-float vec3::magnitude() const
-// Returns the length of *this.
-{
- return sqrtf(sqrmag());
-}
-
-
-float vec3::sqrmag() const
-// Returns the square of the length of *this.
-{
- return x * x + y * y + z * z;
-}
-
-
-void vec3::read(tu_file* in)
-// Read our values from the given stream.
-{
- x = in->read_float32();
- y = in->read_float32();
- z = in->read_float32();
-}
-
-
-void vec3::write(tu_file* out)
-// Write our contents to the given stream.
-{
- out->write_float32(x);
- out->write_float32(y);
- out->write_float32(z);
-}
-
-
-bool vec3::checknan() const
-// Returns true if any component is nan.
-{
- if (x != x || y != y || z != z) {
-// if (fabs(x) > 10000000 || fabs(y) > 10000000 || fabs(z) > 10000000) {
- return true;//xxxxxxx
- }
-// if (_isnan(m[0]) || _isnan(m[1]) || _isnan(m[2])) {
-// return true;
-// }
- else return false;
-}
-
-
-// class matrix
-
-
-void matrix::set_identity()
-// Sets *this to be an identity matrix.
-{
- set_column(0, vec3::x_axis);
- set_column(1, vec3::y_axis);
- set_column(2, vec3::z_axis);
- set_column(3, vec3::zero);
-}
-
-
-void matrix::set_view(const vec3& ViewNormal, const vec3& ViewUp, const
vec3& ViewLocation)
-// Turns *this into a view matrix, given the direction the camera is
-// looking (ViewNormal) and the camera's up vec3 (ViewUp), and its
-// location (ViewLocation) (all vec3s in world-coordinates). The
-// resulting matrix will transform points from world coordinates to view
-// coordinates, which is a right-handed system with the x axis pointing
-// left, the y axis pointing up, and the z axis pointing into the scene.
-{
- vec3 ViewX = ViewUp.cross(ViewNormal);
-
- // Construct the view-to-world matrix.
- set_orient(ViewX, ViewUp, ViewLocation);
-
- // Turn it around, to make it world-to-view.
- invert();
-}
-
-
-void matrix::set_orient(const vec3& Direction, const vec3& Up, const vec3&
Location)
-// Turns *this into a transformation matrix, that transforms vec3s
-// from object coordinates to world coordinates, given the object's Direction,
Up,
-// and Location in world coordinates.
-{
- vec3 ZAxis = Direction.cross(Up);
-
- set_column(0, Direction);
- set_column(1, Up);
- set_column(2, ZAxis);
- set_column(3, Location);
-}
-
-
-vec3 matrix::operator*(const vec3& v) const
-// Applies *this to the given vec3, and returns the transformed vec3.
-{
- vec3 result;
- apply(&result, v);
- return result;
-}
-
-
-matrix matrix::operator*(const matrix& a) const
-// Composes the two matrices, returns the product. Creates a temporary
-// for the return value.
-{
- matrix result;
-
- compose(&result, *this, a);
-
- return result;
-}
-
-
-void matrix::compose(matrix* dest, const matrix& left, const matrix& right)
-// Multiplies left * right, and puts the result in *dest.
-{
- left.apply_rotation(&const_cast<vec3&>(dest->get_column(0)),
right.get_column(0));
- left.apply_rotation(&const_cast<vec3&>(dest->get_column(1)),
right.get_column(1));
- left.apply_rotation(&const_cast<vec3&>(dest->get_column(2)),
right.get_column(2));
- left.apply(&const_cast<vec3&>(dest->get_column(3)),
right.get_column(3));
-}
-
-
-matrix& matrix::operator*=(float f)
-// Scalar multiply of a matrix.
-{
- for(int i = 0; i < 4; i++) m[i] *= f;
- return *this;
-}
-
-
-matrix& matrix::operator+=(const matrix& mat)
-// Memberwise matrix addition.
-{
- for(int i = 0; i < 4; i++) m[i] += mat.m[i];
- return *this;
-}
-
-
-void matrix::invert()
-// Inverts *this. Uses transpose property of rotation matrices.
-{
- invert_rotation();
-
- // Compute the translation part of the inverted matrix, by applying
- // the inverse rotation to the original translation.
- vec3 TransPrime;
- apply_rotation(&TransPrime, get_column(3));
-
- set_column(3, -TransPrime); // Could optimize the negation by doing
it in-place.
-}
-
-
-void matrix::invert_rotation()
-// Inverts the rotation part of *this. Ignores the translation.
-// Uses the transpose property of rotation matrices.
-{
- // Swap elements across the diagonal.
- float f = m[1].get(0);
- m[1].set(0, m[0].get(1));
- m[0].set(1, f);
-
- f = m[2].get(0);
- m[2].set(0, m[0].get(2));
- m[0].set(2, f);
-
- f = m[2].get(1);
- m[2].set(1, m[1].get(2));
- m[1].set(2, f);
-}
-
-
-void matrix::normalize_rotation()
-// Normalizes the rotation part of the matrix.
-{
- m[0].normalize();
- m[1] = m[2].cross(m[0]);
- m[1].normalize();
- m[2] = m[0].cross(m[1]);
-}
-
-
-void matrix::apply(vec3* result, const vec3& v) const
-// Applies v to *this, and puts the transformed result in *result.
-{
- // Do the rotation.
- apply_rotation(result, v);
- // Do the translation.
- *result += m[3];
-}
-
-
-void matrix::apply_rotation(vec3* result, const vec3& v) const
-// Applies the rotation portion of *this, and puts the transformed result in
*result.
-{
- result->set(0, m[0].get(0) * v.get(0) + m[1].get(0) * v.get(1) +
m[2].get(0) * v.get(2));
- result->set(1, m[0].get(1) * v.get(0) + m[1].get(1) * v.get(1) +
m[2].get(1) * v.get(2));
- result->set(2, m[0].get(2) * v.get(0) + m[1].get(2) * v.get(1) +
m[2].get(2) * v.get(2));
-}
-
-
-void matrix::apply_inverse(vec3* result, const vec3& v) const
-// Applies v to the inverse of *this, and puts the transformed result in
*result.
-{
- apply_inverse_rotation(result, v - m[3]);
-}
-
-
-void matrix::apply_inverse_rotation(vec3* result, const vec3& v) const
-// Applies v to the inverse rotation part of *this, and puts the result in
*result.
-{
- result->set(0, m[0] * v);
- result->set(1, m[1] * v);
- result->set(2, m[2] * v);
-}
-
-
-void matrix::translate(const vec3& v)
-// Composes a translation on the right of *this.
-{
- vec3 newtrans;
- apply(&newtrans, v);
- set_column(3, newtrans);
-}
-
-
-void matrix::set_orientation(const quaternion& q)
-// Sets the rotation part of the matrix to the values which correspond to the
given
-// quaternion orientation.
-{
- float S = q.GetS();
- const vec3& V = q.GetV();
-
- m[0].set(0, 1 - 2 * V.get_y() * V.get_y() - 2 * V.get_z() * V.get_z());
- m[0].set(1, 2 * V.get_x() * V.get_y() + 2 * S * V.get_z());
- m[0].set(2, 2 * V.get_x() * V.get_z() - 2 * S * V.get_y());
-
- m[1].set(0, 2 * V.get_x() * V.get_y() - 2 * S * V.get_z());
- m[1].set(1, 1 - 2 * V.get_x() * V.get_x() - 2 * V.get_z() * V.get_z());
- m[1].set(2, 2 * V.get_y() * V.get_z() + 2 * S * V.get_x());
-
- m[2].set(0, 2 * V.get_x() * V.get_z() + 2 * S * V.get_y());
- m[2].set(1, 2 * V.get_y() * V.get_z() - 2 * S * V.get_x());
- m[2].set(2, 1 - 2 * V.get_x() * V.get_x() - 2 * V.get_y() * V.get_y());
-}
-
-
-quaternion matrix::get_orientation() const
-// Converts the rotation part of *this into a quaternion, and returns it.
-{
- // Code adapted from Baraff, "Rigid Body Simulation", from SIGGRAPH 95
course notes for Physically Based Modeling.
- quaternion q;
- float s;
-
- float tr = m[0].get(0) + m[1].get(1) + m[2].get(2); // trace
-
- if (tr >= 0) {
- s = sqrtf(tr + 1);
- q.SetS(0.5f * s);
- s = 0.5f / s;
- q.SetV(vec3(m[1].get(2) - m[2].get(1), m[2].get(0) -
m[0].get(2), m[0].get(1) - m[1].get(0)) * s);
- } else {
- int i = 0;
-
- if (m[1].get(1) > m[0].get(0)) {
- i = 1;
- }
- if (m[2].get(2) > m[i].get(i)) {
- i = 2;
- }
-
- float qr, qi, qj, qk;
- switch (i) {
- default:
- case 0:
- s = sqrtf((m[0].get(0) - (m[1].get(1) + m[2].get(2))) +
1);
- qi = 0.5f * s;
- s = 0.5f / s;
- qj = (m[1].get(0) + m[0].get(1)) * s;
- qk = (m[0].get(2) + m[2].get(0)) * s;
- qr = (m[1].get(2) - m[2].get(1)) * s;
- break;
-
- case 1:
- s = sqrtf((m[1].get(1) - (m[2].get(2) + m[0].get(0))) +
1);
- qj = 0.5f * s;
- s = 0.5f / s;
- qk = (m[2].get(1) + m[1].get(2)) * s;
- qi = (m[1].get(0) + m[0].get(1)) * s;
- qr = (m[2].get(0) - m[0].get(2)) * s;
- break;
-
- case 2:
- s = sqrtf((m[2].get(2) - (m[0].get(0) + m[1].get(1))) +
1);
- qk = 0.5f * s;
- s = 0.5f / s;
- qi = (m[0].get(2) + m[2].get(0)) * s;
- qj = (m[2].get(1) + m[1].get(2)) * s;
- qr = (m[0].get(1) - m[1].get(0)) * s;
- break;
- }
- q.SetS(qr);
- q.SetV(vec3(qi, qj, qk));
- }
-
- return q;
-}
-
-
-//
-// class quaternion
-//
-
-
-quaternion::quaternion(const vec3& Axis, float Angle)
-// Constructs the quaternion defined by the rotation about the given axis of
the given angle (in radians).
-{
- S = cosf(Angle / 2);
- V = Axis;
- V *= sinf(Angle / 2);
-}
-
-
-quaternion quaternion::operator*(const quaternion& q) const
-// Multiplication of two quaternions. Returns a new quaternion
-// result.
-{
- return quaternion(S * q.S - V * q.V, q.V * S + V * q.S + V.cross(q.V));
-}
-
-
-quaternion& quaternion::normalize()
-// Ensures that the quaternion has magnitude 1.
-{
- float mag = sqrtf(S * S + V * V);
- if (mag > 0.0000001) {
- float inv = 1.0f / mag;
- S *= inv;
- V *= inv;
- } else {
- // Quaternion is messed up. Turn it into a null rotation.
- S = 1;
- V = vec3::zero;
- }
-
- return *this;
-}
-
-
-quaternion& quaternion::operator*=(const quaternion& q)
-// In-place quaternion multiplication.
-{
- *this = *this * q; // I don't think we can avoid making
temporaries.
-
- return *this;
-}
-
-
-void quaternion::ApplyRotation(vec3* result, const vec3& v)
-// Rotates the given vec3 v by the rotation represented by this quaternion.
-// Stores the result in the given result vec3.
-{
- quaternion q(*this * quaternion(0, v) * quaternion(S, -V));
// There's definitely a shortcut here. Deal with later.
-
- *result = q.V;
-}
-
-
-quaternion quaternion::lerp(const quaternion& q, float f) const
-// Does a spherical linear interpolation between *this and q, using f as
-// the blend factor. f == 0 --> result == *this, f == 1 --> result == q.
-{
- quaternion result;
-
- float f0, f1;
-
- float cos_omega = V * q.V + S * q.S;
- quaternion qtemp(q);
-
- // Adjust signs if necessary.
- if (cos_omega < 0) {
- cos_omega = -cos_omega;
- qtemp.V = -qtemp.V;
- qtemp.S = -qtemp.S;
- }
-
- if (cos_omega < 0.99) {
- // Do the spherical interp.
- float omega = acosf(cos_omega);
- float sin_omega = sinf(omega);
- f0 = sinf((1 - f) * omega) / sin_omega;
- f1 = sinf(f * omega) / sin_omega;
- } else {
- // Quaternions are close; just do straight lerp and avoid
division by near-zero.
- f0 = 1 - f;
- f1 = f;
- }
-
- result.S = S * f0 + qtemp.S * f1;
- result.V = V * f0 + qtemp.V * f1;
- result.normalize();
-
- return result;
-}
-
-
-
-#ifdef NOT
-QuatSlerp(QUAT * from, QUAT * to, float t, QUAT * res)
- {
- float to1[4];
- double scale0, scale1;
-
- // calc cosine
- double cosom = from->x * to->x + from->y * to->y + from->z * to->z
- + from->w * to->w;
-
- // adjust signs (if necessary)
- if ( cosom <0.0 ){ cosom = -cosom; to1[0] = - to->x;
- to1[1] = - to->y;
- to1[2] = - to->z;
- to1[3] = - to->w;
- } else {
- to1[0] = to->x;
- to1[1] = to->y;
- to1[2] = to->z;
- to1[3] = to->w;
- }
-
- // calculate coefficients
-
- if ( (1.0 - cosom) > DELTA ) {
- // standard case (slerp)
- double omega = acos(cosom);
- double sinom = sin(omega);
- scale0 = sin((1.0 - t) * omega) / sinom;
- scale1 = sin(t * omega) / sinom;
-
- } else {
- // "from" and "to" quaternions are very close
- // ... so we can do a linear interpolation
- scale0 = 1.0 - t;
- scale1 = t;
- }
- // calculate final values
- res->x = scale0 * from->x + scale1 * to1[0];
- res->y = scale0 * from->y + scale1 * to1[1];
- res->z = scale0 * from->z + scale1 * to1[2];
- res->w = scale0 * from->w + scale1 * to1[3];
-}
-
-
-#endif // NOT
-
-
-#ifdef NOT
-void bitmap32::ProcessForColorKeyZero()
-// Examine alpha channel, and set pixels that have alpha==0 to color 0.
-// Pixels that have alpha > 0.5, but have color 0, should be tweaked slightly
-// so they don't get knocked out when blitting.
-{
- uint32_t Key32 = 0;
- uint32_t* p = GetData();
- int pixels = GetHeight() * GetWidth();
- for (int i = 0; i < pixels; i++, p++) {
- if ((*p >> 24) >= 128) {
- // Alpha >= 0.5. Make sure color isn't equal to color
key.
- if ((*p & 0x00FFFFFF) == Key32) {
- *p ^= 8; // Twiddle a low blue bit.
- }
- } else {
- // Set pixel's color equal to color key.
- *p = (*p & 0xFF000000) | Key32;
- }
- }
-}
-#endif // NOT
-
-
-namespace Geometry {
-
-
-
-vec3 Rotate(float Angle, const vec3& Axis, const vec3& Point)
-// Rotates the given point through the given angle (in radians) about the given
-// axis.
-{
- quaternion q(cosf(Angle/2), Axis * sinf(Angle/2));
-
- vec3 result;
- q.ApplyRotation(&result, Point);
-
- return result;
-}
-
-
-}
Index: libgeometry/geometry.h
===================================================================
RCS file: libgeometry/geometry.h
diff -N libgeometry/geometry.h
--- libgeometry/geometry.h 26 Aug 2006 18:45:50 -0000 1.6
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,240 +0,0 @@
-// geometry.hpp -- by Thatcher Ulrich <address@hidden>
-
-// This source code has been donated to the Public Domain. Do
-// whatever you want with it.
-
-// Some basic geometric types.
-
-
-#ifndef GEOMETRY_H
-#define GEOMETRY_H
-
-
-#include "utility.h"
-class tu_file;
-
-class vec3
-// 3-element vector class, for 3D math.
-{
-public:
- float x, y, z; // these guys are out in public, no m_ prefix;
this matches most other conventions.
-
- vec3() {}
- vec3(float XX, float YY, float ZZ) { x = XX; y = YY; z = ZZ; }
- vec3(const vec3& v) { x = v.x; y = v.y; z = v.z; }
-
- operator const float*() const { return &x; }
-
- const float& operator[](int index) const { assert(index >= 0 &&
index < 3); return (&x)[index]; }
- float& operator[](int index) { assert(index >= 0 && index < 3); return
(&x)[index]; }
-
- float get(int element) const { return (&x)[element]; }
- void set(int element, float NewValue) { (&x)[element] = NewValue; }
- float get_x() const { return x; }
- float get_y() const { return y; }
- float get_z() const { return z; }
-// float& x() { return m[0]; }
-// float& y() { return m[1]; }
-// float& z() { return m[2]; }
- void set_xyz(float newx, float newy, float newz) { x = newx; y =
newy; z = newz; }
-
- vec3 operator+(const vec3& v) const;
- vec3 operator-(const vec3& v) const;
- vec3 operator-() const;
- float operator*(const vec3& v) const;
- vec3 operator*(float f) const;
- vec3 operator/(float f) const { return this->operator*(1.0f / f); }
- vec3 cross(const vec3& v) const;
- void set_cross(const vec3& a, const vec3& b);
-
- // returns original length; if length is zero, sets our value to
fallback.
- float normalize(const vec3& fallback = vec3::x_axis);
-
- vec3& operator=(const vec3& v) { x = v.x; y = v.y; z = v.z; return
*this; }
- vec3& operator+=(const vec3& v);
- vec3& operator-=(const vec3& v);
- vec3& operator*=(float f);
- vec3& operator/=(float f) { return this->operator*=(1.0f / f); }
-
- float magnitude() const;
- float sqrmag() const;
-// float min() const;
-// float max() const;
-// float minabs() const;
-// float maxabs() const;
-
- void read(tu_file* in);
- void write(tu_file* out);
-
- bool checknan() const; // Returns true if any component is nan.
-
- // Some handy vector constants.
- static const vec3 zero, x_axis, y_axis, z_axis, flt_max,
minus_flt_max;
-};
-
-
-#define INLINE_VEC3
-
-
-#ifdef INLINE_VEC3
-
-
-inline float vec3::operator*(const vec3& v) const
-// Dot product.
-{
- float result;
- result = x * v.x;
- result += y * v.y;
- result += z * v.z;
- return result;
-}
-
-
-inline vec3& vec3::operator+=(const vec3& v)
-// Adds a vec3 to *this.
-{
- x += v.x;
- y += v.y;
- z += v.z;
- return *this;
-}
-
-
-inline vec3& vec3::operator-=(const vec3& v)
-// Subtracts a vec3 from *this.
-{
- x -= v.x;
- y -= v.y;
- z -= v.z;
- return *this;
-}
-
-
-inline void vec3::set_cross(const vec3& a, const vec3& b)
-// Cross product.
-{
- assert(this != &a);
- assert(this != &b);
-
- x = a.y * b.z - a.z * b.y;
- y = a.z * b.x - a.x * b.z;
- z = a.x * b.y - a.y * b.x;
-}
-
-
-#endif // INLINE_VEC3
-
-
-
-
-
-class quaternion;
-
-
-class matrix
-// 3x4 matrix class, for 3D transformations.
-{
-public:
- matrix() { set_identity(); }
-
- void set_identity();
- void set_view(const vec3& ViewNormal, const vec3& ViewUp, const
vec3& ViewLocation);
- void set_orient(const vec3& ObjectDirection, const vec3& ObjectUp,
const vec3& ObjectLocation);
-
- static void compose(matrix* dest, const matrix& left, const matrix&
right);
- vec3 operator*(const vec3& v) const;
- matrix operator*(const matrix& m) const;
-// operator*=(const quaternion& q);
-
- matrix& operator*=(float f);
- matrix& operator+=(const matrix& m);
-
- void invert();
- void invert_rotation();
- void normalize_rotation();
- void apply(vec3* result, const vec3& v) const;
- void apply_rotation(vec3* result, const vec3& v) const;
- void apply_inverse(vec3* result, const vec3& v) const;
- void apply_inverse_rotation(vec3* result, const vec3& v) const;
- void translate(const vec3& v);
- void set_orientation(const quaternion& q);
- quaternion get_orientation() const;
-
- void set_column(int column, const vec3& v) { m[column] = v; }
- const vec3& get_column(int column) const { return m[column]; }
-private:
- vec3 m[4];
-};
-
-
-// class quaternion -- handy for representing rotations.
-
-class quaternion {
-public:
- quaternion() : S(1), V(vec3::zero) {}
- quaternion(const quaternion& q) : S(q.S), V(q.V) {}
- quaternion(float s, const vec3& v) : S(s), V(v) {}
-
- quaternion(const vec3& Axis, float Angle); // Slightly dubious:
semantics varies from other constructor depending on order of arg types.
-
- float GetS() const { return S; }
- const vec3& GetV() const { return V; }
- void SetS(float s) { S = s; }
- void SetV(const vec3& v) { V = v; }
-
- float get(int i) const { if (i==0) return GetS(); else return
V.get(i-1); }
- void set(int i, float f) { if (i==0) S = f; else V.set(i-1, f); }
-
- quaternion operator*(const quaternion& q) const;
- quaternion& operator*=(float f) { S *= f; V *= f; return *this; }
- quaternion& operator+=(const quaternion& q) { S += q.S; V += q.V;
return *this; }
-
- quaternion& operator=(const quaternion& q) { S = q.S; V = q.V;
return *this; }
- quaternion& normalize();
- quaternion& operator*=(const quaternion& q);
- void ApplyRotation(vec3* result, const vec3& v);
-
- quaternion lerp(const quaternion& q, float f) const;
-private:
- float S;
- vec3 V;
-};
-
-
-class plane_info {
-public:
- vec3 normal;
- float d;
-
- plane_info() { }
-
- plane_info( const vec3& n, float dist ) {
- set( n, dist );
- }
-
- void set( const vec3& n, float dist ) {
- normal = n;
- d = dist;
- }
-
- void set(float nx, float ny, float nz, float dist) {
- normal.set_xyz(nx, ny, nz);
- d = dist;
- }
-};
-
-
-struct collision_info {
- vec3 point;
- vec3 normal;
- // float distance, or ray_parameter;
-};
-
-
-namespace Geometry {
- vec3 Rotate(float Angle, const vec3& Axis, const vec3& Point);
-}
-
-
-
-#endif // GEOMETRY_H
Index: libgeometry/loose_octree.cpp
===================================================================
RCS file: libgeometry/loose_octree.cpp
diff -N libgeometry/loose_octree.cpp
--- libgeometry/loose_octree.cpp 26 Aug 2006 18:32:57 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,100 +0,0 @@
-// loose_octree.cpp -- by Thatcher Ulrich <address@hidden>
-
-// This source code has been donated to the Public Domain. Do
-// whatever you want with it.
-
-// bounding-volume hierarchy for doing spatial queries on objects.
-
-
-#ifndef SPATIAL_CONTAINER_H
-#define SPATIAL_CONTAINER_H
-
-
-#include "geometry.h"
-
-// sp_tag is used as a link node for the spatial_container.
-//
-// @@ questions: best to keep this separate from the actual object
-// storage? Or is there an advantage to allowing contained objects to
-// derive from this tag type (probably not -- prevents putting objects
-// in multiple containers, and isn't too intuitive).
-//
-
-struct sp_tag {
- vec3 center;
- float extent; // half-size of an edge for cubes, radius for spheres.
- void* payload;
-
- sp_tag *next;
- sp_tag *previous;
-};
-
-
-class spatial_container_result_callback {
-public:
- virtual void result_callback( const sp_tag& result );
-};
-
-
-class spatial_container_void {
-public:
- spatial_container_void( base_cell_extent, max_depth );
-
-#if EXAMPLES
- // with the iterator pattern, I think the result callback may be
useless...
- // you just do this sort of thing:
- //
- for ( spatial_container_void::iterator i( container, center, extent );
- ! i.is_finished();
- i.advance() )
- {
- i.get_current()->payload...;
- }
-
- // define a spatial_query class, templated on type of container...?
dunno if that's possible.
-
- foreach_spatial_in_cube( type, var, container, center, extent, hint ) {
- if ( square_length( var->GetPosition(), center ) < extent *
extent ) {
- var->apply_effect();
- }
- }
-
- foreach_spatial_in_frustum( type /* from container? or useful for
casting. */, var, container, frustum, hint ) {
- var->Render();
- }
-
- ray_test( &result, ray, );
-
-#endif // EXAMPLES
-
-
- class cube_iterator {
- public:
- // void advance();
- // sp_tag* get_current();
- sp_tag* get_next(); // return 0 when finished?
- bool is_finished();
-
- private:
- vec3 query_center;
- float query_extent;
- // int direction_hint;
- // int query_outcode; // @@ figure this out.
-
- node* current_node;
- sp_tag* current_tag;
- };
-
-
-// class ray_iterator {
-// };
-
-
-// class frustum_iterator {
-// };
-
-};
-
-
-#endif // SPATIAL_CONTAINER_H
-
Index: libgeometry/tqt.cpp
===================================================================
RCS file: libgeometry/tqt.cpp
diff -N libgeometry/tqt.cpp
--- libgeometry/tqt.cpp 26 Aug 2006 18:32:57 -0000 1.4
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,164 +0,0 @@
-// tqt.cpp -- Thatcher Ulrich <address@hidden> 2002
-
-// This source code has been donated to the Public Domain. Do
-// whatever you want with it.
-
-// Texture quadtree utility class.
-
-
-//#include "ogl.h"
-#include "tqt.h"
-#include "image.h"
-#include "tu_file.h"
-
-
-static const int TQT_VERSION = 1;
-
-
-class tqt_header_info {
-public:
- int m_version;
- int m_tree_depth;
- int m_tile_size;
-
- tqt_header_info()
- : m_version(0),
- m_tree_depth(0),
- m_tile_size(0)
- {
- }
-};
-
-
-static tqt_header_info read_tqt_header_info(tu_file* in)
-// Read .tqt header file info from the given stream, and return a
-// struct containing the info. If the file doesn't look like .tqt,
-// then set m_version in the return value to 0.
-{
- tqt_header_info info;
-
- int tag = in->read_le32();
- if (tag != 0x00747174 /* "tqt\0" */) {
- // Wrong header tag.
- info.m_version = 0; // signal invalid header.
- return info;
- }
-
- info.m_version = in->read_le32();
- info.m_tree_depth = in->read_le32();
- info.m_tile_size = in->read_le32();
-
- return info;
-}
-
-
-tqt::tqt(const char* filename)
-// Constructor. Open the file and read the table of contents. Keep
-// the stream open in order to load textures on demand.
-{
- m_source = new tu_file(filename, "rb");
- if (m_source == NULL) {
- throw "tqt::tqt() can't open file.";
- }
-
- // Read header.
- tqt_header_info info = read_tqt_header_info(m_source);
- if (info.m_version != TQT_VERSION) {
- m_source = NULL;
- throw "tqt::tqt() incorrect file version.";
- return; // Hm.
- }
-
- m_depth = info.m_tree_depth;
- m_tile_size = info.m_tile_size;
-
- // Read table of contents. Each entry is the offset of the
- // index'ed tile's JPEG data, relative to the start of the file.
- m_toc.resize(node_count(m_depth));
- for (int i = 0; i < node_count(m_depth); i++) {
- m_toc[i] = m_source->read_le32();
- }
-}
-
-
-tqt::~tqt()
-// Destructor. Close input file and release resources.
-{
- delete m_source;
-}
-
-
-//unsigned int tqt::get_texture_id(int level, int col, int row) const
-//// Returns the OpenGL texture id for a texture tile corresponding to
-//// the specified node in the quadtree.
-//{
-// return make_texture_id(load_image(level, col, row));
-//}
-
-
-image::rgb* tqt::load_image(int level, int col, int row) const
-// Create a new image with data from the specified texture tile.
-// Caller becomes the owner of the returned object.
-{
- if (is_valid() == false) {
- return NULL;
- }
- assert(level < m_depth);
-
- int index = node_index(level, col, row);
- assert(index < (int) m_toc.size());
-
- // Load the .jpg and make a texture from it.
- m_source->set_position(m_toc[index]);
- image::rgb* im = image::read_jpeg(m_source);
-
- return im;
-}
-
-
-/*static*/ int tqt::node_count(int depth)
-// Return the number of nodes in a fully populated quadtree of the specified
depth.
-{
- return 0x55555555 & ((1 << depth*2) - 1);
-}
-
-
-/*static*/ int tqt::node_index(int level, int col, int row)
-// Given a tree level and the indices of a node within that tree
-// level, this function returns a node index.
-{
- assert(col >= 0 && col < (1 << level));
- assert(row >= 0 && row < (1 << level));
-
- return tqt::node_count(level) + (row << level) + col;
-}
-
-
-/*static*/ bool tqt::is_tqt_file(const char* filename)
-// Return true if the given file looks like a .tqt file of our
-// appropriate version. Do this by attempting to read the header.
-{
- tu_file in(filename, "rb");
- if (in.get_error())
- {
- return false;
- }
-
- // Read header.
- tqt_header_info info = read_tqt_header_info(&in);
-
- if (info.m_version != TQT_VERSION)
- {
- return false;
- }
-
- return true;
-}
-
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 8
-// tab-width: 8
-// indent-tabs-mode: t
-// End:
Index: libgeometry/tqt.h
===================================================================
RCS file: libgeometry/tqt.h
diff -N libgeometry/tqt.h
--- libgeometry/tqt.h 25 Feb 2006 03:54:03 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,50 +0,0 @@
-// tqt.h -- Thatcher Ulrich <address@hidden> 2002
-
-// This source code has been donated to the Public Domain. Do
-// whatever you want with it.
-
-// Texture quadtree utility class.
-
-#ifndef TQT_H
-#define TQT_H
-
-
-#include "container.h"
-#include "image.h"
-class tu_file;
-
-
-class tqt
-// Manages a disk-based texture quadtree.
-{
-public:
- tqt(const char* filename);
- ~tqt();
- bool is_valid() const { return m_source != NULL; }
- int get_depth() const { return m_depth; }
- int get_tile_size() const { return m_tile_size; }
-
- unsigned int get_texture_id(int level, int col, int row) const;
- image::rgb* load_image(int level, int col, int row) const;
-
- // Static utility functions.
- static bool is_tqt_file(const char* filename);
- static int node_count(int depth);
- static int node_index(int level, int col, int row);
-
-private:
- std::vector<unsigned int> m_toc;
- int m_depth;
- int m_tile_size;
- tu_file* m_source;
-};
-
-
-#endif // TQT_H
-
-// Local Variables:
-// mode: C++
-// c-basic-offset: 8
-// tab-width: 8
-// indent-tabs-mode: t
-// End:
Index: libgeometry/view_state.h
===================================================================
RCS file: libgeometry/view_state.h
diff -N libgeometry/view_state.h
--- libgeometry/view_state.h 26 Aug 2006 00:25:07 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,40 +0,0 @@
-// view_state.h -- Thatcher Ulrich <address@hidden>
-
-// This source code has been donated to the Public Domain. Do
-// whatever you want with it.
-
-// "view_state", a class that holds various important rendering
-// states during render traversal.
-
-
-#ifndef VIEW_STATE_H
-#define VIEW_STATE_H
-
-
-#include "geometry.h"
-#include "cull.h"
-
-
-class view_state
-// Description of basic rendering state. Passed as an arg to
-// visual::render().
-{
-public:
- int m_frame_number;
- matrix m_matrix;
- plane_info m_frustum[6]; // In local coordinates.
-
- vec3 get_viewpoint() const
- {
- vec3 v;
- m_matrix.apply_inverse_rotation(&v, -m_matrix.get_column(3));
- return v;
- }
-
- // @@ Should this contain the culling state? Or keep that separate?
-
- // @@ Add transformation methods, perhaps lazy updating of frustum
planes... ??
-};
-
-
-#endif // VIEW_STATE_H
Index: libgeometry/visual.h
===================================================================
RCS file: libgeometry/visual.h
diff -N libgeometry/visual.h
--- libgeometry/visual.h 1 Feb 2006 23:58:32 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,61 +0,0 @@
-// visual.h -- Thatcher Ulrich <address@hidden>
-
-// This source code has been donated to the Public Domain. Do
-// whatever you want with it.
-
-// "visual", a base class interface for renderable objects. Plus a
-// few basic visual nodes.
-
-
-#ifndef VISUAL_H
-#define VISUAL_H
-
-
-#include "view_state.h"
-
-
-class visual
-// Interface for things that can be rendered.
-{
-public:
- virtual void render( const view_state& v ) = 0;
- float get_radius() const { return m_radius; }
-
-protected:
- float m_radius;
-};
-
-
-class visual_transform : virtual public visual
-// Node which contains a transform and another visual node, and
-// transforms the render query before passing it down.
-{
-public:
- void render( const view_state& v ); // render transformed child
visual.
-
- const matrix& get_transform() const { return m_transform; }
- void set_transform( const matrix& m ) { m_transform = m; }
-
- visual* get_visual() { return m_visual; }
- void set_visual( visual* v ) { m_visual = v; }
-
-private:
- visual* m_visual;
- matrix m_transform;
-};
-
-
-class visual_list : virtual public visual
-// Node which contains a collection of visuals.
-{
-public:
-
-private:
-
-};
-
-
-//class visual_label; // label mix-in.
-
-
-#endif // VISUAL_H
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog gui/Makefile.am libgeometry/Mak...,
Sandro Santilli <=