Пример #1
0
void CHuman::Update(float fElapsedTime)
{
	CEnemy::Update( fElapsedTime );

	m_nCollisionWithStaticObjectsSphere.m_Center = tVector2D(GetPosX(), GetPosY());


	for( unsigned int i = 0; i < CGamePlayState::GetInstance()->m_StoreWalls.size(); i++)
	{
		Capsule* temp = CGamePlayState::GetInstance()->m_StoreWalls[i];
		tVector2D ClosestPoint = ClosestPointOnALine(temp->GetStartPoint(), temp->GetEndPoint(), tVector2D( GetPosX(), GetPosY()));

		// Create a circle based on clsoest point with capsule radius
		Circle testCircle;
		testCircle.m_Center = ClosestPoint;
		testCircle.m_fRadius = temp->GetRadius();

		if( GetSphere()->CheckCollision(testCircle) )
		{
			tVector2D sphere2_to_1 = GetSphere()->m_Center - testCircle.m_Center;
			sphere2_to_1 = Vector2DNormalize(sphere2_to_1);
			float dist = GetSphere()->m_fRadius + testCircle.m_fRadius;
			tVector2D scaler = (sphere2_to_1 * (dist * 0.01f));
			tVector2D newpos = GetSphere()->m_Center + scaler;

			SetPosX(newpos.fX);
			SetPosY(newpos.fY);
		}
	}
}
Пример #2
0
static QScriptValue Capsule_Centroid_const(QScriptContext *context, QScriptEngine *engine)
{
    if (context->argumentCount() != 0) { printf("Error! Invalid number of arguments passed to function Capsule_Centroid_const in file %s, line %d!\nExpected 0, but got %d!\n", __FILE__, __LINE__, context->argumentCount()); PrintCallStack(context->backtrace()); return QScriptValue(); }
    Capsule This = qscriptvalue_cast<Capsule>(context->thisObject());
    float3 ret = This.Centroid();
    return qScriptValueFromValue(engine, ret);
}
Пример #3
0
static QScriptValue Capsule_Intersects_Polyhedron_const(QScriptContext *context, QScriptEngine *engine)
{
    if (context->argumentCount() != 1) { printf("Error! Invalid number of arguments passed to function Capsule_Intersects_Polyhedron_const in file %s, line %d!\nExpected 1, but got %d!\n", __FILE__, __LINE__, context->argumentCount()); PrintCallStack(context->backtrace()); return QScriptValue(); }
    Capsule This = qscriptvalue_cast<Capsule>(context->thisObject());
    Polyhedron polyhedron = qscriptvalue_cast<Polyhedron>(context->argument(0));
    bool ret = This.Intersects(polyhedron);
    return qScriptValueFromValue(engine, ret);
}
Пример #4
0
static QScriptValue Capsule_toString_const(QScriptContext *context, QScriptEngine *engine)
{
    Capsule This;
    if (context->argumentCount() > 0) This = qscriptvalue_cast<Capsule>(context->argument(0)); // Qt oddity (bug?): Sometimes the built-in toString() function doesn't give us this from thisObject, but as the first argument.
    else This = qscriptvalue_cast<Capsule>(context->thisObject());
    QString ret = This.toString();
    return qScriptValueFromValue(engine, ret);
}
Пример #5
0
//----------------------------------------------------------------------------
bool Mgc::TestIntersection (const Capsule& rkC0, const Capsule& rkC1)
{
    Real fSqrDist = SqrDistance(rkC0.Segment(),rkC1.Segment());
    Real fRSum = rkC0.Radius() + rkC1.Radius();
    Real fRSumSqr = fRSum*fRSum;

    return fSqrDist <= fRSumSqr;
}
Пример #6
0
static QScriptValue Capsule_Contains_Frustum_const(QScriptContext *context, QScriptEngine *engine)
{
    if (context->argumentCount() != 1) { printf("Error! Invalid number of arguments passed to function Capsule_Contains_Frustum_const in file %s, line %d!\nExpected 1, but got %d!\n", __FILE__, __LINE__, context->argumentCount()); PrintCallStack(context->backtrace()); return QScriptValue(); }
    Capsule This = qscriptvalue_cast<Capsule>(context->thisObject());
    Frustum frustum = qscriptvalue_cast<Frustum>(context->argument(0));
    bool ret = This.Contains(frustum);
    return qScriptValueFromValue(engine, ret);
}
Пример #7
0
static QScriptValue Capsule_SetFrom_Sphere(QScriptContext *context, QScriptEngine *engine)
{
    if (context->argumentCount() != 1) { printf("Error! Invalid number of arguments passed to function Capsule_SetFrom_Sphere in file %s, line %d!\nExpected 1, but got %d!\n", __FILE__, __LINE__, context->argumentCount()); PrintCallStack(context->backtrace()); return QScriptValue(); }
    Capsule This = qscriptvalue_cast<Capsule>(context->thisObject());
    Sphere s = qscriptvalue_cast<Sphere>(context->argument(0));
    This.SetFrom(s);
    ToExistingScriptValue_Capsule(engine, This, context->thisObject());
    return QScriptValue();
}
Пример #8
0
static QScriptValue Capsule_Transform_float4x4(QScriptContext *context, QScriptEngine *engine)
{
    if (context->argumentCount() != 1) { printf("Error! Invalid number of arguments passed to function Capsule_Transform_float4x4 in file %s, line %d!\nExpected 1, but got %d!\n", __FILE__, __LINE__, context->argumentCount()); PrintCallStack(context->backtrace()); return QScriptValue(); }
    Capsule This = qscriptvalue_cast<Capsule>(context->thisObject());
    float4x4 transform = qscriptvalue_cast<float4x4>(context->argument(0));
    This.Transform(transform);
    ToExistingScriptValue_Capsule(engine, This, context->thisObject());
    return QScriptValue();
}
Пример #9
0
static QScriptValue Capsule_Scale_float3_float(QScriptContext *context, QScriptEngine *engine)
{
    if (context->argumentCount() != 2) { printf("Error! Invalid number of arguments passed to function Capsule_Scale_float3_float in file %s, line %d!\nExpected 2, but got %d!\n", __FILE__, __LINE__, context->argumentCount()); PrintCallStack(context->backtrace()); return QScriptValue(); }
    Capsule This = qscriptvalue_cast<Capsule>(context->thisObject());
    float3 centerPoint = qscriptvalue_cast<float3>(context->argument(0));
    float scaleFactor = qscriptvalue_cast<float>(context->argument(1));
    This.Scale(centerPoint, scaleFactor);
    ToExistingScriptValue_Capsule(engine, This, context->thisObject());
    return QScriptValue();
}
Пример #10
0
static QScriptValue Capsule_UniformPointPerhapsInside_float_float_float_const(QScriptContext *context, QScriptEngine *engine)
{
    if (context->argumentCount() != 3) { printf("Error! Invalid number of arguments passed to function Capsule_UniformPointPerhapsInside_float_float_float_const in file %s, line %d!\nExpected 3, but got %d!\n", __FILE__, __LINE__, context->argumentCount()); PrintCallStack(context->backtrace()); return QScriptValue(); }
    Capsule This = qscriptvalue_cast<Capsule>(context->thisObject());
    float l = qscriptvalue_cast<float>(context->argument(0));
    float x = qscriptvalue_cast<float>(context->argument(1));
    float y = qscriptvalue_cast<float>(context->argument(2));
    float3 ret = This.UniformPointPerhapsInside(l, x, y);
    return qScriptValueFromValue(engine, ret);
}
PxU32 raycast_capsule(GU_RAY_FUNC_PARAMS)
{
    PX_UNUSED(maxHits);
    PX_ASSERT(geom.getType() == PxGeometryType::eCAPSULE);
    PX_ASSERT(maxHits && hits);

    const PxCapsuleGeometry& capsuleGeom = static_cast<const PxCapsuleGeometry&>(geom);

    // TODO: PT: could we simplify this ?
    Capsule capsule;
    getCapsuleSegment(pose, capsuleGeom, capsule);
    capsule.radius = capsuleGeom.radius;

    PxReal t;
    if(!intersectRayCapsule(rayOrigin, rayDir, capsule, t))
        return 0;

    if(t>maxDist)
        return 0;

    // PT: we can't avoid computing the position here since it's needed to compute the normal anyway
    hits->position	= rayOrigin + rayDir*t;	// PT: will be rayOrigin for t=0.0f (i.e. what the spec wants)
    hits->distance	= t;
    hits->faceIndex	= 0xffffffff;
    hits->u			= 0.0f;
    hits->v			= 0.0f;

    // Compute additional information if needed
    PxHitFlags outFlags = PxHitFlag::eDISTANCE|PxHitFlag::ePOSITION;
    if(hitFlags & PxHitFlag::eNORMAL)
    {
        outFlags |= PxHitFlag::eNORMAL;

        if(t==0.0f)
        {
            hits->normal = -rayDir;
        }
        else
        {
            PxReal capsuleT;
            distancePointSegmentSquared(capsule, hits->position, &capsuleT);
            capsule.computePoint(hits->normal, capsuleT);
            hits->normal = hits->position - hits->normal;	 //this should never be zero. It should have a magnitude of the capsule radius.
            hits->normal.normalize();
        }
    }
    else
    {
        hits->normal = PxVec3(0.0f);
    }
    hits->flags = outFlags;

    return 1;
}
Пример #12
0
void computeBV<OBB>(const Capsule& s, OBB& bv)
{
  Vec3f R[3];
  matMulMat(s.getRotation(), s.getLocalRotation(), R);
  Vec3f T = matMulVec(s.getRotation(), s.getLocalTranslation()) + s.getTranslation();

  bv.To = T;
  bv.axis[0] = Vec3f(R[0][0], R[1][0], R[2][0]);
  bv.axis[1] = Vec3f(R[0][1], R[1][1], R[2][1]);
  bv.axis[2] = Vec3f(R[0][2], R[1][2], R[2][2]);
  bv.extent = Vec3f(s.radius, s.radius, s.lz / 2 + s.radius);
}
int main(int argc, char *argv[]) {
	string dataSheetFileName(argv[1]);
	fstream dataSheet (dataSheetFileName);
	int iBlockSize, jBlockSize, kBlockSize, blockSize; // physical
	dataSheet >> iBlockSize >> jBlockSize >> kBlockSize;
	Capsule *cube = new Capsule(iBlockSize, jBlockSize, kBlockSize);


	for (int i = 0; i < iBlockSize; i++) {
		for (int j = 0; j < jBlockSize; j++) {
			for (int k = 0; k < kBlockSize; k++) {
				int zID = cube->mortonIndex(i, j, k);
				dataSheet >> cube->b_block[zID];
			}
		}
	}
	/*
	for (int i = 0; i < iBlockSize; i++) {
		for (int j = 0; j < jBlockSize; j++) {
			for (int k = 0; k < kBlockSize; k++) {
				int zID =
						i * cube->iPadBlockSize * cube->jPadBlockSize
						+ j * cube->kPadBlockSize + k;
//				cout << i << "\t" << j << "\t" << k << "\t" << zID << endl;
				dataSheet >> cube->b_block[zID];
			}
		}
	}
	 */
	int subCubeSize = atoi(argv[2]);
	int t0 = clock();
	cube->GS_block_interior_update_009(1, subCubeSize);
//	cube->GS_Regular_block_update_02(subCubeSize);
//	cube->GS_Z_block_update_02(subCubeSize);
	int t1 = clock();
//	cout << endl;
//	cout << cube->padBlockSize << endl;
//	cout << oct << cube->iMask<< endl;
//	cout << cube->jMask<< endl;
//	cout << cube->kMask<< endl;
//
//	cout << cube->i_interleave.size() << endl;
//	cout << cube->j_interleave.size() << endl;
//	cout << cube->k_interleave.size() << endl;

	double t = 1.0 * (t1-t0) / CLOCKS_PER_SEC;
	cout << "Time Elapsed, " <<subCubeSize << "," << t << endl;

	delete cube;
	dataSheet.close();
	return 0;
}
Пример #14
0
void computeBV<AABB>(const Capsule& s, AABB& bv)
{
  Vec3f R[3];
  matMulMat(s.getRotation(), s.getLocalRotation(), R);
  Vec3f T = matMulVec(s.getRotation(), s.getLocalTranslation()) + s.getTranslation();

  BVH_REAL x_range = 0.5 * fabs(R[0][2] * s.lz) + s.radius;
  BVH_REAL y_range = 0.5 * fabs(R[1][2] * s.lz) + s.radius;
  BVH_REAL z_range = 0.5 * fabs(R[2][2] * s.lz) + s.radius;

  bv.max_ = T + Vec3f(x_range, y_range, z_range);
  bv.min_ = T + Vec3f(-x_range, -y_range, -z_range);
}
Пример #15
0
void CGuard::Update(float fElapsedTime)
{

	if(CheckForPlayer())
	{
		ComputeMovement(fElapsedTime);
		this->addTime(fElapsedTime);
		CBase::Update(fElapsedTime);
	}
	else
		CEnemy::Update( fElapsedTime );

	m_nCollisionWithStaticObjectsSphere.m_Center = tVector2D(GetPosX(), GetPosY());


	for( unsigned int i = 0; i < CGamePlayState::GetInstance()->m_StoreWalls.size(); i++)
	{
		Capsule* temp = CGamePlayState::GetInstance()->m_StoreWalls[i];
		tVector2D ClosestPoint = ClosestPointOnALine(temp->GetStartPoint(), temp->GetEndPoint(), tVector2D( GetPosX(), GetPosY()));

		// Create a circle based on clsoest point with capsule radius
		Circle testCircle;
		testCircle.m_Center = ClosestPoint;
		testCircle.m_fRadius = temp->GetRadius();

		if( GetSphere()->CheckCollision(testCircle) )
		{
			tVector2D sphere2_to_1 = GetSphere()->m_Center - testCircle.m_Center;
			sphere2_to_1 = Vector2DNormalize(sphere2_to_1);
			float dist = GetSphere()->m_fRadius + testCircle.m_fRadius;
			tVector2D scaler = (sphere2_to_1 * (dist * 0.01f));
			tVector2D newpos = GetSphere()->m_Center + scaler;

			SetPosX(newpos.fX);
			SetPosY(newpos.fY);
		}
	}

	if( CSGD_DirectInput::GetInstance()->KeyPressed(DIK_1))
	{
		IsUndead = true;
		AnimManager::GetInstance()->SetAnimation( GetAnimID(), "Zombie Walking" );
	}
	if( CSGD_DirectInput::GetInstance()->KeyPressed(DIK_2))
	{
		IsUndead = false;
		AnimManager::GetInstance()->SetAnimation( GetAnimID(), "Person Walking" );
	}
}
Пример #16
0
void Sphere::Enclose(const Capsule &capsule)
{
	// Capsule is a convex object spanned by the endpoint spheres - enclosing
	// the endpoint spheres will also cause this Sphere to enclose the middle
	// section since Sphere is convex as well.
	float da = pos.DistanceSq(capsule.l.a);
	float db = pos.DistanceSq(capsule.l.b);

	// Enclose the farther Sphere of the Capsule first, and the closer one second to retain the tightest fit.
	if (da > db) 
	{
		Enclose(capsule.SphereA());
		Enclose(capsule.SphereB());
	}
	else
	{
		Enclose(capsule.SphereB());
		Enclose(capsule.SphereA());
	}
}
Пример #17
0
bool physx::Gu::computeCapsule_CapsuleMTD(const Capsule& capsule0, const Capsule& capsule1, PxSweepHit& hit)
{
	using namespace Ps::aos;

	PxReal s,t;
	distanceSegmentSegmentSquared2(capsule0, capsule1, &s, &t);


	const PxReal radiusSum = capsule0.radius + capsule1.radius;

	const PxVec3 pointAtCapsule0 = capsule0.getPointAt(s);
	const PxVec3 pointAtCapsule1 = capsule1.getPointAt(t);

	const PxVec3 normal = pointAtCapsule0 - pointAtCapsule1;
	const PxReal lenSq = normal.magnitudeSquared();
	const PxF32 len = PxSqrt(lenSq);
	hit.normal = normal / len;
	hit.distance = len - radiusSum;
	hit.position = pointAtCapsule1 + hit.normal * capsule1.radius;
	return true;
}
Пример #18
0
/* ....................................................................... */
Capsule::Capsule(const Capsule& other, const osg::CopyOp& copyop):
    Collidable(other, copyop)
{
    m_ODE_geom = dCreateCapsule(NULL, REAL(0.5), REAL(1.0)) ;

    _cloneODECapsule(other.m_ODE_geom, m_ODE_geom) ;

    dGeomSetBody(m_ODE_geom, m_ODE_body) ;

    dGeomSetData(m_ODE_geom, this) ;


    setCollidableOffset(other.getCollidableOffset()) ;
}
Пример #19
0
bool physx::Gu::computeSphere_CapsuleMTD( const Sphere& sphere, const Capsule& capsule, PxSweepHit& hit)
{
	const PxReal radiusSum = sphere.radius + capsule.radius;

	PxReal u;
	distancePointSegmentSquared(capsule, sphere.center, &u);

	const PxVec3 normal = capsule.getPointAt(u) -  sphere.center;
	
	const PxReal lenSq = normal.magnitudeSquared();
	const PxF32 d = PxSqrt(lenSq);
	hit.normal = normal / d;
	hit.distance = d - radiusSum;
	hit.position = sphere.center + hit.normal * sphere.radius;
	return true;
}
Пример #20
0
Capsule CoordinateFrame::toWorldSpace(const Capsule& c) const {
    return Capsule(
        pointToWorldSpace(c.point(0)),
        pointToWorldSpace(c.point(1)),
        c.radius());
}
Пример #21
0
float float3::Distance(const Capsule &rhs) const { return rhs.Distance(*this); }
Пример #22
0
bool Sphere::Intersects(const Capsule &capsule) const
{
	return capsule.Intersects(*this);
}
Пример #23
0
float Sphere::Distance(const Capsule &capsule) const
{
	return capsule.Distance(*this);
}
Пример #24
0
bool AABB::Intersects(const Capsule &capsule) const
{
	return capsule.Intersects(*this);
}
Пример #25
0
bool AABB::Contains(const Capsule &capsule) const
{
	return Contains(capsule.MinimalEnclosingAABB());
}
Пример #26
0
bool Triangle::Intersects(const Capsule &capsule) const
{
    return capsule.Intersects(*this);
}
Пример #27
0
bool CapsuleIntTool::shareSameVertex(const Capsule & c1,const Capsule & c2){
    return c1.shareSameVertex(c2);
}
Пример #28
0
float float3::Distance(const Capsule &rhs) const { return rhs.Distance(POINT_VEC(*this)); }