Browse Source

Merge pull request #926 from ablake/bugfix

A couple small fixes.
Sean Paul Taylor 12 years ago
parent
commit
d2b48ca06d
3 changed files with 15 additions and 10 deletions
  1. 6 8
      gameplay/src/Form.cpp
  2. 5 0
      gameplay/src/ImageControl.cpp
  3. 4 2
      gameplay/src/ImageControl.h

+ 6 - 8
gameplay/src/Form.cpp

@@ -748,21 +748,19 @@ bool Form::projectPoint(int x, int y, Vector3* point)
     {
         // Get info about the form's position.
         Matrix m = _node->getWorldMatrix();
-        Vector3 min(0, 0, 0);
-        m.transformPoint(&min);
+        Vector3 pointOnPlane(0, 0, 0);
+        m.transformPoint(&pointOnPlane);
 
         // Unproject point into world space.
         Ray ray;
         camera->pickRay(Game::getInstance()->getViewport(), x, y, &ray);
 
         // Find the quad's plane.  We know its normal is the quad's forward vector.
-        Vector3 normal = _node->getForwardVectorWorld();
+        Vector3 normal = _node->getForwardVectorWorld().normalize();
 
-        // To get the plane's distance from the origin, we'll find the distance from the plane defined
-        // by the quad's forward vector and one of its points to the plane defined by the same vector and the origin.
-        const float& a = normal.x; const float& b = normal.y; const float& c = normal.z;
-        const float d = -(a*min.x) - (b*min.y) - (c*min.z);
-        const float distance = fabs(d) /  sqrt(a*a + b*b + c*c);
+        // To get the plane's distance from the origin, we project a point on the
+        // plane onto the plane's normal vector.
+        const float distance = fabs(Vector3::dot(pointOnPlane, normal));
         Plane plane(normal, -distance);
 
         // Check for collision with plane.

+ 5 - 0
gameplay/src/ImageControl.cpp

@@ -113,6 +113,11 @@ const Rectangle& ImageControl::getRegionDst() const
     return _dstRegion;
 }
 
+const char* ImageControl::getType() const
+{
+    return "image";
+}
+
 void ImageControl::drawImages(SpriteBatch* spriteBatch, const Rectangle& clip)
 {
     spriteBatch->finish();

+ 4 - 2
gameplay/src/ImageControl.h

@@ -1,7 +1,7 @@
 #ifndef IMAGECONTROL_H_
 #define IMAGECONTROL_H_
 
-#include "Control.h"
+#include "Button.h"
 #include "Theme.h"
 #include "Image.h"
 #include "SpriteBatch.h"
@@ -33,7 +33,7 @@ namespace gameplay
      }
  @endverbatim
  */
-class ImageControl : public Control
+class ImageControl : public Button
 {
     friend class Container;
 
@@ -109,6 +109,8 @@ public:
      */
     const Rectangle& getRegionDst() const;
 
+    const char* getType() const;
+
 protected:
 
     ImageControl();