当前位置: 首页>>代码示例>>C++>>正文


C++ Ray::getPoint方法代码示例

本文整理汇总了C++中Ray::getPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ Ray::getPoint方法的具体用法?C++ Ray::getPoint怎么用?C++ Ray::getPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ray的用法示例。


在下文中一共展示了Ray::getPoint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getRayPoint

 btVector3 PhysicsSystem::getRayPoint(float extent, float mouseX, float mouseY)
 {
     //get a ray pointing to the center of the viewport
     Ray centerRay = mRender.getCamera()->getCameraToViewportRay(mouseX, mouseY);
     btVector3 result(centerRay.getPoint(500*extent).x,-centerRay.getPoint(500*extent).z,centerRay.getPoint(500*extent).y); /// \todo make this distance (ray length) configurable
     return result;
 }
开发者ID:DeejStar,项目名称:openmw,代码行数:7,代码来源:physicssystem.cpp

示例2: intersect

    Intersection Triangle::intersect(const Ray &r) const
    {
         const Vec3t edge1(V1-V0), edge2(V2-V0); // could precalculate
         Vec3t pvec(cross(r.getNormal(), edge2));
         DefType det=dot(edge1,pvec);

         if (det < MM_EPSILON)
             return Intersection();

         Vec3t tvec(r.getPoint()-V0);
         DefType u=dot(tvec,pvec);

         if (u < 0 || u > det)
             return Intersection();

         Vec3t qvec(cross(tvec,edge1));

         DefType v=dot(r.getPoint(),qvec);

         if (v < 0 || u+v > det)
             return Intersection();

         DefType t=dot(edge2, qvec)/det;

         return Intersection(r.positionAtTime(t), m_normal, t, true, true);
    }
开发者ID:acornejo,项目名称:CDL,代码行数:26,代码来源:Triangle.cpp

示例3: from

    std::vector < std::pair <float, std::string> > PhysicsSystem::getFacedObjects ()
    {
        //get a ray pointing to the center of the viewport
        Ray centerRay = mRender.getCamera()->getCameraToViewportRay(
        mRender.getViewport()->getWidth()/2,
        mRender.getViewport()->getHeight()/2);
        btVector3 from(centerRay.getOrigin().x,-centerRay.getOrigin().z,centerRay.getOrigin().y);
        btVector3 to(centerRay.getPoint(500).x,-centerRay.getPoint(500).z,centerRay.getPoint(500).y);

        return mEngine->rayTest2(from,to);
    }
开发者ID:DeejStar,项目名称:openmw,代码行数:11,代码来源:physicssystem.cpp

示例4: intersect

	Intersection Quad::intersect(const Ray& ray, float previousBestDistance) const
	{
		float factor= dot(ray.d,qnormal);

		if(factor==0.0) return Intersection::failure();

		float t= dot((qv1-ray.o),qnormal)/factor;

		if (t> previousBestDistance || t<0.0001) return Intersection::failure();

		Point p=ray.getPoint(t);

		/****** n = -det(PA, PQ)/det(PQ, PR)
				m = det(PA, PR)/det(PQ, PR)
				det(PA, PQ) = PA.x*PQ.y-PQ.x*PA.y
		******/
		bool a = dot(cross(qv2 - qv1, p - qv1), qnormal) >= 0;
		bool b = dot(cross(qv4 - qv2, p - qv2), qnormal) >= 0;
		bool c = dot(cross(qv3 - qv4, p - qv4), qnormal) >= 0;
		bool d = dot(cross(qv1 - qv3, p - qv3), qnormal) >= 0;

		if (a && b && c && d)
			return Intersection(t, ray, this, qnormal, p);
		else
			return Intersection::failure();
		/*
		float n = (qspan1.x * ( p.y - qv1.y) - p.x*qspan1.y + qv1.x*qspan1.y) / (qspan2.y * qspan1.x - qspan2.x*qspan1.y);
		if (n < 0 || n > 1) return Intersection::failure();
		float m = (p.x - qv1.x - n *qspan2.x) / qspan1.x;
		if (m < 0 || m > 1) return Intersection::failure(); 
		
		return Intersection(t,ray,this,qnormal,p);
		*/

	}
开发者ID:joniali,项目名称:Cg-Saar-RayTracer,代码行数:35,代码来源:quad.cpp

示例5: evaluateWe

Spectrum Camera::evaluateWe( const Ray &i_ray, glm::vec2* o_rasterPosition ) const
{
    glm::vec3 directionWorld = Transform::transform( glm::vec3( 0.0, 0.0, -1.0 ), m_cameraToWorld );
    float cosTheta = glm::dot( i_ray.getDirection(), directionWorld );
    
    // See if they are pointing in the same direction
    if ( cosTheta <= 0.0f ) {
        return Spectrum::black();
    }
    
    // Find point on plane of focus and convert that to
    // raster coordinates
    float t = ( m_aperature > 0.0f ? m_focalLength : 1.0 ) / cosTheta;
    glm::vec3 focusPoint = i_ray.getPoint( t );
    glm::vec2 rasterPoint = glm::vec2( glm::inverse( m_rasterToCamera ) *
                                       m_worldToCamera *
                                       glm::vec4( focusPoint, 1.0) );
    
    // Optionally return raster position
    if ( o_rasterPosition != nullptr ) {
        *o_rasterPosition = glm::vec2( rasterPoint );
    }
    
    if ( !m_rasterBounds.isInside( rasterPoint ) ) {
        return Spectrum::black();
    }
    
    float lensArea = m_aperature == 0.0f ? 1.0f : ( M_PI * m_aperature * m_aperature );
    float cos2Theta = cosTheta * cosTheta;
    
    return Spectrum( 1.0f / ( m_area * lensArea * cos2Theta * cos2Theta ) );
}
开发者ID:JonCG90,项目名称:GraphicsEngine,代码行数:32,代码来源:Camera.cpp

示例6:

const Vector3 Lambert::shade(const unsigned int threadID, const Ray& ray, const HitInfo &hit, const Scene& scene, bool isSecondary) const
{
    Vector3 L		= Vector3(0.0f, 0.0f, 0.0f);
	Vector3 rayD	= Vector3(ray.d[0],ray.d[1],ray.d[2]);		// Ray direction
	Vector3 viewDir	= -rayD;									// View direction
	float u, v;
	Vector3 N, geoN, T, BT;
	Vector3 diffuseColor = m_kd;

	Vector3 P = ray.getPoint(hit.t);

	hit.getAllInfos(N, geoN, T, BT, u, v);

	if (m_colorMap != NULL) 
	{
		Vector4 texCol = m_colorMap->getLookup(u, v);
		diffuseColor = Vector3(texCol.x, texCol.y, texCol.z);
	}

    const Lights *lightlist = scene.lights();
    
    // loop over all of the lights
    Lights::const_iterator lightIter;
    for (lightIter = lightlist->begin(); lightIter != lightlist->end(); lightIter++)
    {
		float discard;
		Vector3 lightPower = (*lightIter)->sampleLight(threadID, P, N, ray.time, scene, 0, discard);		
		L += lightPower * diffuseColor;								// Calculate Diffuse component
    }
    
    // add the ambient component
    L += m_ka;
    
    return L;
}
开发者ID:curonian,项目名称:rendering-algorithms-raytracer,代码行数:35,代码来源:Lambert.cpp

示例7: intersectRay

bool OsgSceneObject::intersectRay(const Ray& ray, Vector3f* hitPoint)
{
	Vector3f rstart = ray.getOrigin();
	
	// Compute reasonable ray length based on distance between ray origin and
	// owner scene node center.
	Vector3f center = getOwner()->getBoundCenter();
	float dir = (ray.getOrigin() - center).norm();
	Vector3f rend = ray.getPoint(dir * 2);

	osg::Vec3d orig(rstart[0], rstart[1], rstart[2]);
	osg::Vec3d end(rend[0], rend[1], rend[2]);


	Ref<osgUtil::LineSegmentIntersector> lsi = new osgUtil::LineSegmentIntersector(orig, end);
	osgUtil::IntersectionVisitor iv(lsi);

	myTransform->accept(iv);

	if(!lsi->containsIntersections()) return false;

	osgUtil::LineSegmentIntersector::Intersection i = lsi->getFirstIntersection();
	
	osg::Vec3d intersect = i.getWorldIntersectPoint();

	hitPoint->x() = intersect[0];
	hitPoint->y() = intersect[1];
	hitPoint->z() = intersect[2];
	return true;
}
开发者ID:caishanli,项目名称:omegaOsg,代码行数:30,代码来源:OsgSceneObject.cpp

示例8: mouseMoved

bool pathDrawerState::mouseMoved(const OIS::MouseEvent& e)
{
    //cout << _nodoSelector->getName().substr(0,_nodoSelector->getName().find("_")) << endl;
    //cout << "mousemove " << _nodoSelector->getName() << endl;
    if (InputManager_::getSingletonPtr()->getMouse()->getMouseState().buttonDown(OIS::MB_Left) &&
        //_nodoSelector && _nodoSelector->getName() != "PlaneRoadBig") //"track1Big")
        _nodoSelector && 
        _nodoSelector->getName().substr(0,_nodoSelector->getName().find("_")-1) != _checkPointInfo.nombreNodo)
    {
        Ray r = setRayQuery(e.state.X.abs, e.state.Y.abs, MASK_CIRCUITO | MASK_MARCA);
        RaySceneQueryResult &result = _raySceneQuery->execute();
        RaySceneQueryResult::iterator it;
        it = result.begin();
        if (it != result.end() && it->movable->getParentSceneNode()->getName() == "PlaneRoadBig") 
        {   
            Vector3 pos = r.getPoint(it->distance);
            pos.y = _planeRoadNode->getPosition().y + 1;
            _nodoSelector->setPosition(pos);
            recolocarLinea();
        }
    }
        
    
    return true;
}
开发者ID:jalcolea,项目名称:cars,代码行数:25,代码来源:pathDrawerState.cpp

示例9: isHitBy

	// ---------------------------------------------------------------------------------
	bool ConvexPolygon::isHitBy(const Ray& ray) const {
		// Create a RayStart->Edge defined plane. 
		// If the intersection of the ray to the polygon's plane is inside for all the planes, it is inside the poly
		// By inside, I mean the point is on positive side of the plane
		std::pair<bool, Real> intersection = ray.intersects(mPlane);
		
		if (!intersection.first) 
			return false;
		
		// intersection point
		Vector3 ip     = ray.getPoint(intersection.second);
		Vector3 origin = ray.getOrigin();
				
		unsigned int pointcount = mPoints.size();
		for (unsigned int idx = 0; idx < pointcount; idx++) {
			int iv2 = (idx + 1) % pointcount;
			
			Vector3 v1 = mPoints[idx];
			Vector3 v2 = mPoints[iv2];
			
			Plane frp(origin, v1, v2);
			
			// test whether the intersection is inside
			if (frp.getSide(ip) != Plane::POSITIVE_SIDE)
				return false;
		}
		
		return true;
	}
开发者ID:Painpillow,项目名称:openDarkEngine,代码行数:30,代码来源:DarkConvexPolygon.cpp

示例10: OnLeftButtonDown

LRESULT Canvas::OnLeftButtonDown( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled )
{
	//
	int x = GET_X_LPARAM(lParam);
	int y = GET_Y_LPARAM(lParam);
	//_cameraController.onLeftButtonDown(x,y);

	bHandled = false;
	
	//拾取射线
	Ray r = _camera.getCameraToViewportRay(x, y);
	
	//与xz平面的交点
	Real t = -r._origin.y / r._direction.y;
	Vec3 p = r.getPoint(t);
	Vec3 ap = _getActorPosition();
	p -= ap;
	Real len = p.length();
	_positionSpeed = 0.010f / len;
	//目标点
	_setActorPosition(p);
	
	//调整主角方向
	Quaternion q;
	Radian angle = Euler::Basic::ATan2(p.x, p.z);
	q.FromAngleAxis(angle, Vec3::UNIT_Y);
	_angleSpeed = 0.01f;
	_setActorAngle(q);
	return 0;
}
开发者ID:,项目名称:,代码行数:30,代码来源:

示例11: UpdateMousePick

// this is called at simulation time
void DemoApplication::UpdateMousePick ()
{
	bool mouseKey1 = m_mouseState.buttonDown(OIS::MB_Left);

	OgreNewtonRayPickManager* const rayPicker = m_physicsWorld->GetRayPickManager();
	if (m_keyboard->isKeyDown(OIS::KC_LCONTROL) || m_keyboard->isKeyDown(OIS::KC_RCONTROL)) {
		m_cursor->setVisible(true);
		if (mouseKey1) {
			Real mx = Real (m_mouseState.X.abs) / Real(m_mouseState.width);
			Real my = Real (m_mouseState.Y.abs) / Real(m_mouseState.height);
			Ray camray (mCamera->getCameraToViewportRay(mx, my));

			Vector3 start (camray.getOrigin());
			Vector3 end (camray.getPoint (200.0f));

			if (!m_mousePickMemory) {
				rayPicker->SetPickedBody (NULL);
				dNewtonBody* const body = rayPicker->RayCast (start, end, m_pickParam);
				if (body) {
					rayPicker->SetPickedBody (body, start + (end - start) * m_pickParam);
				}
			} else {
				rayPicker->SetTarget (start + (end - start) * m_pickParam);
			}

		} else {
			rayPicker->SetPickedBody (NULL);
		}
	} else {
		m_cursor->setVisible(false);
		rayPicker->SetPickedBody (NULL);
	}
	m_mousePickMemory = mouseKey1;
}
开发者ID:Stuggy,项目名称:ogrenewton,代码行数:35,代码来源:DemoApplication.cpp

示例12: intersect

IntersectResult Sphere::intersect(Ray &ray)
{ 
    IntersectResult result(false);

    // Solve:
    //   | (o + t * dir) - c | = radius
    //  ==> ( co + t * dir ) ^ 2 - radius ^ 2 = 0
    //  ==> dir * dir * t ^ 2 + 2 * dir.co * t + (co.co - radius * radius) = 0
    //  ==> t ^ 2 + (2 * dir.co) * t + (co.co - radius * radius) = 0
    //  ==> t = - dir.co +- sqr((dir.co * dir.co) - (co.co - radius * radius))
    Vector co = Vector(center, ray.origin);
    double b = ray.direction.dot(co);
    double delta = b * b - (co.dot(co) - radius * radius);

    if (delta >= 0)
    {
        delta = sqrt(delta);
        if (-b + delta >= 0.0005f)
        {
            result.hit = true;
            result.geometry = this;
            //result.distance = (-b - delta >= 0.0005f) ? -b - delta : -b + delta;
            result.distance = -b; // in the SBR algorithm, there should be only one intersection
            result.position = ray.getPoint(result.distance);
            result.normal = Vector(center, result.position).norm();
        }
    }
    return result;
}
开发者ID:windy32,项目名称:em-ray-tracing,代码行数:29,代码来源:Sphere.cpp

示例13: updatePickingPoint_

void Global::updatePickingPoint_()
{
    Ray r = getRenderContex()->getPickingRay();
    float x, z;
    if (0)
    {
        //对于平面地表,可以这样处理
        float t = -r.origion_.y / r.direction_.y;
        x = r.origion_.x + t * r.direction_.x;
        z = r.origion_.z + t * r.direction_.z;
    }
    else
    {
        sPick pk;
        pk.empty_ = true;
        calcPick(pk, r, getSceneManager()->getTerrainQuadTreeRoot());
        if (pk.empty_)
        {
            return;
        }
        Vector3 p = r.getPoint(pk.ps_.z);
        p = (1 - pk.ps_.x - pk.ps_.y)*pk.p0_ + pk.ps_.x*pk.p1_ + pk.ps_.y*pk.p2_;
        x = p.x;
        z = p.z;
    }

    if (getSceneManager()->getTerrain())
    {
        getSceneManager()->getTerrain()->updateVisibleChunks(x, z);
    }
    if (getGlobal() && getGlobal()->getBrushDecal())
    {
        getGlobal()->getBrushDecal()->setCenter(Vector4(x, 0, z, 1));
    }
}
开发者ID:cpzhang,项目名称:zen,代码行数:35,代码来源:Global.cpp

示例14: drawRaycast

	// Dibujado de raycast para depurar
	void CShootRaycast::drawRaycast(const Ray& raycast) {
		Graphics::CScene *scene = Graphics::CServer::getSingletonPtr()->getActiveScene();
		Ogre::SceneManager *mSceneMgr = scene->getSceneMgr();

		std::stringstream aux;
		aux << "laser" << _nameWeapon << _temporal;
		++_temporal;
		std::string laser = aux.str();

		Ogre::ManualObject* myManualObject =  mSceneMgr->createManualObject(laser); 
		Ogre::SceneNode* myManualObjectNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(laser+"_node"); 
 
		myManualObject->begin("laser", Ogre::RenderOperation::OT_LINE_STRIP);
		Vector3 v = raycast.getOrigin();
		myManualObject->position(v.x,v.y,v.z);

		for(int i=0; i < _distance;++i){
			Vector3 v = raycast.getPoint(i);
			myManualObject->position(v.x,v.y,v.z);
			// etc 
		}

		myManualObject->end(); 
		myManualObjectNode->attachObject(myManualObject);
	}// drawRaycast
开发者ID:franaisa,项目名称:Gloom,代码行数:26,代码来源:ShootRaycast.cpp

示例15: mouseMoved

bool TutorialApplication::mouseMoved(const OIS::MouseEvent &arg)
{
    auto ret = BaseApplication::mouseMoved(arg);
//    std::cout << "moust at ("
//              << arg.state.X.abs << ","
//              << arg.state.Y.abs << ","
//              << arg.state.Z.abs << ")" << std::endl;
//    std::cout << "plane at Y = " << m_activeLevel.d << std::endl;

    Ray mouseRay = getMouseRay();

    if (m_verticalMode) {
        // ignored for now, untill I figure out how to make it intuitive
    } else {
        auto r = mouseRay.intersects(m_activeLevel);
        if (r.first) {
            auto pos = mouseRay.getPoint(r.second);
            auto gridPos =
                    Vector3(floor(pos.x / GRID_SPACING) * GRID_SPACING,
                            pos.y,
                            floor(pos.z / GRID_SPACING) * GRID_SPACING);
            m_cursorNode->setPosition(gridPos);
            auto pointPos =
                    Vector3(round(pos.x / GRID_SPACING) * GRID_SPACING,
                            pos.y,
                            round(pos.z / GRID_SPACING) * GRID_SPACING);
            m_pointNode->setPosition(pointPos);

            if (m_mode == WitchMode) {
                for (std::size_t i = 0; i < CONE_CASES.size(); i++) {
                    auto c = CONE_CASES[i];
                    bool containsCreatures = true;
                    for (Vector3 creature : m_ogres) {
                        Vector3 dir = creature - gridPos;

                        // cone is facing wrong way for creature
                        if (dir.angleBetween(c) > Degree(45)) {
                            containsCreatures = false;
                            break;
                        }

                        // creature too far away for cone
                        if (distance3(dir.x, dir.y, dir.z) > CONE_SIZE) {
                            containsCreatures = false;
                        }
                    }

                    if (containsCreatures) {
                        m_coneNodes[i]->setVisible(true);
                    } else {
                        m_coneNodes[i]->setVisible(false);
                    }
                }
            }
        }
    }
    return ret;
}
开发者ID:shocklateboy92,项目名称:conemaker,代码行数:58,代码来源:TutorialApplication.cpp


注:本文中的Ray::getPoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。