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


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

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


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

示例1: UpdateSelection

//[-------------------------------------------------------]
//[ Private virtual PLScene::SNMTransformGizmo functions  ]
//[-------------------------------------------------------]
void SNMTransformGizmoRotationController::UpdateSelection(Renderer &cRenderer, const VisNode &cVisNode)
{
	// Get the frontend instance
	Frontend &cFrontend = static_cast<FrontendApplication*>(CoreApplication::GetApplication())->GetFrontend();

	// Check whether or not the mouse is currently over the frontend
	if (cFrontend.IsMouseOver()) {
		// Get current mouse cursor position inside the widget
		const int nMousePosX = cFrontend.GetMousePositionX();
		const int nMousePosY = cFrontend.GetMousePositionY();

		// Calculate the clip space to object space matrix
		Matrix4x4 mClipSpaceToObjectSpace = m_mObjectSpaceToClipSpace;
		mClipSpaceToObjectSpace.Invert();

		// Check where the mouse is over
		// Get the ray starting from the camera position in direction of the mouse position
		Vector3 v2DPos(static_cast<float>(nMousePosX), static_cast<float>(nMousePosY), 0.0001f);
		Vector3 vCamPos = v2DPos.To3DCoordinate(mClipSpaceToObjectSpace, cRenderer.GetViewport());
		v2DPos.z = 0.9999f;
		Vector3 vEndPos = v2DPos.To3DCoordinate(mClipSpaceToObjectSpace, cRenderer.GetViewport());

		// Determine the current selected axis by using a picking ray
		Ray cRay;
		cRay.Set(vCamPos, vEndPos);
		m_nSelected = DetermineSelected(cRay);
	} else {
		m_nSelected = 0;
	}
}
开发者ID:ByeDream,项目名称:pixellight,代码行数:33,代码来源:SNMTransformGizmoRotationController.cpp

示例2:

	bool Smt3DGeoObject::Select(LP3DRENDERDEVICE p3DRenderDevice,const lPoint& point)
	{
		if (NULL == p3DRenderDevice || NULL == m_pVertexBuffer)
			return false;
	
		Vector3 vOrg,vTar,vDir;

		p3DRenderDevice->MatrixPush();
		p3DRenderDevice->MatrixMultiply(m_mtxWorld);

		p3DRenderDevice->MatrixPush();
		p3DRenderDevice->MatrixMultiply(m_mtxModel);
		p3DRenderDevice->Transform2DTo3D(vOrg,vTar,point);
		p3DRenderDevice->MatrixPop();

		p3DRenderDevice->MatrixPop();

		vDir = vTar-vOrg;
		if (vDir.GetSqrLength() > 0)
		{
			Ray		ray;
			float   f;
			ray.Set(vOrg,vDir);
			if (m_aAbb.Intersects(ray,&f))
			{
				return true;
			}
		}

		
		return false;
	}
开发者ID:jsccl1988,项目名称:smartgis,代码行数:32,代码来源:md3d_3dgeoobject.cpp

示例3: KochFlake

int KochFlake() {
	printf("Starting SnowFlake Tests.\n");
	SamplerUtil::Init(false);

	Timer timer;	
	Image image(640, 480);
	PerspectiveCamera camera(Vector3(5, 0, 5), Vector3(-5, 0, -5));
	camera.SetImageDimension(640, 480);
	camera.SetAspectRatio(((FLOAT)640)/480);
	
	Sphere sphere;
	Vector3 light(0, 0, 10);

	vector<Model*> spheres;
	GenerateSnowFlake(4, spheres, new Sphere());

	LinearAccel accel;
	accel.SetGeometry(spheres);
	accel.Init();
			
	timer.Start();
	Ray				ray;
	Ray             shadow;
    Intersection	intersection;
	SurfaceElement	surfel;
    
    ScanLineBucket scanLineBucket(640, 480);
	PrimarySampler primarySampler;
    primarySampler.SetPixelSize(2.0f);
    primarySampler.SetRenderBucket(&scanLineBucket);
    primarySampler.Reset(0, 0, 480, 640);

    PrimarySample sample(&image);

    while (primarySampler.GetNextSample(sample)) {
        camera.GenerateRay(ray, sample.xFilm, sample.yFilm);
        intersection.Reset();

		if (accel.Intersect(ray, intersection)) {
			surfel.Init(&intersection, &ray);

			Vector3 lightVec(light - surfel.iPoint);
			shadow.Set(surfel.iPoint, lightVec);

			//if (accel.Intersect(shadow) == NO_HIT)
			{
                DOUBLE ln = shadow.direction.Dot(surfel.normal);
				ln = fabs(ln);
				if (ln > 0) {
                    FLOAT lnf = (FLOAT)ln;
                    sample.SetColor(Color4f(lnf, lnf, lnf));					    
                }
			}
		}
    }

	printf("Time to render image: %d(ms)\n", timer.Stop());
	ImageIO::Save("..\\Results\\Kochflake.png", &image);

	return 0;
}
开发者ID:grilledcheesesandwich,项目名称:Apollo,代码行数:61,代码来源:Apollo.cpp

示例4: AATest

int AATest() {
    printf("Starting AA Tests.\n");
	SamplerUtil::Init(false);

    
	Timer timer;	
	Image image(640, 480);
	PerspectiveCamera camera;
	camera.SetImageDimension(640, 480);
	camera.SetAspectRatio(((FLOAT)640)/480);
	camera.SetPosition(Vector3(0, 0, 10));	
	
    Sphere sphere1(Vector3(2, 0, 0), 2.5);
    Sphere sphere2(Vector3(-2, 0, 0), 2.5);

	sphere1.Init();
    sphere2.Init();

	Vector3 light(0, 10, 13);

	LinearAccel accel;
	accel.AddGeometry(&sphere1);
    accel.AddGeometry(&sphere2);
	accel.Init();
	
    int* superSamples = new int[640 * 480];
    memset(superSamples, 0, 640 * 480 * sizeof(int));

	timer.Start();

	Ray				ray;
	Ray             shadow;
    Intersection	intersection;
	SurfaceElement	surfel;
    
    ScanLineBucket scanLineBucket(640, 480);
    
    StochasticSuperSampler primarySampler(512);
    //GridSuperSampler primarySampler(23);
    //PrimarySampler primarySampler;
    //AdaptiveSuperSampler primarySampler;

    primarySampler.SetRenderBucket(&scanLineBucket);
    primarySampler.Reset(0, 0, 480, 640);
    primarySampler.SetPixelSize(1.8f);

    PrimarySample sample(&image);

    while (primarySampler.GetNextSample(sample)) {
        superSamples[sample.row * 640 + sample.col]++;
        camera.GenerateRay(ray, sample.xFilm, sample.yFilm);
        intersection.Reset();

		if (accel.Intersect(ray, intersection)) {
            sample.model = intersection.primitive->GetParentModel();
			surfel.Init(&intersection, &ray);

			Vector3 lightVec(light - surfel.iPoint);
			shadow.Set(surfel.iPoint, lightVec);

			if (accel.Intersect(shadow) == NO_HIT) {
                DOUBLE ln = shadow.direction.Dot(surfel.normal);
				ln = fabs(ln);
				if (ln > 0) {
                    FLOAT lnf = (FLOAT)ln;
                    if (intersection.primitive == &sphere1) {
                        sample.SetColor(Color4f(lnf, 0, 0));					    
                    } else {
                        sample.SetColor(Color4f(0, 0, lnf));
                    }
                }
			}
		} else {
            sample.model = nullptr;
            sample.SetColor(Color4f::ZERO());
        }
    }    
    printf("Time to render image: %d(ms)\n", timer.Stop());

    int minSamples = 3000;
    int maxSamples = 0;
    int totalSamples = 0;
    for (int i = 0; i < 640 * 480; i++) {
        minSamples = MIN(minSamples, superSamples[i]);
        maxSamples = MAX(maxSamples, superSamples[i]);
        totalSamples += superSamples[i];
    }
    printf("Min Samples: %d\n", minSamples);
    printf("Max Samples: %d\n", maxSamples);
    printf("Total Samples: %d\n", totalSamples);
    printf("Averages Samples per pixel: %f\n", (FLOAT)totalSamples / (640 * 480));
    Image samples(640, 480);
    for (int row = 0; row < 480; row++) {
        for (int col = 0; col < 640; col++) {
            int s = superSamples[row * 640 + col];
            FLOAT value = (s - minSamples) / (FLOAT)(maxSamples - minSamples);
            Color4f color = UIHelper::GetColorIntensity(value);
            samples.SetPixel(color, row, col);
        }
    }
//.........这里部分代码省略.........
开发者ID:grilledcheesesandwich,项目名称:Apollo,代码行数:101,代码来源:Apollo.cpp


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