]> Dogcows Code - chaz/yoink/commitdiff
game loop tweaks; shapes hierarchy defined
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sat, 30 Jan 2010 05:04:31 +0000 (22:04 -0700)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sat, 30 Jan 2010 05:04:31 +0000 (22:04 -0700)
21 files changed:
data/yoinkrc
src/Character.cc
src/GameLayer.cc
src/GameLayer.hh
src/Hud.cc
src/Hud.hh
src/Makefile.am
src/Moof/Aabb.cc [deleted file]
src/Moof/Aabb.hh
src/Moof/Core.cc
src/Moof/Frustum.hh
src/Moof/Line.hh
src/Moof/OpenGL.hh
src/Moof/Plane.hh
src/Moof/Ray.hh
src/Moof/Rectangle.cc [deleted file]
src/Moof/Rectangle.hh [deleted file]
src/Moof/Shape.hh
src/Moof/Sphere.hh
src/Scene.cc
src/Scene.hh

index de65603a99c3b37ebec77d24b5f1f38805b1bad9..bf5bc83b0f621f22647bc81f10a494e74ac06764 100644 (file)
@@ -56,19 +56,21 @@ resizable           = true
 
 --videomode            = {800, 600}
 
--- Set this to make the cursor remain visible as you mouse over the view of
--- the game.
+-- Set this to make the cursor remain visible as you mouse over the video
+-- output of the game.
 
-showcursor             = true
+showcursor             = false
 
 -- Set this to use double-buffering to improve animation quality.  You
--- should usually leave this as true.
+-- really don't want to turn this off.
 
 doublebuffer   = true
 
 -- Set this to sync with the refresh rate of your display.  Your framerate
--- will be limited to the refresh rate, but you may experience fewer ugly
--- "artifacts" caused by the game animation.
+-- will be limited to the refresh rate, but you may experience less
+-- tearing caused by the display vertical refresh.  On the other hand, you
+-- might experience worse tearing, depending on your setup.  Try it both
+-- ways.
 
 swapcontrol            = true
 
index 6a7c69883ea6ddeeda7f8ec77f9c806f0b76c080..840099c8fcd97cd1cffb17d7a9010a635d0c383f 100644 (file)
@@ -30,8 +30,7 @@ public:
 
                // spring:
                //mState.force += -15.0 * x - 1.5 * mState.velocity;
-               force = SCALAR(-10.0) * (mag - d) * (x / mag) -
-                               SCALAR(2.0) * state.velocity;
+               force = SCALAR(-10.0) * (mag - d) * (x / mag);// - SCALAR(2.0) * state.velocity;
 
                return force;
        }
@@ -73,8 +72,8 @@ Character::Character(const std::string& name) :
 
        // forces
        mState.force = Mf::Vector2(0.0, 0.0);
-       //mState.forces.push_back(SpringForce(Mf::Vector2(20.0, 4.0)));
-       mState.forces.push_back(ResistanceForce(2.0));
+       //mState.forces.push_back(SpringForce(Mf::Vector2(5.0, 4.0)));
+       //mState.forces.push_back(ResistanceForce(2.0));
        //mState.forces.push_back(Mf::LinearState<2>::GravityForce(-9.8));
 
        // starting position
index 3a0ea09eba80e44fb81dda883975bf5bd1c66f43..331d04fbc9db98f81d02ba12a3c07c9fea618fed 100644 (file)
@@ -114,7 +114,7 @@ GameLayer::GameLayer() :
 }
 
 
-void GameLayer::pushedOntoEngine()
+void GameLayer::addedToCore()
 {
        Mf::core.push(mHud);
 
@@ -123,8 +123,8 @@ void GameLayer::pushedOntoEngine()
        mLine.a.set(20, 10);
        mLine.b.set(19, 14);
 
-       mSphere.point.set(22, 5);
-       mSphere.radius = 2;
+       mCircle.point.set(22, 5);
+       mCircle.radius = 2;
 
        mRayTimer.init(boost::bind(&GameLayer::rayTimer, this),
                                   1.0, Mf::Timer::REPEAT);
@@ -155,8 +155,8 @@ void GameLayer::thinkTimer()
 
 void GameLayer::rayTimer()
 {
-       Mf::Ray<2>::Intersection meh;
-       std::list<Mf::Ray<2>::Intersection> hits;
+       Mf::Ray2::Contact meh;
+       std::list<Mf::Ray2::Contact> hits;
        Mf::Vector2 point;
 
        bool bam = mLine.intersectRay(mRay, meh);
@@ -166,7 +166,7 @@ void GameLayer::rayTimer()
                hits.push_back(meh);
        }
 
-       bam = mSphere.intersectRay(mRay, meh);
+       bam = mCircle.intersectRay(mRay, meh);
        if (bam)
        {
                meh.normal.normalize();
@@ -177,9 +177,9 @@ void GameLayer::rayTimer()
        {
                hits.front().normal.normalize();
                mRay.solve(point, hits.front().distance);
-               //Mf::logInfo << "scene: d = " << hits.front().distance << std::endl;
-               //Mf::logInfo << "       P = " << point << std::endl;
-               //Mf::logInfo << "       n = " << hits.front().normal << std::endl;
+               Mf::logInfo << "scene: d = " << hits.front().distance << std::endl;
+               Mf::logInfo << "       P = " << point << std::endl;
+               Mf::logInfo << "       n = " << hits.front().normal << std::endl;
        }
 }
 
@@ -195,12 +195,11 @@ void GameLayer::draw(Mf::Scalar alpha) const
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
 
        mState.scene->drawIfVisible(alpha, mState.camera.getFrustum());
-
        mState.heroine->draw(alpha);
 
        mRay.draw();
        mLine.draw();
-       mSphere.draw();
+       mCircle.draw();
 }
 
 bool GameLayer::handleEvent(const Mf::Event& event)
index 885a49daa3392d07de25369573c9f5112b3a005b..c537af6391569230118af2ee7ff72f086b5f3d1f 100644 (file)
@@ -51,7 +51,7 @@ public:
                return GameLayerP(new GameLayer);
        }
 
-       void pushedOntoEngine();
+       void addedToCore();
 
        void update(Mf::Scalar t, Mf::Scalar dt);
        void draw(Mf::Scalar alpha) const;
@@ -75,9 +75,9 @@ private:
        Mf::SoundStream mMusic;
        Mf::Sound               mPunchSound;
 
-       Mf::Ray<2>              mRay;
-       Mf::Line<2>             mLine;
-       Mf::Sphere<2>   mSphere;
+       Mf::Ray2                mRay;
+       Mf::Line2               mLine;
+       Mf::Circle              mCircle;
 
        Mf::Timer               mRayTimer;
        void rayTimer();
index 9e40a601a859f15f9a89a4243a008b0879bb3559..f4134cf737fd468acee3b76acc5a3166bfc00611 100644 (file)
@@ -9,7 +9,9 @@
 *
 **************************************************************************/
 
+#include <Moof/Aabb.hh>
 #include <Moof/Core.hh>
+#include <Moof/Log.hh>
 #include <Moof/OpenGL.hh>
 #include <Moof/Video.hh>
 
@@ -30,11 +32,12 @@ ProgressBar::ProgressBar(const Mf::Texture& tilemap,
 
 void ProgressBar::resize(const Mf::Rectangle& rect)
 {
+       Mf::logInfo << "rect: " << rect.min << ", " << rect.max << std::endl;
        Mf::Scalar height = rect.max[1] - rect.min[1];
        Mf::Scalar halfHeight = height / 2.0;
 
        mWidth = rect.max[0] - rect.min[0] - height;
-       // assert width > 0
+       ASSERT(mWidth > 0);
 
        mVertices[0] = rect.min;
        mVertices[1] = Mf::Vector2(rect.min[0] + halfHeight, rect.min[1]);
@@ -122,10 +125,8 @@ void Hud::resize(int width, int height)
                        SCALAR(1.0), SCALAR(-1.0), cml::z_clip_neg_one);
 
        // position the two progress bars at the top-left of the screen
-       mBar1.resize(Mf::Rectangle(20, height - 51,
-                               0.7 * width, height - 3));
-       mBar2.resize(Mf::Rectangle(20, height - 28,
-                               0.7 * width, height - 70));
+       mBar1.resize(Mf::Rectangle(20, height - 51, 0.7 * width, height - 3));
+       mBar2.resize(Mf::Rectangle(20, height - 28, 0.7 * width, height - 70));
 
        setBar1Progress(0.05);
        setBar2Progress(0.0);
@@ -174,6 +175,7 @@ bool Hud::handleEvent(const Mf::Event& event)
                        {
                                // don't want the hud anymore
                                Mf::core.pop(this);
+                               Mf::logWarning("okay bye bye hud");
                                return true;
                        }
                        break;
index 30b5a42be36cae2d195372d6c762399dd59d34c0..bc8a313100e79d30315640e2eaac6ec78aab077f 100644 (file)
 #include <Moof/Drawable.hh>
 #include <Moof/Layer.hh>
 #include <Moof/Math.hh>
-#include <Moof/Rectangle.hh>
+//#include <Moof/Rectangle.hh>
 #include <Moof/Texture.hh>
 
 #include "GameState.hh"
 
 
+class Rectangle;
+
 // TODO this stuff is still just hacked up
 
 class ProgressBar : public Mf::Drawable
index 45ea7cdd6fde36fe917d9c2390b0195a46e86c7e..4e8f65d0b26b0f47d252050332843f7e227426cd 100644 (file)
@@ -12,7 +12,6 @@
 noinst_LIBRARIES = libmoof.a
 
 libmoof_a_SOURCES = \
-                                       Moof/Aabb.cc \
                                        Moof/Aabb.hh \
                                        Moof/Camera.cc \
                                        Moof/Camera.hh \
@@ -46,8 +45,6 @@ libmoof_a_SOURCES = \
                                        Moof/Plane.cc \
                                        Moof/Plane.hh \
                                        Moof/Ray.hh \
-                                       Moof/Rectangle.cc \
-                                       Moof/Rectangle.hh \
                                        Moof/Resource.cc \
                                        Moof/Resource.hh \
                                        Moof/RigidBody.hh \
diff --git a/src/Moof/Aabb.cc b/src/Moof/Aabb.cc
deleted file mode 100644 (file)
index 4ef1520..0000000
+++ /dev/null
@@ -1,71 +0,0 @@
-
-/*]  Copyright (c) 2009-2010, Charles McGarvey  [**************************
-**]  All rights reserved.
-*
-* vi:ts=4 sw=4 tw=75
-*
-* Distributable under the terms and conditions of the 2-clause BSD license;
-* see the file COPYING for a complete text of the license.
-*
-**************************************************************************/
-
-#include "Aabb.hh"
-#include "Frustum.hh"
-#include "OpenGL.hh"
-#include "Texture.hh"
-
-
-namespace Mf {
-
-
-       /*
-void Aabb::getOctant(Aabb& octant, int num) const
-{
-       Vector3 mid = getCenter();
-
-       switch (num)
-       {
-               case 0:
-                       octant.init(Vector3(min[0], min[1], mid[2]),
-                                               Vector3(mid[0], mid[1], max[2]));
-                       break;
-
-               case 1:
-                       octant.init(Vector3(mid[0], min[1], mid[2]),
-                                               Vector3(max[0], mid[1], max[2]));
-                       break;
-
-               case 2:
-                       octant.init(mid, max);
-                       break;
-
-               case 3:
-                       octant.init(Vector3(min[0], mid[1], mid[2]),
-                                               Vector3(mid[0], max[1], max[2]));
-                       break;
-
-               case 4:
-                       octant.init(min, mid);
-                       break;
-
-               case 5:
-                       octant.init(Vector3(mid[0], min[1], min[2]),
-                                               Vector3(max[0], mid[1], mid[2]));
-                       break;
-
-               case 6:
-                       octant.init(Vector3(mid[0], mid[1], min[2]),
-                                               Vector3(max[0], max[1], mid[2]));
-                       break;
-
-               case 7:
-                       octant.init(Vector3(min[0], mid[1], min[2]),
-                                               Vector3(mid[0], max[1], mid[2]));
-                       break;
-       }
-}
-*/
-
-
-} // namespace Mf
-
index f3e92ab471c8b48701a19cf8e61a4427c66a46ab..8fcdbc3787114aca620ba3bdf832698d119f66f3 100644 (file)
@@ -38,6 +38,7 @@ struct Aabb : public Cullable, public Drawable, public Shape<D>
        Vector min;
        Vector max;
 
+
        Aabb() {}
 
        Aabb(const Vector& a, const Vector& b)
@@ -45,16 +46,48 @@ struct Aabb : public Cullable, public Drawable, public Shape<D>
                init(a, b);
        }
 
-       Aabb(Scalar ax, Scalar ay, Scalar az,
-                       Scalar bx, Scalar by, Scalar bz)
+       Aabb(Scalar x1, Scalar y1, Scalar x2, Scalar y2)
        {
-               Vector a(ax, ay, az);
-               Vector b(bx, by, bz);
+               Vector a(x1, y1);
+               Vector b(x2, y2);
 
                init(a, b);
        }
 
-       void init(const Vector& a, const Vector& b)
+       Aabb(Scalar x1, Scalar y1, Scalar z1, Scalar x2, Scalar y2, Scalar z2)
+       {
+               Vector a(x1, y1, z1);
+               Vector b(x2, y2, z2);
+
+               init(a, b);
+       }
+
+
+       void init(const Vector2& a, const Vector2& 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];
+               }
+       }
+
+       void init(const Vector3& a, const Vector3& b)
        {
                if (a[0] < b[0])
                {
@@ -88,19 +121,17 @@ struct Aabb : public Cullable, public Drawable, public Shape<D>
                }
        }
 
+
        Vector getCenter() const
        {
-               return Vector((min[0] + max[0]) / 2.0,
-                                          (min[1] + max[1]) / 2.0,
-                                          (min[2] + max[2]) / 2.0);
+               return (min + max) / 2.0;
        }
 
-       //void getOctant(Aabb& octant, int num) const;
 
        Plane getPlaneXY() const
        {
                Plane plane;
-               plane.normal = Vector(0.0, 0.0, 1.0);
+               plane.normal = Vector3(0.0, 0.0, 1.0);
                plane.d = cml::dot(-plane.normal, getCenter());
                return plane;
        }
@@ -108,7 +139,7 @@ struct Aabb : public Cullable, public Drawable, public Shape<D>
        Plane getPlaneXZ() const
        {
                Plane plane;
-               plane.normal = Vector(0.0, 1.0, 0.0);
+               plane.normal = Vector3(0.0, 1.0, 0.0);
                plane.d = cml::dot(-plane.normal, getCenter());
                return plane;
        }
@@ -116,22 +147,21 @@ struct Aabb : public Cullable, public Drawable, public Shape<D>
        Plane getPlaneYZ() const
        {
                Plane plane;
-               plane.normal = Vector(1.0, 0.0, 0.0);
+               plane.normal = Vector3(1.0, 0.0, 0.0);
                plane.d = cml::dot(-plane.normal, getCenter());
                return plane;
        }
 
-       /*
-       void getCorners(Vector3 corners[8]) const;
-
-       void encloseVertices(const Vector3 vertices[], unsigned count);
-
-       void draw(Scalar alpha = 0.0) const;
-       bool isVisible(const Frustum& frustum) const;
-       */
 
+       void getCorners(Vector2 corners[4]) const
+       {
+               corners[0][0] = min[0]; corners[0][1] = min[1];
+               corners[1][0] = max[0]; corners[1][1] = min[1];
+               corners[2][0] = max[0]; corners[2][1] = max[1];
+               corners[3][0] = min[0]; corners[3][1] = max[1];
+       }
 
-       void getCorners(Vector corners[8]) const
+       void getCorners(Vector3 corners[8]) const
        {
                corners[0][0] = min[0];
                corners[0][1] = min[1];
@@ -175,45 +205,63 @@ struct Aabb : public Cullable, public Drawable, public Shape<D>
 
        void draw(Scalar alpha = 0.0) 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 indices[] = {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);
-               glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-               glVertexPointer(3, GL_SCALAR, 0, vertices);
-
-               glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-               Texture::resetBind();
-
-               glDrawElements(GL_QUADS, sizeof(indices), GL_UNSIGNED_BYTE,
-                                          indices);
-
-               glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-               //glDisableClientState(GL_VERTEX_ARRAY);
-
-               glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+               glRect(min[0], min[1], max[0], max[1]);
        }
 
        bool isVisible(const Frustum& frustum) const
        {
-               return frustum.contains(*this);
+               return true;
        }
 };
 
 
+template <>
+inline void Aabb<3>::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 indices[] = {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);
+       glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+       glVertexPointer(3, GL_SCALAR, 0, vertices);
+
+       glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+       Texture::resetBind();
+
+       glDrawElements(GL_QUADS, sizeof(indices), GL_UNSIGNED_BYTE,
+                                  indices);
+
+       glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+       //glDisableClientState(GL_VERTEX_ARRAY);
+
+       glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+}
+
+template <>
+inline bool Aabb<3>::isVisible(const Frustum& frustum) const
+{
+       return frustum.contains(*this);
+}
+
+
+typedef Aabb<2>                Aabb2;
+typedef Aabb2          Rectangle;
+typedef Aabb<3>                Aabb3;
+
+
 } // namespace Mf
 
 #endif // _MOOF_AABB_HH_
index b9ad92a63a8e29e8c7f59e1e6cc310a03bca5b36..b659f9890784c2c66cdc867b91671914d0f5260c 100644 (file)
@@ -70,6 +70,7 @@ public:
        void run()
        {
                init();
+               ASSERT(video && "cannot run core without a current video context");
 
                Scalar totalTime = 0.0;
                Scalar ticks = Timer::getTicks();
@@ -79,49 +80,50 @@ public:
                Scalar nextSecond = ticks + SCALAR(1.0);
 
                mFps = 0;
-               int frames = 0;
+               int frameCount = 0;
 
-               const int MAX_FRAMESKIP = 15;
-               const Scalar inverseTimestep = SCALAR(1.0) / mTimestep;
+               const Scalar timestep = mTimestep;
+               const Scalar framerate = mFramerate;
 
-               ASSERT(video && "cannot run core without a current video context");
+               const int MAX_FRAMESKIP = 15;
+               const Scalar inverseTimestep = SCALAR(1.0) / timestep;
 
                do
                {
-                       Timer::fireIfExpired();
-                       dispatchEvents();
+                       Timer::fireIfExpired();                         // 1. fire timers
+                       dispatchEvents();                                       // 2. dispatch events
 
                        int i = 0;
                        while (nextUpdate < Timer::getTicks() && i < MAX_FRAMESKIP)
                        {
-                               totalTime += mTimestep;
-                               update(totalTime, mTimestep);
+                               totalTime += timestep;
+                               update(totalTime, timestep);    // 3. update state
 
-                               nextUpdate += mTimestep;
+                               nextUpdate += timestep;
                                ++i;
                        }
 
                        if (nextDraw < (ticks = Timer::getTicks()))
                        {
-                               ++frames;
-                               draw((ticks + mTimestep - nextUpdate) * inverseTimestep);
-                               video->swap();
+                               draw((ticks + timestep - nextUpdate) * inverseTimestep);
+                               video->swap();                                  // 4. draw state
 
-                               nextDraw += mFramerate;
+                               nextDraw += framerate;
+                               ++frameCount;
 
-                               if (mShowFps && nextSecond < ticks)
+                               if (nextSecond < Timer::getTicks())
                                {
-                                       mFps = frames;
-                                       frames = 0;
+                                       mFps = frameCount;
+                                       frameCount = 0;
 
-                                       logInfo << mFps << " fps" << std::endl;
+                                       if (mShowFps) logInfo << mFps << " fps" << std::endl;
 
                                        nextSecond += SCALAR(1.0);
                                }
                        }
 
-                       // be a good citizen and give back what you don't need
-                       Timer::sleep(0.0);
+                       ticks = Timer::getTicks();                      // 5. yield timeslice
+                       if (ticks < nextUpdate && ticks < nextDraw) Timer::sleep(0.0);
                }
                while (!mStack.empty());
 
index 6e93cd6c87f8c675ca61ff4f3dc820ee9b57a1f5..5710004c58989115622b779fedfcdfb9096279c3 100644 (file)
@@ -44,7 +44,7 @@ public:
        {
                init(modelview, fovy, aspect, abutting, distant);
        }
-       
+
        void init(const Matrix4& modelview, const Matrix4& projection);
        void init(const Matrix4& modelview, Scalar fovy, Scalar aspect,
                          Scalar abutting, Scalar distant);
index 7902ea90d969e2a6c7170f9f970c25f215613eb1..f8a2b66111f34a6de84a480fe461cd118064b77e 100644 (file)
@@ -38,7 +38,7 @@ struct Line : public Drawable, public Shape<D>
                a(point1),
                b(point2) {}
 
-       bool intersectRay(const Ray<2>& ray, Ray<2>::Intersection& hit) const
+       bool intersectRay(const Ray<2>& ray, Ray<2>::Contact& hit) const
        {
                // solve: Cx + r*Dx = Ax + s(Bx - Ax)
                //        Cy + r*Dy = Ay + s(By - Ay)
@@ -79,6 +79,8 @@ struct Line : public Drawable, public Shape<D>
                hit.distance = -(a[0] * (ray.point[1] - b[1]) +
                                                 b[0] * (a[1] - ray.point[1]) +
                                                 ray.point[0] * (b[1] - a[1])) / denom;
+
+               // check if the intersection is behind the ray
                if (hit.distance < SCALAR(0.0)) return false;
 
                Vector normal = cml::perp(a - b);
@@ -98,15 +100,41 @@ struct Line : public Drawable, public Shape<D>
 };
 
 
+typedef Line<2>                Line2;
+typedef Line<3>                Line3;
+
+
 template <int D, int N>
-struct Polygon : public Shape<D>
+struct Polygon : public Drawable, public Shape<D>
 {
        typedef cml::vector< Scalar, cml::fixed<D> > Vector;
 
        Vector  points[N];
+
+       Polygon() {}
+
+       bool intersectRay(const Ray<D>& ray, typename Ray<D>::Contact& hit)
+       {
+               return false;
+       }
+
+       void draw(Scalar alpha = 0.0) const
+       {
+               Mf::Texture::resetBind();
+               glBegin(GL_POLYGON);
+               for (int i = 0; i < D; ++i)
+               {
+                       glVertex(points[0]);
+               }
+               glEnd();
+       }
 };
 
 
+typedef Polygon<2,3>   Triangle2;
+typedef Polygon<3,3>   Triangle3;
+
+
 } // namespace Mf
 
 #endif // _MOOF_LINE_HH_
index 2fc919779682dd725b179a59ecd9b2a746236ce7..05d8317caefa4b001f3bdf67a23072945aaa82dc 100644 (file)
@@ -97,6 +97,9 @@ OPENGL_ORDINAL_FUNC(void,     TexCoord,       2);
 OPENGL_ORDINAL_FUNC(void,      TexCoord,       3);
 OPENGL_ORDINAL_FUNC(void,      TexCoord,       4);
 
+OPENGL_GENERIC_FUNC(void,      Rect,           S4);
+OPENGL_GENERIC_FUNC(void,      Rect,           V4);
+
 
 #if USE_DOUBLE_PRECISION
 inline void glGetScalar(GLenum a, GLscalar* b) { glGetDoublev(a, b); }
index 262a6bd281bfb796eb1832b3f2e68c54761e0dd4..108c49f95e891dcf8d5c23c26eba8289acb3a8a6 100644 (file)
@@ -49,7 +49,7 @@ struct Plane : public Shape<3>
                d(scalar) {}
 
 
-       bool intersectRay(const Ray<3>& ray, Ray<3>::Intersection& hit)
+       bool intersectRay(const Ray<3>& ray, Ray<3>::Contact& hit)
        {
                // solve: [(ray.point + t*ray.direction) dot normal] + d = 0
 
index 1564087dcf4482bde9cada95e9084f60bc8ec82a..6d4705a81d4f24998597c17617e95f309caeb231 100644 (file)
@@ -34,12 +34,12 @@ struct Ray : public Drawable
        Vector  point;
        Vector  direction;
 
-       struct Intersection
+       struct Contact
        {
                Scalar  distance;       // distance from the origin to the nearest point
-               Vector  normal;         // surface normal at intersection point
+               Vector  normal;         // surface normal at contact point
 
-               bool operator < (const Intersection& rhs)
+               bool operator < (const Contact& rhs)
                {
                        return distance < rhs.distance;
                }
@@ -69,6 +69,10 @@ struct Ray : public Drawable
 };
 
 
+typedef Ray<2> Ray2;
+typedef Ray<3> Ray3;
+
+
 } // namespace Mf
 
 #endif // _MOOF_RAY_HH_
diff --git a/src/Moof/Rectangle.cc b/src/Moof/Rectangle.cc
deleted file mode 100644 (file)
index 949c22a..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-
-/*]  Copyright (c) 2009-2010, Charles McGarvey  [**************************
-**]  All rights reserved.
-*
-* vi:ts=4 sw=4 tw=75
-*
-* Distributable under the terms and conditions of the 2-clause BSD license;
-* see the file COPYING for a complete text of the license.
-*
-**************************************************************************/
-
-#include "Rectangle.hh"
-
-
-namespace Mf {
-
-
-void Rectangle::getCorners(Vector2 corners[4]) const
-{
-       corners[0][0] = min[0]; corners[0][1] = min[1];
-       corners[1][0] = max[0]; corners[1][1] = min[1];
-       corners[2][0] = max[0]; corners[2][1] = max[1];
-       corners[3][0] = min[0]; corners[3][1] = max[1];
-       corners[4][0] = min[0]; corners[4][1] = min[1];
-       corners[5][0] = max[0]; corners[5][1] = min[1];
-       corners[6][0] = max[0]; corners[6][1] = max[1];
-       corners[7][0] = min[0]; corners[7][1] = max[1];
-}
-
-
-} // namespace Mf
-
diff --git a/src/Moof/Rectangle.hh b/src/Moof/Rectangle.hh
deleted file mode 100644 (file)
index e41b879..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-
-/*]  Copyright (c) 2009-2010, Charles McGarvey  [**************************
-**]  All rights reserved.
-*
-* vi:ts=4 sw=4 tw=75
-*
-* Distributable under the terms and conditions of the 2-clause BSD license;
-* see the file COPYING for a complete text of the license.
-*
-**************************************************************************/
-
-#ifndef _MOOF_RECTANGLE_HH_
-#define _MOOF_RECTANGLE_HH_
-
-#include <Moof/Math.hh>
-
-
-namespace Mf {
-
-
-/**
- * Axis-aligned Bounding Box
- */
-
-struct Rectangle
-{
-       Vector2 min;
-       Vector2 max;
-
-
-       Rectangle() {}
-
-       Rectangle(const Vector2& a, const Vector2& b)
-       {
-               init(a, b);
-       }
-
-       Rectangle(Scalar ax, Scalar ay, Scalar bx, Scalar by)
-       {
-               Vector2 a(ax, ay);
-               Vector2 b(bx, by);
-
-               init(a, b);
-       }
-
-       void init(const Vector2& a, const Vector2& 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];
-               }
-       }
-
-       Vector2 getCenter() const
-       {
-               return Vector2((min[0] + max[0]) / 2.0,
-                                          (min[1] + max[1]) / 2.0);
-       }
-
-       void getCorners(Vector2 corners[4]) const;
-};
-
-
-} // namespace Mf
-
-#endif // _MOOF_RECTANGLE_HH_
-
index c97296004b7a80aa73d5ff3594ed4ae658b38c40..c059d46bff1b1ec563dc471cebe13f84c3b3da7b 100644 (file)
 
 
 // Frustum
-// Plane (can construct from Triangle<3>)
+// Plane (can construct from Triangle3)
 // Ray
 // Shape<>
 // +- Line<>
-// +- Ball<>
-// |  Circle           <- Ball<2>
-// |  Sphere           <- Ball<3>
-// +- Box<>
-// |  Rectangle                <- Box<2>
-// |  Aabb                     <- Box<3>
+// -   Line2                   Line<2>
+// -   Line3                   Line<3>
+// +- Sphere<>
+// |   Sphere2, Circle Sphere<2>
+// |   Sphere3                 Sphere<3>
+// +- Aabb<>
+// |   Aabb2, Rectangle        Aabb<2>
+// |   Aabb3                   Aabb<3>
 // +- Polygon<>
-// |  Triangle         <- Polygon<3>
-// +- Cylinder
-// +- Cone
+// |   Triangle2               Polygon<2,3>
+// |   Triangle3               Polygon<3,3>
 
 
 namespace Mf {
@@ -48,13 +49,13 @@ public:
        /**
         * Checks if this shape is intersected by a given ray.  If so, returns
         * the distance from the start of the ray to the shape and information
-        * about the intersection via the 2nd parameter.  A negative value is
-        * returned if there is no intersection.
+        * about the contact via the 2nd parameter.  A negative value is
+        * returned if there is no contact.
         */
        virtual bool intersectRay(const Ray<D>& ray,
-                                                         typename Ray<D>::Intersection& hit)
+                                                         typename Ray<D>::Contact& hit)
        {
-               return SCALAR(-1.0);
+               return false;
        }
 };
 
index 3cd1ec7a073c05b00988ea97c2c4565afb89ba8c..d42bfd8a98fa8e643494c7b242f8e659c1893da9 100644 (file)
@@ -61,7 +61,7 @@ struct Sphere : public Cullable, public Drawable, public Shape<D>
 
 
        // a ray inside the sphere will not intersect on its way out
-       bool intersectRay(const Ray<D>& ray, typename Ray<D>::Intersection& hit)
+       bool intersectRay(const Ray<D>& ray, typename Ray<D>::Contact& hit)
        {
                Vector b = point - ray.point;
                Scalar z = cml::dot(b, ray.direction);
@@ -163,6 +163,11 @@ inline bool checkCollision(const Sphere<D>& a, const Sphere<D>& b)
 }
 
 
+typedef Sphere<2>      Sphere2;
+typedef Sphere2        Circle;
+typedef Sphere<3>      Sphere3;
+
+
 } // namespace Mf
 
 #endif // _MOOF_SPHERE_HH_
index 7b23ab6431e7a88da48ae3a5fdd38fc7e41a6b3d..8b155e7dd96bf991df058a41806fe5d760214c99 100644 (file)
@@ -526,14 +526,14 @@ void Scene::drawIfVisible(Mf::Scalar alpha,
 
 
 bool Scene::castRay(const Mf::Ray<2>& ray,
-                                       std::list<Mf::Ray<2>::Intersection>& hits) const
+                                       std::list<Mf::Ray<2>::Contact>& hits) const
 {
        std::list< Mf::Line<2> >& lines = mImpl->mLines;
        std::list< Mf::Line<2> >::const_iterator it;
 
        for (it = lines.begin(); it != lines.end(); ++it)
        {
-               Mf::Ray<2>::Intersection hit;
+               Mf::Ray<2>::Contact hit;
                Mf::Scalar d = (*it).intersectRay(ray, hit);
                if (d > 0.0)
                {
index 85a6716953109c9739c7b0c6ba97108c18a01912..07db30dba32ac449cf3836e57682a5d6d9b33cc3 100644 (file)
@@ -51,7 +51,7 @@ public:
        Mf::Scalar getZCoord(const Mf::Vector2& position) const;
 
        bool castRay(const Mf::Ray<2>& ray,
-                       std::list<Mf::Ray<2>::Intersection>& hits) const;
+                       std::list<Mf::Ray<2>::Contact>& hits) const;
        bool checkForCollision(Character& character);
 
        static std::string getPath(const std::string& name);
This page took 0.057601 seconds and 4 git commands to generate.