Пример #1
0
cv::Point3f
rayPlaneIntersection(cv::Point2f uv, const cv::Mat& centroid, const cv::Mat& normal, const cv::Mat_<float>& Kinv)
{
    cv::Matx33d dKinv(Kinv);
    cv::Vec3d dNormal(normal);
    return rayPlaneIntersection(cv::Vec3d(uv.x, uv.y, 1), centroid.dot(normal), dNormal, dKinv);
}
Пример #2
0
void PointLightInteractionHandler::setLightPosFromScreenCoords(const vec2& normalizedScreenCoord) {
    vec2 deviceCoord(2.f * (normalizedScreenCoord - 0.5f));
    // Flip vertical axis since mouse event y position starts at top of screen
    deviceCoord.y *= -1.f;
    // Use half distance between look from and look to positions as scene radius.
    float sceneRadius = 0.5f * glm::length(camera_->getLookTo() - camera_->getLookFrom());
    vec3 rayOrigin = camera_->getWorldPosFromNormalizedDeviceCoords(vec3(deviceCoord, 0.f));
    vec3 rayDir = glm::normalize(
        camera_->getWorldPosFromNormalizedDeviceCoords(vec3(deviceCoord, 1.f)) - rayOrigin);
    float t0 = 0, t1 = std::numeric_limits<float>::max();
    float lightRadius = glm::length(lightPosition_->get());

    if (raySphereIntersection(vec3(0.f), sceneRadius, rayOrigin, rayDir, &t0, &t1)) {
        lightPosition_->set(glm::normalize(rayOrigin + t1 * rayDir) * lightRadius);
    } else {
        // Project it to the rim of the sphere
        t0 = 0;
        t1 = std::numeric_limits<float>::max();
        if (rayPlaneIntersection(camera_->getLookTo(),
                                 glm::normalize(camera_->getLookTo() - camera_->getLookFrom()),
                                 rayOrigin, rayDir, &t0, &t1)) {
            // Project it to the edge of the sphere
            lightPosition_->set(glm::normalize(rayOrigin + t1 * rayDir) * lightRadius);
        }
    }
    // Ensure that up vector is same as camera afterwards
    setLookUp(camera_->getLookUp());
}
Пример #3
0
bool collision (const AABB& b, const Ray& r) {
	Vec3f intersection;
	const Vec3f lower = b.xyz - Vec3f (DEFAULT_ERROR, DEFAULT_ERROR, -DEFAULT_ERROR);
	const Vec3f upper = b.XYZ + Vec3f (DEFAULT_ERROR, DEFAULT_ERROR, -DEFAULT_ERROR);
//	const Vec3f lower = b.xyz;
//	const Vec3f upper = b.XYZ;

	for (int i=0; i<6; ++i) {
		float parameter = rayPlaneIntersection (r, b.planes[i]); // returns the t parameter (the value for the ray equation that gives intersection point)

		Vec3f solution = solve(r, parameter); // put the t value above on the plane and returns the intersection point

		if (parameter > -DEFAULT_ERROR &&
			solution[0] >= lower[0] &&
			solution[1] >= lower[1] &&
			solution[2] >= lower[2] &&
			solution[0] <= upper[0] &&
			solution[1] <= upper[1] &&
			solution[2] <= upper[2] ) {

		//	std::cout << "collided! plane = " << b.planes[i] << ", point = " << solution << std::endl;
			return true;
		}
		else {
//			std::cout << "didnt=" << solution << "  ";
		}
	}
//	std::cout << std::endl;
	return false;
}
Пример #4
0
    IntersectionClass lineSegmentPlaneIntersection(const Plane &p,
                                                   const LineSegment &line,
                                                   Vector &v) {
      double t;
      IntersectionClass r = rayPlaneIntersection(p, line.v1, line.v2, v, t);

      if (r <= 0) return r;

      if ((t < 0.0 && !equal(v, line.v1)) || (t > 1.0 && !equal(v, line.v2)))
        return INTERSECT_NONE;

      return INTERSECT_PLANE;
    }
void PlayerControl::update()
{
	pickRayDirection();
	rayPlaneIntersection();

	if(glfwGetMouseButton(m_window, GLFW_MOUSE_BUTTON_1) == GLFW_PRESS)
	{
		m_mouseDown = true;
	}
	else
	{
		if(m_mouseDown)
		{
			//event on current position
			m_event = true;
		}
		m_mouseDown = false;
	}
}
Пример #6
0
 cv::Vec3f
 intersection(float u, float v, const cv::Matx33f& Kinv) const
 {
     return rayPlaneIntersection(cv::Vec3d(u, v, 1), p_dot_n, n, Kinv);
 }
Пример #7
0
reRay planePlaneIntersection(reRay a, reRay b)
{
	reVec3 normal = glm::normalize(glm::cross(a.n, b.n)); 
	reVec3 dir = glm::normalize(glm::cross(normal, a.n));
	return reRay(rayPlaneIntersection(reRay(a.p, dir), b), normal);
};
	__forceinline Ogre::Vector3 projectPointOnLine(const Ogre::Vector3 &p, const Ogre::Vector3 &line1, const Ogre::Vector3 &line2)
	{
		Ogre::Vector3 rayDir = line2 - line1;
		float t = rayPlaneIntersection(line1, rayDir, rayDir, p);
		return line1 + rayDir * t;
	}