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


C++ Vec3f::Dot方法代码示例

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


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

示例1: updateOrientation

void updateOrientation() {
	if ( orientationDirty == false ) {
		return;
	}
	orientationDirty = false;
	
	float decay = 0.9f;
	
	float hyst = cos( ToRadians( app_orientationHysteresis.GetVal() ) );

	if ( GotCompassUpdate ) {
		if ( headingSmooth.Dot( heading ) < hyst ) {
			headingSmooth *= decay;
			headingSmooth += (1.0f - decay) * heading;
		}
		headingSmooth.Normalize();
	} 		

	if ( accelSmooth.Dot( accel ) < hyst ) {
		accelSmooth *= decay;
		accelSmooth += (1.0f - decay) * accel;		
	}
	accelSmooth.Normalize();		
	
	Vec3f up = -accelSmooth;
	up.Normalize();
	Vec3f north = headingSmooth;
	north -= up * up.Dot( north );
	north.Normalize();

	Matrix3f toTrueNorth = Rotationf( up, ToRadians( trueHeadingDiff ) ).GetMatrix3();
	north = toTrueNorth * north;
	
	Vec3f east = north.Cross( up );

	Matrix4f o;
	o.SetRow( 0, Vec4f(  east.x,  east.y,  east.z, 0.0f ) );
	o.SetRow( 1, Vec4f( north.x, north.y, north.z, 0.0f ) );
	o.SetRow( 2, Vec4f(    up.x,    up.y,    up.z, 0.0f ) );
	o.SetRow( 3, Vec4f(     0.0,     0.0,     0.0, 1.0f ) );
	
	platformOrientation = o.Transpose();
}
开发者ID:bcrowell,项目名称:planetfinder_ios,代码行数:43,代码来源:app.cpp

示例2:

static void
HandleCollision (Entity *ent, Entity *ent2, Vec3f norm)
{

	if (ent2 && fabs(norm.x) > .8)
	{
		ent->vel.x += ent2->vel.x;
	}
	if (norm.Dot (ent->vel) < 0) // moving torwards entity
	{
		// velocity
		if (fabs(norm.y) > 0.5) // slide along floors
			ent->vel -= norm.Project(ent->vel)*1.5;
		else // bounce off walls
			ent->vel -= norm.Project(ent->vel)*1.2;
		if (ent2 && (ent2->type & ET_PLAYER) && fabs(norm.x) > .8)
		{
			ent->vel.x += ent2->vel.x*1.2;
		}

		ent->vel.z = 0.;
	}

}
开发者ID:philhey,项目名称:scroller,代码行数:24,代码来源:TurtleShell.cpp

示例3: rayTracing

void RayTracer::rayTracing(Ray &ray, Vec3f &shadeColor, int depth)
{
	float curDist = MAX_DIST;
	float newDist;
	int pi = -1;

	for(int k=0; k<numPrim; k++)
	{	
		if(prims[k]->isEnabled() == false) continue;

		if(prims[k]->intercect(ray, newDist) == 1)
		{
			if(newDist < curDist)
			{
				curDist = newDist;
				pi = k;
			}
		}
	}

	if(pi != -1)
	{
		if(prims[pi]->isLightEnabled() == true)
		{
			//light source
			shadeColor = shadeColor + prims[pi]->getMaterial().getColor();
		}
		else
		{
			Vec3f pos = ray.origin+ray.direction*curDist;
			Vec3f N = prims[pi]->getNormal(pos);
			Vec3f R = ray.direction - N * ray.direction.Dot(N) * 2.0f;
			R = Vec3f(0.0f, 0.0f, 0.0f) - R;

			for(int l=0; l<numPrim; l++)
			{
				if(prims[l]->isLightEnabled() == false)
				{
					continue;
				}

				float viewLightDist = (((Sphere *)prims[l])->getCenter() - pos).Length();
				Vec3f L = (((Sphere *)prims[l])->getCenter() - pos).genNormal();

				//shadow light
				float shade = 1.0f;
				Ray rayShadow;
				rayShadow.direction = L;
				rayShadow.origin = pos;
				for(int s=0; s<numPrim; s++)
				{
					if(prims[s]->isLightEnabled() == true) continue;

					float tmpDist;
					if(prims[s]->intercect(rayShadow, tmpDist) == 1 && s != pi && viewLightDist > tmpDist)
					{
						shade = 1.0f;
						break;
					}
				}

				//diffusion light
				float dot = N.Dot(L);
				if(dot > 0)
				{
					float diff = dot * prims[pi]->getMaterial().getDiffRate();
					shadeColor= shadeColor + prims[pi]->getMaterial().getColor() * prims[l]->getMaterial().getColor() * diff * 1.0f;//shade;
				}

				//spec Light
				Vec3f V = ray.direction.genNormal();
				Vec3f LR = L - N * L.Dot(N) * 2.0f;
				dot = V.Dot(LR);
				if (dot > 0)
				{
					float spec = pow(dot, 20) * prims[pi]->getMaterial().getSpecRate();
					shadeColor = shadeColor + prims[l]->getMaterial().getColor() * spec;
				}
			}

			//reflection light
			float refl = prims[pi]->getMaterial().getReflecRate();
			if(depth < RAY_TRACE_DEPTH) 
			{
				Vec3f recColor(0.0f, 0.0f, 0.0f);
				Ray recRay;
				recRay.direction=R;
				recRay.origin=R * 0.00001f + pos;
				rayTracing(recRay, recColor, depth+1);
				shadeColor = shadeColor + recColor * prims[pi]->getMaterial().getColor() * refl;
			}

			//refraction light
			/*float rindex = prims[pi]->getMaterial().getRafracIndex();
			if(prims[pi]->getMaterial().getRefracRate() > 0.0f &&  depth < RAY_TRACE_DEPTH)
			{
				float n = -1.0f;
				Vec3f N = prims[pi]->getNormal(pos);
				float cosI = 0.0f - N.Dot(ray.direction);
				float cosT2 = 1.0f - n * n * (1.0f - cosI * cosI);
//.........这里部分代码省略.........
开发者ID:finallyjustice,项目名称:raytracer,代码行数:101,代码来源:RayTracer.cpp

示例4: Find

//---------------------------------------
Intersection::CollisionInfo Intersection::Find( float t, const Spheref& A, const Vec3f& velA, const Spheref& B, const Vec3f& velB )
{
	// Get the relative velocity
	Vec3f vRel = velB - velA;
	float a = vRel.LengthSqr();

	// Get the minkowski sum of the spheres
	Vec3f center = B.Center - A.Center;
	float c = center.LengthSqr();
	float r = A.Radius + B.Radius;
	float r2 = r * r;

	CollisionInfo cInfo;

	if ( a > 0 )
	{
		float b = center.Dot( vRel );
		if ( b <= 0 )
		{
			if ( -t*a <= b || t*(t*a+2*b) + c <= r2 )
			{
				float deltaC = c - r2;
				float d = b*b - a*deltaC;

				if ( d >= 0 )
				{
					// Sphere start in intersection
					if ( deltaC <= 0 )
					{
						// Contact point is midpoint
						cInfo.ContactPoint = 0.5f * ( A.Center + B.Center );
						cInfo.ContactTime = 0.0f;
					}
					else
					{
						cInfo.ContactTime = -( b + std::sqrtf( d ) ) / a;

						if ( cInfo.ContactTime < 0 )
						{
							cInfo.ContactTime = 0.0f;
						}
						else if ( cInfo.ContactTime > t )
						{
							cInfo.ContactTime = t;
						}

						cInfo.ContactPoint = A.Center + cInfo.ContactTime * velA +
							( A.Radius / r ) * ( center + cInfo.ContactTime * vRel );
					}
					cInfo.Collision = true;
					return cInfo;
				}
			}
			cInfo.Collision = false;
			return cInfo;
		}
	}

	// Sphere start in intersection
	if ( c <= r2 )
	{
		// Contact point is midpoint
		cInfo.ContactPoint = 0.5f * ( A.Center + B.Center );
		cInfo.ContactTime = 0.0f;
		cInfo.Collision = true;
		return cInfo;
	}

	cInfo.Collision = false;
	return cInfo;
}
开发者ID:hydraskillz,项目名称:NetworkShooter,代码行数:72,代码来源:Intersection.cpp

示例5:

void R004PseudoTexture::Render()
{
	m_viewport->Clear();
	MatrixStack mstackvertices;
	MatrixStack mstacknormals;

	// TODO: sort meshes

	mstackvertices.PushMatrix(m_camera->m_projectionmatrix);
	mstackvertices.PushMatrix(m_camera->m_viewmatrix);
	mstacknormals.PushMatrix(m_camera->m_viewmatrix);

	for (int i=0 ; i<m_scene->m_meshCount ; i++)
	{
		Mesh *mesh = m_scene->m_meshes[i];
		//mstackvertices.PushMatrix(mesh->m_worldmatrix);
		//mstacknormals.PushMatrix(mesh->m_worldmatrix);

		// Transforming vertices into screen coords
		Vec3f *vertices = new Vec3f[mesh->m_vertexcount];
		for (unsigned int v=0 ; v<mesh->m_vertexcount ; v++)
		{
			Vec3f vec = mesh->m_vertexbuffer[v];			
			vec = vec * mstackvertices.GetTopMatrix();
			vec.x = vec.x / ( (vec.z>0) ? (vec.z) : (-vec.z) );
			vec.y = vec.y / ( (vec.z>0) ? (vec.z) : (-vec.z) );
			vec = vec * m_viewport->m_viewportmatrix;
			vertices[v] = vec;
		}

		// Reading index buffer and drawing lines
		for (unsigned int s=0 ; s<mesh->m_stripcount ; s++)
		{
			Strip *strip = mesh->m_strips[s];
			Vec3f v0,v1,v2;
			v0 = vertices[strip->m_indexbuffer[0]];
			v1 = vertices[strip->m_indexbuffer[1]];
			for (unsigned i=2 ; i<strip->m_indexcount ; i++)
			{
				v2 = vertices[strip->m_indexbuffer[i]];
	
				// backface culling
				Vec3f cullingnormal = ((v1-v0).Cross((v2-v0)));
				if (cullingnormal.z < 0) // TODO dotproduct with camera ?
				{
					// Calculate flat shading
					Vec3f normal = (mesh->m_vertexbuffer[strip->m_indexbuffer[i]]-mesh->m_vertexbuffer[strip->m_indexbuffer[0]])
									.Cross(mesh->m_vertexbuffer[strip->m_indexbuffer[i-1]]-mesh->m_vertexbuffer[strip->m_indexbuffer[0]]);
					normal = normal.Mul3x3(mstacknormals.GetTopMatrix());
					normal.Normalize();
					Vec3f frontvec;
					frontvec.z = 1;
					float normaldotproduct = normal.Dot(frontvec);
					if (normaldotproduct > 0) normaldotproduct = 0;
					unsigned char shade = (unsigned char) ((normaldotproduct * (-200.0f)) + 55.0f);

					// Fill poly
					FillPoly(v0, v1, v2, shade);
				}

				v1 = v2;
			}
		}
		//mstack.PopMatrix(); // Remove world matrix (the mesh one)
		delete vertices;
	}
}
开发者ID:RomanHargrave,项目名称:skulls3d,代码行数:67,代码来源:R004PseudoTexture.cpp


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