33 #define _def_MaxFarClipDistance 99999
35 namespace Hydrax{
namespace Module
63 , mVerticesChoppyBuffer(0)
64 , mBasePlane(BasePlane)
65 , mNormal(BasePlane.normal)
66 , mPos(
Ogre::Vector3(0,0,0))
67 , mProjectingCamera(0)
69 , mRenderingCamera(h->getCamera())
78 , mVerticesChoppyBuffer(0)
79 , mBasePlane(BasePlane)
80 , mNormal(BasePlane.normal)
81 , mPos(
Ogre::Vector3(0,0,0))
82 , mProjectingCamera(0)
84 , mRenderingCamera(h->getCamera())
261 Ogre::Vector3 HydraxPos = Ogre::Vector3(RenderingCameraPos.x,
mHydrax->
getPosition().y,RenderingCameraPos.z);
386 Ogre::Vector4 result;
404 divide = 1.0f/result.w;
408 Vertices[i].
x = result.x;
409 Vertices[i].
z = result.z;
442 divide = 1.0f/result.w;
446 Vertices[i].
x = result.x;
447 Vertices[i].
z = result.z;
515 Ogre::Vector3 vec1, vec2, normal;
523 vec1 = Ogre::Vector3(
528 vec2 = Ogre::Vector3(
533 normal = vec2.crossProduct(vec1);
560 Ogre::Vector3 CameraDir,
Norm;
561 Ogre::Vector2 Dir, Perp, Norm2;
564 Dir = Ogre::Vector2(CameraDir.x, CameraDir.z).normalisedCopy();
565 Perp = Dir.perpendicular();
567 if (Dir.x < 0 ) Dir.x = -Dir.x;
568 if (Dir.y < 0 ) Dir.y = -Dir.y;
570 if (Perp.x < 0 ) Perp.x = -Perp.x;
571 if (Perp.y < 0 ) Perp.y = -Perp.y;
608 Norm2 = Ogre::Vector2(
Norm.x,
Norm.z) *
622 Ogre::Vector4 origin(uv.x,uv.y,-1,1);
623 Ogre::Vector4 direction(uv.x,uv.y,1,1);
626 direction = m*direction;
628 Ogre::Vector3 _org(origin.x/origin.w,origin.y/origin.w,origin.z/origin.w);
629 Ogre::Vector3 _dir(direction.x/direction.w,direction.y/direction.w,direction.z/direction.w);
633 Ogre::Ray _ray(_org,_dir);
634 std::pair<bool,Ogre::Real> _result = _ray.intersects(
mBasePlane);
635 float l = _result.second;
636 Ogre::Vector3 worldPos = _org + _dir*l;
637 Ogre::Vector4 _tempVec = _viewMat*Ogre::Vector4(worldPos);
638 float _temp = -_tempVec.z/_tempVec.w;
639 Ogre::Vector4 retPos(worldPos);
649 float x_min,y_min,x_max,y_max;
650 Ogre::Vector3 frustum[8],proj_points[24];
661 Ogre::Vector3 _testLine;
665 std::pair<bool,Ogre::Real> _result;
678 frustum[0] = invviewproj * Ogre::Vector3(-1,-1,0);
679 frustum[1] = invviewproj * Ogre::Vector3(+1,-1,0);
680 frustum[2] = invviewproj * Ogre::Vector3(-1,+1,0);
681 frustum[3] = invviewproj * Ogre::Vector3(+1,+1,0);
682 frustum[4] = invviewproj * Ogre::Vector3(-1,-1,+1);
683 frustum[5] = invviewproj * Ogre::Vector3(+1,-1,+1);
684 frustum[6] = invviewproj * Ogre::Vector3(-1,+1,+1);
685 frustum[7] = invviewproj * Ogre::Vector3(+1,+1,+1);
690 src=cube[i*2]; dst=cube[i*2+1];
691 _testLine = frustum[dst]-frustum[src];
692 _dist = _testLine.normalise();
693 _ray = Ogre::Ray(frustum[src], _testLine);
695 if ((_result.first) && (_result.second<_dist+0.00001))
697 proj_points[n_points++] = frustum[src] + _result.second * _testLine;
700 if ((_result.first) && (_result.second<_dist+0.00001))
702 proj_points[n_points++] = frustum[src] + _result.second * _testLine;
711 proj_points[n_points++] = frustum[i];
728 bool keep_it_simple =
false,
731 if (height_in_plane < 0.0f)
742 Ogre::Vector3 aimpoint, aimpoint2;
761 _result = Ogre::Math::intersects(_ray,
mBasePlane);
765 _result.second = -_result.second;
775 _result = Ogre::Math::intersects(_ray,
mBasePlane);
777 aimpoint =
mTmpRndrngCamera->getDerivedPosition() + _result.second * flipped;
788 aimpoint = aimpoint*af + aimpoint2*(1.0f-af);
793 for(i=0; i<n_points; i++)
798 proj_points[i] =
mProjectingCamera->getProjectionMatrixWithRSDepth() * proj_points[i];
804 x_min = proj_points[0].x;
805 x_max = proj_points[0].x;
806 y_min = proj_points[0].y;
807 y_max = proj_points[0].y;
809 for(i=1; i<n_points; i++)
811 if (proj_points[i].
x > x_max) x_max = proj_points[i].x;
812 if (proj_points[i].
x < x_min) x_min = proj_points[i].x;
813 if (proj_points[i].
y > y_max) y_max = proj_points[i].y;
814 if (proj_points[i].
y < y_min) y_min = proj_points[i].y;
818 Ogre::Matrix4 pack(x_max-x_min, 0, 0, x_min,
819 0, y_max-y_min, 0, y_min,
824 *range = invviewproj * pack;