From: Charles McGarvey Date: Fri, 14 Aug 2009 16:37:40 +0000 (-0600) Subject: scene drawing correctly implemented; new classes X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=29e3d45f7bbbf31eadf793c41ff2b3d9c47b7539;p=chaz%2Fyoink scene drawing correctly implemented; new classes --- diff --git a/configure.ac b/configure.ac index 4aafa81..9267e80 100644 --- a/configure.ac +++ b/configure.ac @@ -73,10 +73,10 @@ AC_SUBST([DATADIR]) AC_DEFINE_UNQUOTED([YOINK_DATADIR], ["$DATADIR"], [Define to path of game asset directory.]) -CONFIGFILES="\$HOME/.yoinkrc:/etc/yoinkrc:$DATADIR/yoinkrc" +CONFIGFILES="\$HOME/.yoinkrc:/etc/yoinkrc" AC_DEFINE_UNQUOTED([YOINK_CONFIGFILES], ["$CONFIGFILES"], - [Define to colon-delimited config file paths.]) + [Define to colon-delimited configuration file paths.]) # diff --git a/data/scenes/Test.xml b/data/scenes/Test.xml deleted file mode 100644 index fa92959..0000000 --- a/data/scenes/Test.xml +++ /dev/null @@ -1,824 +0,0 @@ - - - - - - - - - -5 0 5 - 32 - - TowerBlock1 - - 2 2 2 2 2 - 1 0 0 1 0 - 1 0 0 1 0 - 1 0 0 1 0 - 1 0 0 1 0 - 1 0 0 1 0 - 1 0 0 1 0 - 1 0 0 1 0 - 1 0 0 1 0 - 1 0 0 1 0 - 1 0 0 1 0 - 1 0 0 1 0 - 1 0 0 1 0 - 1 0 0 1 0 - 4 4 4 4 4 - - - - - - 90 - 0 0 5 - 32 - - TowerBlock1 - - 2 2 2 2 2 - 0 0 0 0 0 - 0 0 0 0 0 - 0 0 0 0 0 - 0 0 0 0 0 - 0 0 0 0 0 - 0 0 0 0 0 - 0 0 0 0 0 - 0 0 0 0 0 - 0 0 0 0 0 - 0 0 0 0 0 - 0 0 0 0 0 - 0 0 0 0 0 - 0 0 0 0 6 - 4 5 5 5 4 - - - - - - 90 - -5 15 0 - 32 - - TowerBlock1 - - 3 3 3 3 3 - 3 3 3 3 3 - 3 3 3 3 3 - 3 3 3 3 3 - 3 3 3 3 3 - - - - - - - - 32 - - TowerBlock1 - - 2 2 2 2 2 2 2 - 0 1 0 0 0 1 0 - 0 1 0 0 0 1 0 - 0 1 0 0 6 1 0 - 0 1 0 0 0 1 0 - 0 1 0 0 0 1 0 - 0 1 0 0 0 1 0 - 4 4 5 5 5 4 4 - - - - - - 90 - 7 0 0 - 32 - - TowerBlock1 - - 2 2 2 2 2 2 - 0 1 0 0 1 0 - 0 1 0 0 1 0 - 0 1 0 0 1 0 - 0 1 0 0 1 0 - 0 1 0 0 1 0 - 0 1 0 0 1 0 - 4 4 4 4 4 4 - - - - - - 90 - -2 8 -6 - 32 - - TowerBlock1 - - 3 3 3 3 3 3 3 3 3 - 3 3 3 3 3 3 3 3 3 - 3 3 3 3 3 3 3 3 3 - 3 3 3 3 3 3 3 3 3 - 3 3 3 3 3 3 3 3 3 - 3 3 3 3 3 3 3 3 3 - - - - - - - - -90 - 10 0 1 - 32 - - Building - - -1 9 11 -1 - 9 10 12 11 - 15 7 7 16 - 3 5 6 4 - 3 6 5 4 - - - - - - -90 - 13 0 1 - 32 - - Building - - -1 9 11 -1 - 9 10 12 11 - 15 7 7 16 - 3 5 6 4 - 3 8 5 4 - - - - - - 10 0 5 - 32 - - Building - - 15 7 16 - 3 5 4 - 3 6 4 - - - - - - 135 - 1 1.5 1.5 - 10 5 3 - 32 - - Building - - 13 13 13 - 13 13 13 - - - - - - 10 5 3 - 32 - - Building - - 18 18 18 - - - - - - 10 4 3 - 32 - - Building - - -1 -1 -1 - - - - - - - - 90 - -3 0 0 - 32 - Scenery - - 1 1 1 1 1 1 1 1 1 1 1 1 1 - 1 1 1 1 1 1 1 1 1 1 1 1 1 - -1 -1 -1 1 0 0 0 0 0 0 0 0 1 - -1 -1 -1 1 0 0 0 0 0 0 0 0 1 - -1 -1 -1 1 0 0 0 0 0 0 0 0 1 - -1 -1 -1 1 0 0 0 0 0 0 0 0 1 - -1 -1 -1 1 1 1 1 1 1 1 1 1 1 - - - - - - 8 1 1 - 1 -0.5 5 - 32 - Scenery - - - - - - 8 1 1 - 1 -0.5 1 - 32 - Scenery - - - - - - 4 1 1 - -90 - 1 -0.5 1 - 32 - Scenery - - - - - - 4 1 1 - -90 - 9 -0.5 1 - 32 - Scenery - - - - - - 11 1 1 - 7 0 0 - 32 - - Scenery - - - - - - - - 19 0 0 - 32 - - Building - - -1 9 11 -1 - 9 10 12 11 - 15 7 7 16 - 3 6 5 4 - 3 5 6 4 - 3 8 5 4 - - - - - - -90 - 19 0 -3 - 32 - - Building - - 15 1 16 - 3 7 4 - 3 5 4 - 3 0 4 - - - - - - -90 - 23 0 -3 - 32 - - Building - - 15 0 16 - 3 7 4 - 3 6 4 - 3 2 4 - - - - - - 135 - 1 1.5 1.5 - -90 - 21 6 -3 - 32 - - Building - - 13 13 13 - 13 13 13 - - - - - - -135 - 1 1.5 1.5 - -90 - 21 6 -3 - 32 - - Building - - 13 13 13 - 13 13 13 - - - - - - -90 - 21 6 -3 - 32 - - Building - - 18 18 18 - - - - - - - - 90 - 10 0 0 - 32 - Scenery - - 1 1 1 - 1 1 1 - -1 -1 -1 - -1 -1 -1 - -1 -1 -1 - -1 -1 -1 - 1 1 1 - - - - - - 90 - 13 0 0 - 32 - Scenery - - 1 1 1 1 1 1 1 1 - 1 1 1 1 1 1 1 1 - 1 0 0 0 0 0 0 0 - 1 0 0 0 0 0 1 1 - 0 0 0 0 0 0 1 1 - 1 0 0 0 0 0 0 0 - 1 1 1 1 1 0 0 0 - - - - - - 12 1 1 - 14 -0.5 5 - 32 - Scenery - - - - - - 4 1 1 - 14 -0.5 1 - 32 - Scenery - - - - - - 1 1 1 - 13 -0.5 3 - 32 - Scenery - - - - - - 1 1 1 - 13 -0.5 2 - 32 - Scenery - - - - - - -90 - 14 -0.5 1 - 32 - Scenery - - 2 -1 2 2 - - - - - - -90 - 1 1 1 - 18 -0.5 0 - 32 - Scenery - - - - - - -90 - 1 1 1 - 24 -0.5 0 - 32 - Scenery - - - - - - 4 1 1 - 19 -0.5 4 - 32 - Scenery - - - - - - 4 1 1 - 19 -0.5 2 - 32 - Scenery - - - - - - 2 1 1 - -90 - 19 -0.5 2 - 32 - Scenery - - - - - - 2 1 1 - -90 - 23 -0.5 2 - 32 - Scenery - - - - - - - - 90 - 21 0 0 - 32 - Scenery - - 1 1 1 1 1 0 0 - 1 1 1 1 1 0 0 - 0 0 0 0 0 0 0 - 1 1 0 0 0 0 0 - 1 1 0 0 0 0 0 - 0 0 0 0 0 0 0 - 0 0 0 1 1 1 1 - - - - - - 4 1 1 - 24 0 0 - 32 - - Scenery - - - - - - 4 1 1 - 24 -0.5 1 - 32 - Scenery - - - - - - 2 1 1 - -90 - 26 -0.5 5 - 32 - Scenery - - - - - - 2 1 1 - -90 - 35 -0.5 5 - 32 - Scenery - - - - - - 5 1 1 - 35 -0.5 5 - 32 - Scenery - - - - - - 6 1 1 - 34 -0.5 1 - 32 - Scenery - - - - - - 1 1 1 - -90 - 34 -0.5 0 - 32 - Scenery - - - - - - 90 - 28 0 4 - 32 - Scenery - - 0 0 0 0 0 - 0 0 0 0 0 - 0 0 0 0 0 - - - - - - 90 - 33 0 0 - 32 - Scenery - - 0 0 1 1 1 1 1 1 1 1 - 0 0 1 1 1 1 1 1 1 1 - 0 0 0 0 0 0 0 -1 -1 -1 - 0 0 0 0 0 0 0 -1 -1 -1 - 0 0 0 0 0 0 0 -1 -1 -1 - 0 0 0 0 0 0 0 -1 -1 -1 - 0 1 1 1 1 1 1 -1 -1 -1 - - - - - - - - 28 0 4 - 32 - - TowerBlock1 - - 2 2 2 2 2 - 0 0 0 0 0 - 0 0 0 0 6 - 0 0 0 0 0 - 0 0 0 0 0 - 0 0 0 6 0 - 4 4 4 4 4 - - - - - - 90 - 33 0 4 - 32 - - TowerBlock1 - - 2 2 2 2 2 2 - 0 1 0 0 1 0 - 0 1 0 0 1 0 - 0 1 0 0 1 0 - 0 1 0 0 1 0 - 0 1 0 0 1 0 - 5 4 5 5 4 5 - - - - - - 90 - 28 0 4 - 32 - - TowerBlock1 - - 2 2 2 2 2 2 - 0 1 6 0 1 0 - 0 1 0 0 1 0 - 0 1 0 0 1 0 - 0 1 0 0 1 0 - 0 1 0 0 1 0 - 5 4 5 5 4 5 - - - - - - 90 - 28 7 -2 - 32 - - TowerBlock1 - - 3 3 3 3 3 - 3 3 3 3 3 - 3 3 3 3 3 - 3 3 3 3 3 - 3 3 3 3 3 - 3 3 3 3 3 - - - - - - - - 40 0 5 - 32 - - TowerBlock1 - - 2 2 2 2 2 - 0 1 0 0 1 - 0 1 0 0 1 - 0 1 0 0 1 - 0 1 0 0 1 - 6 1 0 0 1 - 0 1 0 0 1 - 0 1 0 0 1 - 0 1 0 0 1 - 0 1 0 0 1 - 0 1 0 0 1 - 6 1 0 0 1 - 0 1 0 0 1 - 0 1 0 0 1 - 4 4 4 4 4 - - - - - - 90 - 40 0 5 - 32 - - TowerBlock1 - - 2 2 2 2 2 - 6 0 0 0 0 - 0 0 0 0 0 - 0 0 0 0 0 - 0 0 0 6 0 - 0 0 0 0 0 - 0 0 0 0 0 - 0 0 6 0 0 - 0 0 0 0 0 - 0 0 0 0 0 - 0 0 0 0 0 - 0 0 0 0 0 - 0 0 0 0 0 - 0 0 0 0 0 - 4 5 5 5 4 - - - - - - 90 - 40 15 0 - 32 - - TowerBlock1 - - 3 3 3 3 3 - 3 3 3 3 3 - 3 3 3 3 3 - 3 3 3 3 3 - 3 3 3 3 3 - - - - - - -0.3 -0.17 -900 - 3200 1600 1 - BackgroundFar - - - 0 0 300 - BackgroundNear - - - - - Trees - - - - - 96 - 250 -2.5 16 - - - - - - - 96 - 610 -2.5 85 - - - - - 96 - 650 -2.5 115 - - - - - - - 96 - 1080 -2.5 10 - - - - - 96 - 1120 -2.5 -15 - - - - - 96 - 1220 -2.5 -30 - - - diff --git a/src/Character.cc b/src/Character.cc index 1797f00..f508682 100644 --- a/src/Character.cc +++ b/src/Character.cc @@ -40,7 +40,7 @@ Character::~Character() } -void Character::draw(Mf::Scalar alpha) {} +void Character::draw(Mf::Scalar alpha) const {} Mf::Tilemap& Character::getTilemap() { diff --git a/src/Character.hh b/src/Character.hh index 2894c5e..e39e7ff 100644 --- a/src/Character.hh +++ b/src/Character.hh @@ -45,7 +45,7 @@ public: Character(const std::string& name); ~Character(); - void draw(Mf::Scalar alpha); + void draw(Mf::Scalar alpha) const; Mf::Tilemap& getTilemap(); Mf::Animation& getAnimation(); diff --git a/src/Makefile.am b/src/Makefile.am index 0826767..ea68cde 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,9 +2,11 @@ noinst_LTLIBRARIES = libmoof.la libmoof_la_SOURCES = \ + Moof/Aabb.cc \ Moof/Aabb.hh \ Moof/Animation.cc \ Moof/Animation.hh \ + Moof/Camera.cc \ Moof/Camera.hh \ Moof/ConvertUTF.c \ Moof/ConvertUTF.h \ @@ -16,12 +18,16 @@ libmoof_la_SOURCES = \ Moof/Drawable.hh \ Moof/Engine.cc \ Moof/Engine.hh \ + Moof/Entity.hh \ Moof/Event.hh \ + Moof/Frustum.hh \ Moof/Interpolator.hh \ Moof/Math.hh \ Moof/Mippleton.hh \ + Moof/Octree.hh \ Moof/OpenGL.cc \ Moof/OpenGL.hh \ + Moof/Plane.hh \ Moof/Profiler.hh \ Moof/Random.cc \ Moof/Random.hh \ @@ -45,6 +51,7 @@ libmoof_la_SOURCES = \ Moof/Tilemap.hh \ Moof/Timer.cc \ Moof/Timer.hh \ + Moof/Tree.hh \ Moof/Video.cc \ Moof/Video.hh \ Moof/fastevents.c \ @@ -75,8 +82,7 @@ yoink_LDADD = libmoof.la EXTRA_DIST = Moof/cml -YOINK_ENVIRONMENT = YOINK_DATADIR="$(top_srcdir)/data" \ - YOINKRC="$(top_srcdir)/data/yoinkrc" +YOINK_ENVIRONMENT = YOINK_DATADIR="$(top_srcdir)/data" run: all $(YOINK_ENVIRONMENT) ./yoink diff --git a/src/Moof/Aabb.cc b/src/Moof/Aabb.cc new file mode 100644 index 0000000..7b2ada7 --- /dev/null +++ b/src/Moof/Aabb.cc @@ -0,0 +1,63 @@ + +/******************************************************************************* + + Copyright (c) 2009, Charles McGarvey + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*******************************************************************************/ + +#include + + +namespace Mf { + + +void Aabb::draw(Scalar alpha) const +{ + Scalar vertices[] = {min[0], min[1], min[2], + min[0], max[1], min[2], + max[0], max[1], min[2], + max[0], min[1], min[2], + min[0], max[1], max[2], + min[0], min[1], max[2], + max[0], min[1], max[2], + max[0], max[1], max[2]}; + + GLubyte indicis[] = {0, 1, 2, 3, + 1, 2, 7, 4, + 3, 0, 5, 6, + 2, 3, 6, 7, + 5, 0, 1, 4, + 4, 5, 6, 7}; + + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(3, GL_SCALAR, 0, vertices); + + glDrawElements(GL_QUADS, sizeof(indicis), GL_UNSIGNED_BYTE, indicis); +} + + +} // namespace Mf + +/** vim: set ts=4 sw=4 tw=80: *************************************************/ + diff --git a/src/Moof/Aabb.hh b/src/Moof/Aabb.hh index f66fb24..b43e194 100644 --- a/src/Moof/Aabb.hh +++ b/src/Moof/Aabb.hh @@ -1,5 +1,5 @@ -/****************************************************************************** +/******************************************************************************* Copyright (c) 2009, Charles McGarvey All rights reserved. @@ -24,11 +24,12 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -******************************************************************************/ +*******************************************************************************/ #ifndef _MOOF_AABB_HH_ #define _MOOF_AABB_HH_ +#include #include @@ -39,21 +40,70 @@ namespace Mf { * Axis-aligned Bounding Box */ -struct Aabb +struct Aabb : public Drawable { - Aabb() {} + Vector3 min; + Vector3 max; - Aabb(const Vector3& minPoint, const Vector3& maxPoint) : - min(minPoint), - max(maxPoint) {} - Aabb (Scalar minX, Scalar minY, Scalar minZ, - Scalar maxX, Scalar maxY, Scalar maxZ) : - min(minX, minY, minZ), - max(maxX, maxY, maxZ) {} + Aabb() {} - Vector3 min; - Vector3 max; + Aabb(const Vector3& a, const Vector3& b) + { + init(a, b); + } + + Aabb(Scalar ax, Scalar ay, Scalar az, + Scalar bx, Scalar by, Scalar bz) + { + Vector3 a(ax, ay, az); + Vector3 b(bx, by, bz); + + init(a, b); + } + + inline void init(const Vector3& a, const Vector3& b) + { + if (a[0] < b[0]) + { + min[0] = a[0]; + max[0] = b[0]; + } + else + { + min[0] = b[0]; + max[0] = a[0]; + } + if (a[1] < b[1]) + { + min[1] = a[1]; + max[1] = b[1]; + } + else + { + min[1] = b[1]; + max[1] = a[1]; + } + if (a[2] < b[2]) + { + min[2] = a[2]; + max[2] = b[2]; + } + else + { + min[2] = b[2]; + max[2] = a[2]; + } + } + + inline Vector3 getCenter() const + { + return Vector3((min[0] + max[0]) / 2.0, + (min[1] + max[1]) / 2.0, + (min[2] + max[2]) / 2.0); + } + + void draw(Scalar alpha) const; }; diff --git a/src/Moof/Camera.cc b/src/Moof/Camera.cc new file mode 100644 index 0000000..26e24ba --- /dev/null +++ b/src/Moof/Camera.cc @@ -0,0 +1,166 @@ + +/******************************************************************************* + + Copyright (c) 2009, Charles McGarvey + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*******************************************************************************/ + +#include +#include + + +namespace Mf { + + +void Camera::setPosition(const Vector3& point) +{ + //position_ = point; + Vector3 coeff[2] = {position_, point}; + pInterp_.init(coeff, 0.1); +} +void Camera::setRotation(const Quaternion& rotation) +{ + rotation_ = rotation; + //srcRotation_ = rotation_; + //dstRotation_ = rotation; + //tInterp_ = 0.0; +} + +void Camera::update(Scalar t, Scalar dt) +{ + pInterp_.update(dt); + position_ = pInterp_.getState(0.0); + + //tInterp_ += dt * 10.0; + //rotation_ = cml::slerp(srcRotation_, dstRotation_, cml::clamp(tInterp_, 0.0, 1.0)); + //rotation_.normalize(); + + calculateSecondary(); +} + + +void Camera::lookAt(const Vector3& point) +{ + quaternion_rotation_aim_at(rotation_, position_, point); +} + +void Camera::adjustFromInput(const Event& event) +{ + switch (event.type) + { + case SDL_KEYDOWN: + if (event.key.keysym.sym == SDLK_RIGHT || + event.key.keysym.sym == SDLK_d) + { + Vector3 vec = position_; + vec[0] -= 50.0; + setPosition(vec); + } + else if (event.key.keysym.sym == SDLK_LEFT || + event.key.keysym.sym == SDLK_a) + { + Vector3 vec = position_; + vec[0] += 50.0; + setPosition(vec); + } + else if (event.key.keysym.sym == SDLK_UP || + event.key.keysym.sym == SDLK_w) + { + Vector3 vec = position_; + vec[1] -= 50.0; + setPosition(vec); + } + else if (event.key.keysym.sym == SDLK_DOWN || + event.key.keysym.sym == SDLK_s) + { + Vector3 vec = position_; + vec[1] += 50.0; + setPosition(vec); + } + else if (event.key.keysym.sym == SDLK_PAGEUP) + { + Vector3 vec = position_; + vec[2] += 50.0; + setPosition(vec); + } + else if (event.key.keysym.sym == SDLK_PAGEDOWN) + { + //position_[2] -= 50.0; + Vector3 vec = position_; + vec[2] -= 50.0; + setPosition(vec); + } + break; + + case SDL_MOUSEMOTION: + { + Scalar xrel = cml::rad(Scalar(event.motion.xrel) / 5.0); + Scalar yrel = cml::rad(Scalar(event.motion.yrel) / 5.0); + + Quaternion rotation = rotation_; + + quaternion_rotate_about_world_x(rotation, yrel); + //rotation_.normalize(); + quaternion_rotate_about_world_y(rotation, xrel); + rotation.normalize(); + + setRotation(rotation); + break; + } + + case SDL_MOUSEBUTTONDOWN: + if (event.button.button == SDL_BUTTON_WHEELUP) + { + Vector3 vec = position_; + vec[2] += 50.0; + setPosition(vec); + } + else if (event.button.button == SDL_BUTTON_WHEELDOWN) + { + Vector3 vec = position_; + vec[2] -= 50.0; + setPosition(vec); + } + break; + } + + calculateSecondary(); +} + +void Camera::calculateSecondary() +{ + matrix_rotation_quaternion(transformation_, rotation_); + + Matrix4 translate; + matrix_translation(translate, position_); + + //transformation_ = translate * transformation_; + transformation_ *= translate; +} + + +} // namespace Mf + +/** vim: set ts=4 sw=4 tw=80: *************************************************/ + diff --git a/src/Moof/Camera.hh b/src/Moof/Camera.hh index 8800e3b..8b3b1da 100644 --- a/src/Moof/Camera.hh +++ b/src/Moof/Camera.hh @@ -29,14 +29,53 @@ #ifndef _MOOF_CAMERA_HH_ #define _MOOF_CAMERA_HH_ +#include +#include +#include + namespace Mf { class Camera { + void calculateSecondary(); + public: + Camera() : + position_(0.0, 0.0, 0.0) + { + quaternion_rotation_world_y(rotation_, 0.0); + srcRotation_ = rotation_; + dstRotation_ = rotation_; + calculateSecondary(); + } + + void setPosition(const Vector3& point); + void setRotation(const Quaternion& rotation); + + void lookAt(const Vector3& point); + + const Matrix4& getTransformation() const + { + return transformation_; + } + + void adjustFromInput(const Event& event); + + void update(Scalar t, Scalar dt); + private: + Vector3 position_; + Quaternion rotation_; + + Matrix4 transformation_; + + Lerpv3 pInterp_; + + Quaternion srcRotation_; + Quaternion dstRotation_; + Scalar tInterp_; }; diff --git a/src/Moof/Cullable.hh b/src/Moof/Cullable.hh index d543d0f..34a09b6 100644 --- a/src/Moof/Cullable.hh +++ b/src/Moof/Cullable.hh @@ -36,14 +36,16 @@ namespace Mf { /** - * Interface for anything that can be culled. This can include more than just - * frustrum culling. + * Interface for anything that can be culled. */ class Cullable { public: - virtual bool isVisible(const Camera& cam) = 0; + virtual bool isVisible(const Camera& cam) const + { + return true; + } }; diff --git a/src/Moof/Drawable.hh b/src/Moof/Drawable.hh index 8d93f05..1554b11 100644 --- a/src/Moof/Drawable.hh +++ b/src/Moof/Drawable.hh @@ -29,6 +29,7 @@ #ifndef _MOOF_DRAWABLE_HH_ #define _MOOF_DRAWABLE_HH_ +#include #include @@ -42,7 +43,7 @@ namespace Mf { class Drawable { public: - virtual void draw(Scalar alpha) = 0; + virtual void draw(Scalar alpha) const = 0; }; diff --git a/src/Moof/Profiler.hh b/src/Moof/Entity.hh similarity index 73% rename from src/Moof/Profiler.hh rename to src/Moof/Entity.hh index 40199df..738e137 100644 --- a/src/Moof/Profiler.hh +++ b/src/Moof/Entity.hh @@ -26,58 +26,42 @@ *******************************************************************************/ -#ifndef _MOOF_PROFILER_HH_ -#define _MOOF_PROFILER_HH_ +#ifndef _MOOF_ENTITY_HH_ +#define _MOOF_ENTITY_HH_ -/** - * @file Profiler.hh - * Braindead-simple profiler. - */ +#include -#include +#include +#include +#include namespace Mf { -class Profiler -{ + +/** + * Interface for game objects that can be drawn to the screen and half a + * specified size. + */ + +class Entity : public Drawable, public Cullable +{ public: - Profiler(const char* name = "") - { - start(name); - } - ~Profiler() + const Aabb& getAabb() const { - stop(); - } - - void start(const char* name = "") - { - begin = std::clock(); - std::cout << "Profiling " << name << "... "; + return aabb_; } - void stop() - { - if (begin == -1) return; - double elapsed = double(std::clock() - begin) / double(CLOCKS_PER_SEC); - std::cout << elapsed << " sec" << std::endl; - begin = -1; - } +protected: + Aabb aabb_; +}; - void cancel() - { - begin = -1; - } +typedef boost::shared_ptr EntityPtr; -private: - std::clock_t begin; -}; } // namespace Mf - -#endif // _MOOF_PROFILER_HH_ +#endif // _MOOF_ENTITY_HH_ /** vim: set ts=4 sw=4 tw=80: *************************************************/ diff --git a/src/Moof/Frustum.hh b/src/Moof/Frustum.hh new file mode 100644 index 0000000..82eba17 --- /dev/null +++ b/src/Moof/Frustum.hh @@ -0,0 +1,56 @@ + +/******************************************************************************* + + Copyright (c) 2009, Charles McGarvey + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*******************************************************************************/ + +#ifndef _MOOF_FRUSTUM_HH_ +#define _MOOF_FRUSTUM_HH_ + +#include + + +namespace Mf { + + +class Frustum +{ + Matrix4 projection; + //Plane left, right, bottom, top, near, far; + +public: + Frustum(Scalar l, Scalar r, Scalar b, Scalar t, Scalar n, Scalar f); + Frustum(Scalar fovy, Scalar aspect, Scalar near, Scalar far); + + const Matrix4& getMatrix() const; +}; + + +} // namespace Mf + +#endif // _MOOF_FRUSTUM_HH_ + +/** vim: set ts=4 sw=4 tw=80: *************************************************/ + diff --git a/src/Moof/Interpolator.hh b/src/Moof/Interpolator.hh index 87e3acd..2c33844 100644 --- a/src/Moof/Interpolator.hh +++ b/src/Moof/Interpolator.hh @@ -29,6 +29,8 @@ #ifndef _MOOF_INTERPOLATOR_HH_ #define _MOOF_INTERPOLATOR_HH_ +#include + namespace Mf { @@ -124,7 +126,7 @@ public: Interpolator::init(seconds, mode); calculate(0.0); // set value - calculate(0.0); // set previous + previous_ = value_; } void calculate(Scalar alpha) diff --git a/src/Moof/Octree.hh b/src/Moof/Octree.hh new file mode 100644 index 0000000..2ee617f --- /dev/null +++ b/src/Moof/Octree.hh @@ -0,0 +1,87 @@ + +/******************************************************************************* + + Copyright (c) 2009, Charles McGarvey + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*******************************************************************************/ + +#ifndef _MOOF_OCTREE_HH_ +#define _MOOF_OCTREE_HH_ + +#include + +#include + +#include +#include + + +namespace Mf { + + +class Entity; + + +class Octree +{ +public: + + class Node + { + Aabb aabb_; + Vector3 center_; + + std::list > objects_; + + public: + + Node() : + aabb_(-1.0, -1.0, -1.0, 1.0, 1.0, 1.0), + center_(0.0, 0.0, 0.0) {} + + Node(const Aabb& aabb) : + aabb_(aabb), + center_(aabb.getCenter()) {} + }; + + Octree() : + root_(new Tree()) {} + + Octree(const Aabb& aabb) : + root_(new Tree(Node(aabb))) {} + + + Tree::WeakPtr add(EntityPtr object); + +private: + Tree::Ptr root_; +}; + + +} // namespace Mf + +#endif // _MOOF_OCTREE_HH_ + +/** vim: set ts=4 sw=4 tw=80: *************************************************/ + diff --git a/src/Moof/OpenGL.cc b/src/Moof/OpenGL.cc index 6f223d1..e3e742b 100644 --- a/src/Moof/OpenGL.cc +++ b/src/Moof/OpenGL.cc @@ -31,9 +31,15 @@ #if USE_DOUBLE_PRECISION +void (*glGetScalarv)(GLenum, GLscalar*)(glGetDoublev); + void (*glLoadMatrix)(const GLscalar*)(glLoadMatrixd); void (*glMultMatrix)(const GLscalar*)(glMultMatrixd); +void (*glScale)(GLscalar, GLscalar, GLscalar)(glScaled); +void (*glRotate)(GLscalar, GLscalar, GLscalar, GLscalar)(glRotated); +void (*glTranslate)(GLscalar, GLscalar, GLscalar)(glTranslated); + void (*glColor3)(GLscalar, GLscalar, GLscalar)(glColor3d); void (*glColor4)(GLscalar, GLscalar, GLscalar, GLscalar)(glColor4d); void (*glColor3v)(const GLscalar*)(glColor3dv); @@ -48,9 +54,15 @@ void (*glVertex4v)(const GLscalar*)(glVertex4dv); #else +void (*glGetScalarv(GLenum, GLscalar*)(glGetFloatv); + void (*glLoadMatrix)(const GLscalar*)(glLoadMatrixf); void (*glMultMatrix)(const GLscalar*)(glMultMatrixf); +void (*glScale)(GLscalar, GLscalar, GLscalar)(glScalef); +void (*glRotate)(GLscalar, GLscalar, GLscalar, GLscalar)(glRotatef); +void (*glTranslate)(GLscalar, GLscalar, GLscalar)(glTranslatef); + void (*glVertex2)(GLscalar, GLscalar)(glVertex2f); void (*glVertex3)(GLscalar, GLscalar, GLscalar)(glVertex3f); void (*glVertex4)(GLscalar, GLscalar, GLscalar, GLscalar)(glVertex4f); diff --git a/src/Moof/OpenGL.hh b/src/Moof/OpenGL.hh index 6db55ce..657f05f 100644 --- a/src/Moof/OpenGL.hh +++ b/src/Moof/OpenGL.hh @@ -49,9 +49,15 @@ typedef GLfloat GLscalar; #endif +extern void (*glGetScalarv)(GLenum, GLscalar*); + extern void (*glLoadMatrix)(const GLscalar*); extern void (*glMultMatrix)(const GLscalar*); +extern void (*glScale)(GLscalar, GLscalar, GLscalar); +extern void (*glRotate)(GLscalar, GLscalar, GLscalar, GLscalar); +extern void (*glTranslate)(GLscalar, GLscalar, GLscalar); + extern void (*glColor3)(GLscalar, GLscalar, GLscalar); extern void (*glColor4)(GLscalar, GLscalar, GLscalar, GLscalar); extern void (*glColor3v)(const GLscalar*); diff --git a/src/Moof/Plane.hh b/src/Moof/Plane.hh new file mode 100644 index 0000000..797edc0 --- /dev/null +++ b/src/Moof/Plane.hh @@ -0,0 +1,51 @@ + +/******************************************************************************* + + Copyright (c) 2009, Charles McGarvey + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*******************************************************************************/ + +#ifndef _MOOF_PLANE_HH_ +#define _MOOF_PLANE_HH_ + +#include + + +namespace Mf { + + +class Plane +{ + Vector4 components; + +public: +}; + + +} // namespace Mf + +#endif // _MOOF_PLANE_HH_ + +/** vim: set ts=4 sw=4 tw=80: *************************************************/ + diff --git a/src/Moof/Scene.cc b/src/Moof/Scene.cc index 5f4a440..b8cb233 100644 --- a/src/Moof/Scene.cc +++ b/src/Moof/Scene.cc @@ -32,11 +32,11 @@ #include "Aabb.hh" #include "Camera.hh" -#include "Cullable.hh" #include "Deserializer.hh" -#include "Drawable.hh" +#include "Entity.hh" #include "Math.hh" #include "Mippleton.hh" +#include "Octree.hh" #include "OpenGL.hh" #include "Scene.hh" #include "Serializable.hh" @@ -48,7 +48,7 @@ namespace Mf { class Scene::SceneImpl : public Mippleton { - class Scenery : public Drawable, public Cullable + class Scenery : public Entity { public: Scenery(const Matrix4& transform, const std::string& textureName) : @@ -118,7 +118,7 @@ class Scene::SceneImpl : public Mippleton } } - void draw(Scalar alpha) + void draw(Scalar alpha) const { glPushMatrix(); //std::cout << "transforming..." << std::endl; @@ -195,16 +195,31 @@ class Scene::SceneImpl : public Mippleton { (*it).second->get(uScale); } + if ((it = rootObj.find("fog")) != rootObj.end()) + { + (*it).second->get(fog); + } + if ((it = rootObj.find("blend")) != rootObj.end()) + { + (*it).second->get(blending); + } } image.getTileCoords(index, texCoords); } - void draw(Scalar alpha) + void draw(Scalar alpha) const { glPushMatrix(); glMultMatrix(transformation.data()); + if (blending) + { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + /*if (fog) glEnable(GL_FOG);*/ + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); image.bind(); @@ -226,6 +241,9 @@ class Scene::SceneImpl : public Mippleton glEnd(); } + glDisable(GL_BLEND); + glDisable(GL_FOG); + glPopMatrix(); } @@ -253,7 +271,27 @@ class Scene::SceneImpl : public Mippleton if (numbers[0]->getNumber(num)) { - + theBox.min[0] = Scalar(num); + } + if (numbers[1]->getNumber(num)) + { + theBox.min[1] = Scalar(num); + } + if (numbers[2]->getNumber(num)) + { + theBox.min[2] = Scalar(num); + } + if (numbers[3]->getNumber(num)) + { + theBox.max[0] = Scalar(num); + } + if (numbers[4]->getNumber(num)) + { + theBox.max[1] = Scalar(num); + } + if (numbers[5]->getNumber(num)) + { + theBox.max[2] = Scalar(num); } } } @@ -268,6 +306,10 @@ public: loadFromFile(); } + ~SceneImpl() + { + } + void loadInstructions(SerializablePtr root) { @@ -289,7 +331,6 @@ public: if (instruction == "reset_transform") { transform.identity(); - //std::cout << "===================RESET=====================" << std::endl; } else if (instruction == "translate") { @@ -313,8 +354,6 @@ public: Matrix4 translation; cml::matrix_translation(translation, vec); transform = translation * transform; - //std::cout << "TRANSLATE\t" << vec << std::endl - //<< transform << std::endl; } } else if (instruction == "scale") @@ -333,8 +372,6 @@ public: Matrix4 scaling; cml::matrix_uniform_scale(scaling, Scalar(value)); transform = scaling * transform; - //std::cout << "SCALE\t\t" << value << std::endl - //<< transform << std::endl; } else if (values.size() == 3) { @@ -353,8 +390,6 @@ public: Matrix4 scaling; cml::matrix_scale(scaling, vec); transform = scaling * transform; - //std::cout << "SCALE\t\t" << vec << std::endl - //<< transform << std::endl; } } } @@ -370,28 +405,30 @@ public: std::string axis; size_t axisIndex = 0; double value = 0.0; + Vector3 vec(0.0, 0.0, 0.0); if (values[0]->get(axis)) { if (axis == "x") { axisIndex = 0; + vec[0] = 1.0; } else if (axis == "y") { axisIndex = 1; + vec[1] = 1.0; } else if (axis == "z") { axisIndex = 2; + vec[2] = 1.0; } values[1]->getNumber(value); } - cml::matrix_rotate_about_local_axis(transform, + cml::matrix_rotate_about_world_axis(transform, axisIndex, Scalar(value * cml::constantsd::rad_per_deg())); - //std::cout << "ROTATE\t" << axis << " " << value << std::endl - //<< transform << std::endl; } } } @@ -402,9 +439,6 @@ public: } else if (instruction == "tilemap") { - //std::cout << "TILEMAP\t" << texture<< std::endl; - //std::cout << transform << std::endl; - it++; TilePanel* tilePanel = new TilePanel(transform, texture, *it); @@ -413,9 +447,6 @@ public: } else if (instruction == "billboard") { - //std::cout << "BILLBOARD\t" << texture << std::endl; - //std::cout << transform << std::endl; - it++; Billboard* billboard = new Billboard(transform, texture, *it); @@ -458,6 +489,9 @@ public: } } } + + std::cout << "playfield: " << playfieldBounds.min << " ... " << + playfieldBounds.max << std::endl; } @@ -470,6 +504,14 @@ public: //std::cout << "draw object"; (*it)->draw(alpha); } + + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + + glBindTexture(GL_TEXTURE_2D, 0); + glColor4f(0.0f, 1.0f, 0.0f, 1.0f); + playfieldBounds.draw(0.0); + + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } @@ -486,12 +528,18 @@ Scene::Scene(const std::string& name) : impl_(Scene::SceneImpl::retain(name), &Scene::SceneImpl::release) {} -void Scene::draw(Scalar alpha) +void Scene::draw(Scalar alpha) const { // pass through impl_->draw(alpha); } +void Scene::refresh() +{ + impl_->objects.clear(); + impl_->loadFromFile(); +} + /** * Specialized search location for scene files. They can be found in the diff --git a/src/Moof/Scene.hh b/src/Moof/Scene.hh index 66a54a9..db25db7 100644 --- a/src/Moof/Scene.hh +++ b/src/Moof/Scene.hh @@ -45,7 +45,8 @@ class Scene : public Resource, public Drawable public: Scene(const std::string& name); - void draw(Scalar alpha); + void draw(Scalar alpha) const; + void refresh(); static std::string getPathToResource(const std::string& name); diff --git a/src/Moof/Texture.cc b/src/Moof/Texture.cc index 8bd3c4a..128d54f 100644 --- a/src/Moof/Texture.cc +++ b/src/Moof/Texture.cc @@ -396,7 +396,7 @@ Texture::Texture(const std::string& name) : * Bind the GL texture for mapping, etc. */ -void Texture::bind() +void Texture::bind() const { // pass through impl_->bind(); @@ -407,20 +407,20 @@ void Texture::bind() * Get the texture object, for the curious. */ -GLuint Texture::getObject() +GLuint Texture::getObject() const { // pass through return impl_->object_; } -unsigned Texture::getWidth() +unsigned Texture::getWidth() const { // pass through return impl_->width_; } -unsigned Texture::getHeight() +unsigned Texture::getHeight() const { // pass through return impl_->height_; diff --git a/src/Moof/Texture.hh b/src/Moof/Texture.hh index 2ab4710..d2b2359 100644 --- a/src/Moof/Texture.hh +++ b/src/Moof/Texture.hh @@ -50,11 +50,11 @@ class Texture : public Resource public: Texture(const std::string& name); - void bind(); - GLuint getObject(); + void bind() const; + GLuint getObject() const; - unsigned getWidth(); - unsigned getHeight(); + unsigned getWidth() const; + unsigned getHeight() const; void setMinFilter(GLuint filter); void setMagFilter(GLuint filter); diff --git a/src/Moof/Tilemap.cc b/src/Moof/Tilemap.cc index 1bfbfbc..9f24b1b 100644 --- a/src/Moof/Tilemap.cc +++ b/src/Moof/Tilemap.cc @@ -175,7 +175,7 @@ Tilemap::Tilemap(const std::string& name) : } -bool Tilemap::getTileCoords(unsigned index, Scalar coords[8]) +bool Tilemap::getTileCoords(unsigned index, Scalar coords[8]) const { // make sure the index represents a real tile if (index >= impl_->nTilesS_ * impl_->nTilesT_) return false; @@ -197,7 +197,7 @@ bool Tilemap::getTileCoords(unsigned index, Scalar coords[8]) } bool Tilemap::getTileCoords(unsigned index, Scalar coords[8], - Orientation orientation) + Orientation orientation) const { if (getTileCoords(index, coords)) { diff --git a/src/Moof/Tilemap.hh b/src/Moof/Tilemap.hh index d8708f1..f056886 100644 --- a/src/Moof/Tilemap.hh +++ b/src/Moof/Tilemap.hh @@ -82,7 +82,7 @@ public: * @return True if index is valid, false otherwise. */ - bool getTileCoords(Index index, Scalar coords[8]); + bool getTileCoords(Index index, Scalar coords[8]) const; /** @@ -93,7 +93,7 @@ public: * @return True if index is valid, false otherwise. */ - bool getTileCoords(Index index, Scalar coords[8], Orientation what); + bool getTileCoords(Index index, Scalar coords[8], Orientation what) const; static std::string getPathToResource(const std::string& name); diff --git a/src/Moof/Tree.hh b/src/Moof/Tree.hh new file mode 100644 index 0000000..2b5fdb8 --- /dev/null +++ b/src/Moof/Tree.hh @@ -0,0 +1,156 @@ + +/******************************************************************************* + + Copyright (c) 2009, Charles McGarvey + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +*******************************************************************************/ + +#ifndef _MOOF_TREE_HH_ +#define _MOOF_TREE_HH_ + +#include +#include + + +namespace Mf { + + +template +class Tree +{ +public: + typedef boost::shared_ptr Ptr; + typedef boost::weak_ptr WeakPtr; + +private: + WeakPtr parent_; + WeakPtr prevSibling_; + Ptr next_; + WeakPtr lastDescendant_; + +public: + + T data; + + Tree() {} + Tree(const T& item) : + data(item) {} + + inline Ptr next() const + { + return next_; + } + + inline Ptr prev() const + { + Ptr parent = parent_.lock(); + + if (parent) + { + if (parent->next_.get() == this) + { + return parent; + } + else + { + return prevSibling_.lock()->lastDescendant_.lock(); + } + } + + return Ptr(); + } + + inline Ptr firstChild() const + { + if (next_ && next_->parent_.lock().get() == this) + { + return next_; + } + + return Ptr(); + } + + inline Ptr lastChild() const + { + Ptr child = firstChild(); + + if (child) + { + child = child->prevSibling_.lock(); + } + + return child; + } + + inline Ptr nextSibling() const + { + Ptr sibling = lastDescendant_.lock()->next_; + + if (sibling && sibling->parent_.lock() != parent_.lock()) + { + return Ptr(); + } + + return sibling; + } + + inline Ptr prevSibling() const + { + Ptr parent = parent_.lock(); + + if (parent && parent->next_.get() != this) + { + return prevSibling_.lock(); + } + + return Ptr(); + } + + + class Iterator + { + Ptr current; + + public: + + }; + + + void insert() + { + } + + void remove() + { + } + +}; + + +} // namespace Mf + +#endif // _MOOF_TREE_HH_ + +/** vim: set ts=4 sw=4 tw=80: *************************************************/ + diff --git a/src/YoinkApp.cc b/src/YoinkApp.cc index 232c097..023b3a3 100644 --- a/src/YoinkApp.cc +++ b/src/YoinkApp.cc @@ -50,6 +50,7 @@ static std::string configFiles() std::string files; char* configFile = getenv("YOINKRC"); + char* dataDir = getenv("YOINK_DATADIR"); if (configFile) { @@ -59,8 +60,23 @@ static std::string configFiles() files += ":"; } + // add the colon-delimited paths from configure files += YOINK_CONFIGFILES; + if (dataDir) + { + // if another data directory is set in the environment, look for a + // config file there + files += ":"; + files += dataDir; + files += "/yoinkrc"; + } + + // look in the configured data directory last of all + files += ":"; + files += (dataDir ? dataDir : YOINK_DATADIR); + files += "/yoinkrc"; + return files; } @@ -71,8 +87,11 @@ static std::string iconFile() // first set up the search paths so we can find the icon and other resources if (dataDir) { + // look first in the data directory specified by the environment Mf::Resource::addSearchPath(dataDir); } + + // then look in the configured data directory Mf::Resource::addSearchPath(YOINK_DATADIR); return Mf::Resource::getPathToResource("yoink.png"); @@ -125,7 +144,7 @@ void YoinkApp::setupGL() glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); - glEnable(GL_POLYGON_SMOOTH); + //glEnable(GL_POLYGON_SMOOTH); //int texSize; //glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize); @@ -138,6 +157,10 @@ void YoinkApp::setupGL() glClearColor(1.0, 0.0, 0.0, 1.0); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60.0, 1.33333, 1.0, 2500.0); + //glLineWidth(10.0f); } @@ -155,6 +178,8 @@ void YoinkApp::update(Mf::Scalar t, Mf::Scalar dt) fadeIn.update(dt); + camera.update(t, dt); + someChar->getAnimation().update(t, dt); interp.update(dt); @@ -177,16 +202,13 @@ void YoinkApp::draw(Mf::Scalar alpha) - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(60.0, 1.33333, 1.0, 2000.0); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + //glLoadIdentity(); glBindTexture(GL_TEXTURE_2D, 0); //glRotatef(drawstate*15.0f, 0.0, 1.0, 0.0); - glTranslatef(x, y, z); + //glTranslatef(x, y, z); + glLoadMatrix(camera.getTransformation().data()); // DRAW THE SCENE testScene->draw(alpha); @@ -327,30 +349,43 @@ void YoinkApp::handleEvent(const Mf::Event& event) { someChar->getAnimation().startSequence("Punch"); } - else if (event.key.keysym.sym == SDLK_RIGHT) - { - x -= 50.0; - } - else if (event.key.keysym.sym == SDLK_LEFT) - { - x += 50.0; - } - else if (event.key.keysym.sym == SDLK_UP) - { - y -= 50.0; - } - else if (event.key.keysym.sym == SDLK_DOWN) + else if (event.key.keysym.sym == SDLK_r) { - y += 50.0; + testScene->refresh(); } - else if (event.key.keysym.sym == SDLK_PAGEUP) + else if (event.key.keysym.sym == SDLK_l) { - z += 50.0; - } - else if (event.key.keysym.sym == SDLK_PAGEDOWN) - { - z -= 50.0; + getVideo().toggleCursorGrab(); + getVideo().toggleCursorVisible(); } + //else if (event.key.keysym.sym == SDLK_RIGHT) + //{ + //x -= 50.0; + //} + //else if (event.key.keysym.sym == SDLK_LEFT) + //{ + //x += 50.0; + //} + //else if (event.key.keysym.sym == SDLK_UP) + //{ + //y -= 50.0; + //} + //else if (event.key.keysym.sym == SDLK_DOWN) + //{ + //y += 50.0; + //} + //else if (event.key.keysym.sym == SDLK_PAGEUP) + //{ + //z += 50.0; + //} + //else if (event.key.keysym.sym == SDLK_PAGEDOWN) + //{ + //z -= 50.0; + //} + + case SDL_MOUSEMOTION: + case SDL_MOUSEBUTTONDOWN: + camera.adjustFromInput(event); break; case SDL_QUIT: @@ -359,11 +394,20 @@ void YoinkApp::handleEvent(const Mf::Event& event) case SDL_VIDEORESIZE: glViewport(0, 0, event.resize.w, event.resize.h); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + + gluPerspective(60.0, double(event.resize.w / event.resize.h), 1.0, 2500.0); + + glMatrixMode(GL_MODELVIEW); break; } } +#include int main(int argc, char* argv[]) { @@ -374,6 +418,10 @@ int main(int argc, char* argv[]) int status = 0; + //Mf::Tree myTree; + //Mf::Tree::Ptr prev = myTree.previousSibling(); + //myTree = *prev; + try { YoinkApp app(argc, argv); diff --git a/src/YoinkApp.hh b/src/YoinkApp.hh index 19564b5..66406d2 100644 --- a/src/YoinkApp.hh +++ b/src/YoinkApp.hh @@ -37,6 +37,7 @@ #include #include +#include #include #include #include @@ -70,6 +71,7 @@ private: Mf::Cerpv2 interp; Mf::Lerps fadeIn; + Mf::Camera camera; Mf::Scene* testScene; Mf::Scalar x, y, z;