示例#1
0
gkScalar gkOgreParticleResource::getMaxTimeToLiveOfEmitters(void)
{
	GK_ASSERT(m_psys);
	if (!m_psys) return 0;

	gkScalar timeToLive = 0;
	unsigned short i;

	for (i = 0; i < m_psys->getNumEmitters(); i++)
	{
		timeToLive = gkMax(timeToLive, m_psys->getEmitter(i)->getTimeToLive());
	}

	return timeToLive;
}
示例#2
0
void gkBlenderSceneConverter::convertObjectLamp(gkGameObject* gobj, Blender::Object* bobj)
{
	GK_ASSERT(gobj->getType() == GK_LIGHT && bobj->data);

	gkLight* obj = static_cast<gkLight*>(gobj);

	gkLightProperties& props = obj->getLightProperties();
	Blender::Lamp* la = static_cast<Blender::Lamp*>(bobj->data);

	props.m_diffuse = gkColor(la->r, la->g, la->b);
	if (la->mode & LA_NO_DIFF)
		props.m_diffuse = gkColor::Black;

	props.m_specular = gkColor(la->r, la->g, la->b);
	if (la->mode & LA_NO_SPEC)
		props.m_specular = gkColor::Black;

	props.m_power = la->energy;
	if (la->mode & LA_NEG)
		props.m_power = -props.m_power;

	props.m_linear    = la->att1 / la->dist;
	props.m_constant  = 1.f;
	props.m_quadratic = la->att2 / (la->dist * la->dist);


	props.m_type = gkLightProperties::LI_POINT;
	if (la->type != LA_LOCAL)
		props.m_type = la->type == LA_SPOT ? gkLightProperties::LI_SPOT : gkLightProperties::LI_DIR;

	
	props.m_spot.y  = la->spotsize > 128 ? 128 : la->spotsize;
	props.m_spot.x  = gkMax(gkRadian(la->spotblend).valueDegrees(), props.m_spot.y);
	props.m_falloff = 128.f * la->spotblend;

	props.m_casts = (la->type != LA_HEMI && 
		((la->mode & LA_SHAD_RAY) ||
		 (la->type == LA_SPOT && (la->mode & LA_SHAD_BUF))));		
}
示例#3
0
void gkOgreParticleEmitter::_initParticle(Particle* pParticle)
{
	GK_ASSERT(m_creator);

	gkParticleSettingsProperties& props = m_creator->getParticleProperties();

	ParticleEmitter::_initParticle(pParticle);

	pParticle->direction = props.m_velocity;

	if (mParent)
	{
		Ogre::Any any = mParent->getUserAny();
		if (!any.isEmpty())
		{
			gkOgreParticleObject* pobj = Ogre::any_cast<gkOgreParticleObject*>(any);
			gkMesh* mesh = pobj->getParticleProperties().m_mesh;
			if (mesh)
			{

				if (props.m_emitfrom == gkParticleSettingsProperties::EF_VERTS)
				{
					UTsize count = mesh->getMeshVertexCount();
					int i = rand() % count;
					const gkVertex& v = mesh->getMeshVertex(i);

					pParticle->position = v.co;
					
					if (props.m_velNormal != 0)
						pParticle->direction = (pParticle->direction + v.no * props.m_velNormal)/2; 
				}
				else // if (props.m_emitfrom == gkParticleSettingsProperties::EF_FACES)
				{
					UTsize count = mesh->getMeshTriFaceCount();
					int i = rand() % count;
					gkTriFace face = mesh->getMeshTriFace(i);

					pParticle->position = randomInTri(face.p);

					if (props.m_velNormal != 0)
						pParticle->direction = (pParticle->direction + face.normal() * props.m_velNormal)/2; 
				}
			}
		}
	}


	//setStartTime(props.m_start);
			
	//setTimeToLive(props.m_lifetime);
	//setDirection(props.m_velocity);
	//setParticleVelocity(props.m_velocity.length());

	//pParticle->position = getPosition();
	//pParticle->setDimensions(props.m_size, props.m_size);
	
	//genEmissionColour(pParticle->colour);
    //genEmissionDirection(pParticle->direction);
	//genEmissionVelocity(pParticle->direction); //props.m_velocity

	gkParticleVisualData* data = static_cast<gkParticleVisualData*>(pParticle->getVisualData());
	if (data)
		data->m_initDir = pParticle->direction;

	gkScalar size = gkMax(0.01f, Ogre::Math::RangeRandom(props.m_size - props.m_sizeRandom, props.m_size + props.m_sizeRandom));
	pParticle->setDimensions(size, size);
	pParticle->timeToLive = pParticle->totalTimeToLive = props.m_lifetime; //genEmissionTTL();
}
示例#4
0
btCollisionShape* gkPhysicsController::_createShape(void)
{
	gkMesh* me = 0;
	gkEntity* ent = m_object->getEntity();
	if (ent != 0)
		me = ent->getEntityProperties().m_mesh;

	gkVector3 size(1.f, 1.f, 1.f);
	if (me != 0)
		size = me->getBoundingBox().getHalfSize();
	else
		size *= m_props.m_radius;

	btCollisionShape* shape = 0;	

	switch (m_props.m_shape)
	{
	case SH_BOX:
		shape = new btBoxShape(btVector3(size.x, size.y, size.z));
		break;
	case SH_CONE:
		shape = new btConeShapeZ(gkMax(size.x, size.y), 2.f * size.z);
		break;
	case SH_CYLINDER:
		shape = new btCylinderShapeZ(btVector3(size.x, size.y, size.z));
		break;
	case SH_CONVEX_TRIMESH:
	case SH_GIMPACT_MESH:
	case SH_BVH_MESH:
		{
			if (me != 0)
			{
				btTriangleMesh* triMesh = me->getTriMesh();
				if (triMesh->getNumTriangles() > 0)
				{
					switch (m_props.m_shape)
					{
					case SH_CONVEX_TRIMESH:
						shape = new btConvexTriangleMeshShape(triMesh);
						break;
					case SH_GIMPACT_MESH:
					{
						btGImpactMeshShape* gimpactShape = new btGImpactMeshShape(triMesh);
						gimpactShape->setMargin(m_props.m_margin);
						gimpactShape->setLocalScaling(gkMathUtils::get(m_object->getScale()));
						gimpactShape->updateBound();
						shape = gimpactShape;
						break;
					}					
					case SH_BVH_MESH:
						shape = new btBvhTriangleMeshShape(triMesh, true);
						break;
					}
 					break;
				}
				else
					return 0;
			}
		}
	case SH_SPHERE:
		shape = new btSphereShape(gkMax(size.x, gkMax(size.y, size.z)));
		break;
	case SH_CAPSULE:
		// For some reason, the shape is a bit bigger than the actual capsule...
		gkScalar c_radius = gkMax(size.x, size.y);
		shape = new btCapsuleShapeZ(c_radius-0.05, (size.z-c_radius-0.05) * 2);
		break;
	}

	if (!shape)
		return 0;

	// these values are already set for gimpact-shape
	if (m_props.m_shape != SH_GIMPACT_MESH) {
		shape->setMargin(m_props.m_margin);
		shape->setLocalScaling(gkMathUtils::get(m_object->getScale()));
	}

	if (m_props.isCompound())
	{
		btCompoundShape *compShape = new btCompoundShape();
		compShape->addChildShape(btTransform::getIdentity(), shape);
		return compShape;
	}
	
	return shape;
	
}