예제 #1
0
//-----------------------------------------------------------------------------
// Name: Bound::GetMaxRadius
// Desc: Computes the maximum radius of the bound.
//-----------------------------------------------------------------------------
FLOAT Bound::GetMaxRadius() const
{
    switch( m_Type )
    {
        case Bound::Sphere_Bound:
        {
            float Radius = GetSphere().Radius;
            return Radius;
        }

        case Bound::Frustum_Bound:
        {
            FLOAT MaxZ = abs( GetFrustum().Far - GetFrustum().Near );
            FLOAT MaxX = abs( GetFrustum().LeftSlope * GetFrustum().Far - GetFrustum().RightSlope * GetFrustum().Far );
            FLOAT MaxY = abs( GetFrustum().TopSlope * GetFrustum().Far - GetFrustum().BottomSlope * GetFrustum().Far );
            return max( MaxZ, max( MaxX, MaxY ) );
        }

        case Bound::OBB_Bound:
        {
            XMVECTOR v = XMVector3Length( XMLoadFloat3( &( GetObb().Extents ) ) );
            return XMVectorGetX( v );
        }
        case Bound::AABB_Bound:
        {
            XMVECTOR v = XMVector3Length( XMLoadFloat3( &( GetAabb().Extents ) ) );
            return XMVectorGetX( v );
        }
        case Bound::No_Bound:
            break;
    }

    return 0.0f;
}
예제 #2
0
_Use_decl_annotations_
__forceinline void __vectorcall FindBarycentricCoordinates(FXMVECTOR a, FXMVECTOR b, FXMVECTOR c, FXMVECTOR p, float* s, float* r, float* t)
{
    XMVECTOR u = b - a;
    XMVECTOR v = c - a;
    XMVECTOR w = p - a;
    XMVECTOR vCrossW = XMVector3Cross(v, w);
    XMVECTOR vCrossU = XMVector3Cross(v, u);

    // Validate r is positive (should be if p is in triangle)
    assert(XMVector2GreaterOrEqual(XMVector3Dot(vCrossW, vCrossU), XMVectorZero()));

    XMVECTOR uCrossW = XMVector3Cross(u, w);
    XMVECTOR uCrossV = XMVector3Cross(u, v);

    // Validate t is positive (should be if p is in triangle)
    assert(XMVector2GreaterOrEqual(XMVector3Dot(uCrossW, uCrossV), XMVectorZero()));

    XMVECTOR denom = XMVector3Length(uCrossV);
    XMVECTOR R = XMVector3Length(vCrossW) / denom;
    XMVECTOR T = XMVector3Length(uCrossW) / denom;

    assert(XMVector2LessOrEqual(R + T, XMVectorSet(1, 1, 1, 1)));

    *r = XMVectorGetX(R);
    *t = XMVectorGetX(T);
    *s = 1 - (*r) - (*t);
}
예제 #3
0
void World::moveEntity( WorldEntity* entity, XMVECTOR moveVec, float dist )
{
    //Try to move the entity in the world along the moveVec
    XMVECTOR pos = XMLoadFloat4( &entity->getPosition() );
    XMVECTOR wall = XMVectorZero();
    XMVECTOR vel = XMVectorScale( moveVec, dist );
    XMVECTOR desiredPos;
    XMFLOAT4 check;
    XMFLOAT4 negativeCheck;

    int checks = 0;
    int maxChecks = 10;
    float saveDist = dist;
    float distInterval = dist / static_cast<float>(maxChecks);

    XMStoreFloat4( &check, XMVector3Length(moveVec) );

    //Don't bother doing anything if there is no movement direction
    if( check.x <= 0.0f ){
        return;
    }

    //Check collision at where we plan to be
    if( checkEntityCollision( entity, pos, &wall ) ){
        XMStoreFloat4( &check, wall );
        XMStoreFloat4( &negativeCheck, vel );

        //Check the negative bit of the x and z values and see if they are equal, if they are, then stop movement
        bool negativeXWall = *(int*)(&check.x) < 0;
        bool negativeZWall = *(int*)(&check.z) < 0;

        bool negativeXVel = *(int*)(&negativeCheck.x) < 0;
        bool negativeZVel = *(int*)(&negativeCheck.z) < 0;

        //If we are not in a corner, collide with the wall, otherwise stop movement
        if(check.w <= 1.5f ||
           ( negativeXWall != negativeXVel || 
             negativeZWall != negativeZVel ) ){
            XMVECTOR invWall = XMVectorNegate( wall );
            wall = wall * XMVector3Length( moveVec * invWall );
            vel = (moveVec - wall) * dist;
        }else{
            vel = XMVectorZero();
        }
    }

    desiredPos = pos + vel;
    
    XMStoreFloat4( &entity->getPosition(), desiredPos );
}
예제 #4
0
XMFLOAT3 CSteeringManager::DoSeek(XMFLOAT3 target, float slowDist)
{
	XMFLOAT3 force;
	XMVECTOR vForce;
	XMVECTOR desired;
	XMVECTOR currVelocity;

	currVelocity = XMLoadFloat3(m_pBoid->GetZAxis());

	float dist;

	desired = XMLoadFloat3(&target) - XMLoadFloat3(m_pBoid->GetPosition());
	dist = XMVector3Length(desired).m128_f32[0];
	desired = XMVector3Normalize(desired);

	if (dist <= slowDist)
		desired *= m_pBoid->GetMaxVelocity() * (dist / slowDist);
	else
		desired *= m_pBoid->GetMaxVelocity();

	vForce = desired - currVelocity;

	XMStoreFloat3(&force, vForce);
	return force;
}
예제 #5
0
void Engine::OctreeSystem::_initOctree(const UINT &depth, Octree *octree, const XMFLOAT3 &position, const FLOAT &dim) const
{
	if (depth >= _maxDepth)	return;

	FLOAT newDim = dim / 2;
	FLOAT tmp = newDim / 2;

	octree->position = position;
	octree->dim = dim;
	octree->dim_2 = newDim;
	octree->radius = XMVectorGetX(XMVector3Length(XMVectorSet(newDim, newDim, newDim, 0)));
	octree->next = new Octree[8];

	octree->vertex[0] = XMFLOAT3(position.x - newDim, position.y - newDim, position.z - newDim);
	octree->vertex[1] = XMFLOAT3(position.x - newDim, position.y - newDim, position.z + newDim);
	octree->vertex[2] = XMFLOAT3(position.x - newDim, position.y + newDim, position.z - newDim);
	octree->vertex[3] = XMFLOAT3(position.x - newDim, position.y + newDim, position.z + newDim);
	octree->vertex[4] = XMFLOAT3(position.x + newDim, position.y - newDim, position.z - newDim);
	octree->vertex[5] = XMFLOAT3(position.x + newDim, position.y - newDim, position.z + newDim);
	octree->vertex[6] = XMFLOAT3(position.x + newDim, position.y + newDim, position.z - newDim);
	octree->vertex[7] = XMFLOAT3(position.x + newDim, position.y + newDim, position.z + newDim);

	_initOctree(depth + 1, &octree->next[0], XMFLOAT3(position.x - tmp, position.y - tmp, position.z - tmp), newDim);
	_initOctree(depth + 1, &octree->next[1], XMFLOAT3(position.x - tmp, position.y - tmp, position.z + tmp), newDim);
	_initOctree(depth + 1, &octree->next[2], XMFLOAT3(position.x - tmp, position.y + tmp, position.z - tmp), newDim);
	_initOctree(depth + 1, &octree->next[3], XMFLOAT3(position.x - tmp, position.y + tmp, position.z + tmp), newDim);
	_initOctree(depth + 1, &octree->next[4], XMFLOAT3(position.x + tmp, position.y - tmp, position.z - tmp), newDim);
	_initOctree(depth + 1, &octree->next[5], XMFLOAT3(position.x + tmp, position.y - tmp, position.z + tmp), newDim);
	_initOctree(depth + 1, &octree->next[6], XMFLOAT3(position.x + tmp, position.y + tmp, position.z - tmp), newDim);
	_initOctree(depth + 1, &octree->next[7], XMFLOAT3(position.x + tmp, position.y + tmp, position.z + tmp), newDim);
}
예제 #6
0
파일: Vector.cpp 프로젝트: tedajax/orryx
 f32 Vector::length() const
 {
     XMVECTOR vecLen = XMVector3Length(m_vector);
     XMFLOAT4 fLen;
     XMStoreFloat4(&fLen, vecLen);
     return fLen.x;
 }
예제 #7
0
float Float3::Distance(const Float3& a, const Float3& b)
{
    XMVECTOR x = a.ToSIMD();
    XMVECTOR y = b.ToSIMD();
    XMVECTOR length = XMVector3Length(XMVectorSubtract(x, y));
    return XMVectorGetX(length);
}
//--------------------------------------------------------------------------------------
// Calcaulte the camera based on size of the current scene
//--------------------------------------------------------------------------------------
void UpdateViewerCameraNearFar()
{
    XMVECTOR vMeshExtents = g_CascadedShadow.GetSceneAABBMax() - g_CascadedShadow.GetSceneAABBMin();
    XMVECTOR vMeshLength = XMVector3Length(vMeshExtents);
    FLOAT fMeshLength = XMVectorGetByIndex(vMeshLength, 0);
    g_ViewerCamera.SetProjParams(XM_PI / 4, g_fAspectRatio, 0.05f, fMeshLength);
}
예제 #9
0
void AimingEnemyController::update(UpdatePackage * package)
{
	//find the player
	PlayerController * playerController = package->state->getComponentOfType<PlayerController>();
	// if there is a player
	if (playerController != NULL)
	{
		// get information on the player and the enemy
		Entity * player = package->state->getContainerEntity(playerController);
		ShipController * ship = package->entity->getComponentOfType<ShipController>();
		Transform * transform = package->entity->getComponentOfType<Transform>();
		Physics * physics = package->entity->getComponentOfType<Physics>();
		Transform * playerTransform = player->getComponentOfType<Transform>();
		//find the vector between them
		XMVECTOR difference = transform->getPosition() - playerTransform->getPosition();
		//get the length of the distance
		float distance = XMVectorGetX(XMVector3Length(difference));
		//get the cross product of the unit vector between the player and the enemy and the forward vector of the enemy 
		difference = XMVector3Normalize(difference);
		XMVECTOR cross = XMVector3Cross(transform->getUp(), difference);
		// turn the ship based on the z component of the cross product
		ship->turn(-XMVectorGetZ(cross) * 2);
		//if the vectors are moslty aligned then fire
		if (abs(XMVectorGetZ(cross)) < 0.1f)
		{
			ship->fire();
		}
		//if the ship is mostly facing the player and is too far away then thrust
		if (distance > 300 && abs(abs(XMVectorGetZ(cross)) < 0.5f))
		{
			ship->thrust();
		}
	}
}
예제 #10
0
float  CSkeleton::DistanceToPlayer()
{
	XMVECTOR vToPlayer = XMLoadFloat3(GetPlayer()->GetPosition());
	XMVECTOR vSkeleton = XMLoadFloat3(GetPosition());
	vToPlayer = vToPlayer - vSkeleton;

	return XMVector3Length(vToPlayer).m128_f32[0];
}
예제 #11
0
float EnemyIceBear::DistanceToIglo()
{
	XMVECTOR vector1 = XMLoadFloat3(&m_pIgloPointer->GetTransform()->GetPosition());
	XMVECTOR vector2 = XMLoadFloat3(&m_Position);
	XMVECTOR direction = XMVectorSubtract(vector1, vector2);

	return *XMVector3Length(direction).m128_f32;
}
예제 #12
0
	float Distance(const XMVECTOR& v1, const XMVECTOR& v2)
	{
		XMVECTOR& vectorSub = XMVectorSubtract(v1, v2);
		XMVECTOR& length = XMVector3Length(vectorSub);

		float Distance = 0.0f;
		XMStoreFloat(&Distance, length);
		return Distance;
	}
예제 #13
0
float LineConnection::Distance(const XMVECTOR& vector1,const XMVECTOR& vector2)
{
    XMVECTOR vectorSub = XMVectorSubtract(vector1,vector2);
    XMVECTOR length = XMVector3Length(vectorSub);

    float distance = 0.0f;
    XMStoreFloat(&distance,length);
    return distance;
}
예제 #14
0
void	CFVec4::Normalise( FLOAT32 &fMagnitude )
{
	XMVECTOR& v4V = *reinterpret_cast<XMVECTOR*>( this );

	//TODO: Is there a cheaper way of doing this?
	fMagnitude = XMVectorGetX( XMVector3Length( v4V ) );

	v4V = XMVector3Normalize( v4V );
}
예제 #15
0
inline BOOL checkOctreeInCamSphere(const Engine::Octree *octree, const Engine::PerspCamera *cam)
{
	const XMVECTOR octree_position = XMLoadFloat3(&octree->position);
	const FLOAT distance = XMVectorGetX(XMVector3Length(octree_position - cam->getFrusSpherePosition()));

	if (distance < octree->radius + cam->getFrusSphereRadius())
		return TRUE;
	return FALSE;
}
예제 #16
0
//-----------------------------------------------------------------------------
// Name: Bound::operator*
// Desc: transforms the bound by the current matrix
//-----------------------------------------------------------------------------
Bound Bound::operator*( CXMMATRIX World ) const
{
    //$OPTIMIZE: store matrix decomposed    
    XMVECTOR Translation = World.r[3];
    FLOAT Scale = XMVectorGetX( XMVector3Length( World.r[2] ) );
    XMVECTOR Rotation = XMQuaternionNormalize( XMQuaternionRotationMatrix( World ) );

    // switch based off this bounds type and call the correct
    // bound transform function
    switch( m_Type )
    {
        case Bound::Sphere_Bound:
        {
            Sphere WorldSphere = GetSphere();
            TransformSphere( &WorldSphere,
                             &WorldSphere,
                             Scale,
                             Rotation,
                             Translation );
            return Bound( WorldSphere );
        }
        case Bound::Frustum_Bound:
        {
            Frustum WorldFrustum = GetFrustum();
            TransformFrustum( &WorldFrustum,
                              &WorldFrustum,
                              Scale,
                              Rotation,
                              Translation );
            return Bound( WorldFrustum );
        }
        case Bound::OBB_Bound:
        {
            OrientedBox WorldObb = GetObb();
            TransformOrientedBox( &WorldObb,
                                  &WorldObb,
                                  Scale,
                                  Rotation,
                                  Translation );
            return Bound( WorldObb );
        }
        case Bound::AABB_Bound:
        {
            AxisAlignedBox WorldAabb = GetAabb();
            TransformAxisAlignedBox( &WorldAabb,
                                     &WorldAabb,
                                     Scale,
                                     Rotation,
                                     Translation );
            return Bound( WorldAabb );
        }
        case Bound::No_Bound:
            return Bound();
    }

    return Bound();
}
예제 #17
0
XMVECTOR CSkeletonGroup::CalculateSeparation(CSkeleton* _current)
{
	XMVECTOR mathOutput = XMVECTOR();

	// For all skeletons
	for (size_t i = 0; i < m_vSkeletons.size(); i++)
	{
		// Cast the skeleton for future use
		CSkeleton* other = reinterpret_cast<CSkeleton*>(m_vSkeletons[i]);

		// Convert the positions for math
		XMVECTOR mathOtherPos = XMLoadFloat3(other->GetPosition());
		XMVECTOR mathCurrentPos = XMLoadFloat3(_current->GetPosition());

		// Find the distance between them
		XMVECTOR mathFromVector = mathCurrentPos - mathOtherPos;
		float fDistance = XMVector3Length(mathFromVector).m128_f32[0];

		// If within safe distance
		if (fDistance < SEPARATION_DISTANCE)
		{
			mathFromVector = XMVector3Normalize(mathFromVector);

			mathFromVector *= (SEPARATION_DISTANCE - fDistance) / SEPARATION_DISTANCE;

			mathOutput += mathFromVector;
		}
	}

	// Rescale the velocity
	if (XMVector3Length(mathOutput).m128_f32[0] > 1.0f)
		mathOutput = XMVector3Normalize(mathOutput);

	// Scale by modifier
	return mathOutput * SEPARATION_STRENGTH;



}
예제 #18
0
void Projectile::Update(float dt)
{
	XMVECTOR pos = XMLoadFloat3(&mPos);
	XMVECTOR vel = XMLoadFloat3(&mVelocity);

	mDistanceTravelled += XMVector3Length(vel).m128_f32[0] * dt;

	pos = pos + (vel * dt);
	mWorldUpdated = true;

	XMStoreFloat3(&mPos, pos);
	XMStoreFloat3(&mVelocity, vel);
	GraphicalObject::Update();
}
	void XM_CALLCONV PrimitveDrawer::DrawCylinder(FXMVECTOR P1, FXMVECTOR P2, float radius, FXMVECTOR Color)
	{
		auto center = 0.5f * XMVectorAdd(P1, P2);
		auto dir = XMVectorSubtract(P1, P2);
		auto scale = XMVector3Length(dir);
		scale = XMVectorSet(radius, XMVectorGetX(scale), radius, 1.0f);
		XMVECTOR rot;
		if (XMVector4Equal(dir, g_XMZero))
			rot = XMQuaternionIdentity();
		else
			rot = XMQuaternionRotationVectorToVector(g_XMIdentityR1, dir);
		XMMATRIX world = XMMatrixAffineTransformation(scale, g_XMZero, rot, center);
		m_pCylinder->Draw(world, ViewMatrix, ProjectionMatrix, Color);
	}
예제 #20
0
void Engine::PerspCamera::setPerspective(const FLOAT &fov, const UINT &width, const UINT &height, const FLOAT &n, const FLOAT &f)
{
	FLOAT ratio = (FLOAT)width / height;
	FLOAT yfar = tanf(fov * 0.5f) * f;
	FLOAT xfar = yfar * ratio;

	*_projectionMatrix = XMMatrixPerspectiveFovRH(fov, ratio, n, f);

	_near = n;
	_far = f;
	_fov = fov * ratio;
	_frusSphereDistance = n + (f - n) * 0.5f;
	_frusSphereRadius = XMVectorGetX(XMVector3Length(XMVectorSet(xfar, yfar, f, 0.0f) - XMVectorSet(0.0f, 0.0f, _frusSphereDistance, 0.0f)));
}
예제 #21
0
    bool SnapToGravity(_Inout_ Plane* plane, _Inout_opt_ XMFLOAT3* tangent, _In_ const XMFLOAT3& center, float snapToGravityThreshold, _In_ const XMVECTOR& vUp)
    {
        XMVECTOR vNormal = XMLoadFloat3(&plane->normal);
        XMVECTOR vCenter = XMLoadFloat3(&center);

        float dotGravity = XMVectorGetX(XMVector3Dot(vNormal, vUp));
        float dotProductThreshold = cosf(XMConvertToRadians(snapToGravityThreshold));
        bool isGravityAligned = false;

        // check for nearly horizontal planes
        if (dotGravity > dotProductThreshold)
        {
            vNormal = vUp;
        }
        else if (dotGravity < -dotProductThreshold)
        {
            vNormal = -vUp;
        }
        else
        {
            // check for nearly vertical planes
            XMVECTOR vNormalProjectedPerpendicularToGravity = vNormal - (vUp * dotGravity);
            float dotPerpendicularToGravity = XMVectorGetX(XMVector3Length(vNormalProjectedPerpendicularToGravity));
            if (fabs(dotPerpendicularToGravity) > dotProductThreshold)
            {
                vNormal = XMVector3Normalize(vNormalProjectedPerpendicularToGravity);
                isGravityAligned = true;
            }
            else
            {
                // plane should not be snapped, so exit without modifying plane/tangent
                return false;
            }
        }

        // update the plane equation
        plane->StoreVector(XMPlaneFromPointNormal(vCenter, vNormal));

        // update the tangent vector
        if (tangent != nullptr)
        {
            XMVECTOR vTangent = (isGravityAligned)
                ? XMVector3Cross(vNormal, vUp)
                : XMVector3Cross(XMVector3Cross(vNormal, XMLoadFloat3(tangent)), vNormal);

            XMStoreFloat3(tangent, XMVector3Normalize(vTangent));
        }

        return isGravityAligned;
    }
예제 #22
0
void Entity::SetGoToPoint(float x, float y, float z)
{
	mGoToPos.x = x; mGoToPos.y = y, mGoToPos.z = z;
	goToPos = true;

	XMVECTOR first = XMLoadFloat3(&mGoToPos);
	XMVECTOR second = XMLoadFloat3(&mPosition);
	XMVECTOR end = XMVectorSubtract(first, second);

	XMVECTOR length = XMVector3Length(end);
	mDistanceLeft = XMVectorGetX(length);
	
	XMStoreFloat3(&mLook, XMVector3Normalize(end));
	XMStoreFloat3(&mRight, XMVector3Cross(XMLoadFloat3(&mUp), XMLoadFloat3(&mLook)));
}
void ContructSphereVertexBuffer(CRawModel *pRawModel)
{
	CRawMesh *pRawMesh = new CRawMesh(pRawModel, E_MESH_TYPE::SPHERE, E_MESH_TOPOLOGY::TRIANGLESTRIP, pRawModel->m_eRidigBodyFlag);

	float fRadius = XMVectorGetX(XMVector3Length(XMLoadFloat3(&pRawModel->m_vScale)));

	const DWORD dwSphereNumVertices = 64 * 32;

	int i = 0,
		nNumSlices = 32,
		nNumStacks = (dwSphereNumVertices / nNumSlices);
	nNumStacks = nNumStacks / 2 * 2;
	//dwSphereNumVertices = nNumStacks * nNumSlices;

	float
		fTheta = 0.0f,
		fPhi = 0.0f;

	for (int nStack = 0; nStack < nNumStacks; nStack++)
	{
		fPhi = 0.0f;

		for (int nSlice = 0; nSlice < nNumSlices; nSlice++)
		{
			CVertex v;

			v.vPosition = XMFLOAT3(
				cosf(fPhi) * sinf(fTheta) * fRadius,
				cosf(fTheta) * fRadius,
				sinf(fPhi) * sinf(fTheta) * fRadius
				);

			fPhi += XM_PI / nNumSlices * 2.0f;

			if (nSlice % 2)
				fTheta += XM_PI / nNumStacks * 2.0f;
			else
				fTheta -= XM_PI / nNumStacks * 2.0f;

			pRawMesh->m_Vertices.push_back(v);
		}

		fTheta += XM_PI / nNumStacks * 2.0f;
	}

	pRawModel->m_RawMeshes.push_back(pRawMesh);
}
예제 #24
0
    //--------------------------------------------------------------------------------------
    // Name: FilterAdaptiveDoubleExponential::UpdateSmoothingParameters()
    // Desc: Updates the smoothing parameters based on the smoothing filter's trend
    //--------------------------------------------------------------------------------------
    VOID FilterAdaptiveDoubleExponential::Update( const NUI_SKELETON_DATA* pSkeletonData, const FLOAT fDeltaTime  )
    {
        for (UINT i = 0; i < NUI_SKELETON_POSITION_COUNT; i++)
        {
            XMVECTOR vPreviousPosition  = m_DoubleExponentialFilter.m_History[ i ].m_vRawPosition;
            XMVECTOR vCurrentPosition   = pSkeletonData->SkeletonPositions[ i ];
            XMVECTOR vVelocity          = ( vCurrentPosition - vPreviousPosition ) / fDeltaTime;
            FLOAT fVelocity             = fabsf( XMVectorGetX( XMVector3Length( vVelocity ) ) );

            UpdateSmoothingParameters( i, fVelocity, pSkeletonData->eSkeletonPositionTrackingState[i] );

            m_DoubleExponentialFilter.Update( pSkeletonData, i, m_SmoothingParams[ i ] );
        }

        // Copy filtered data to output data
        XMemCpy( m_FilteredJoints, m_DoubleExponentialFilter.GetFilteredJoints(), sizeof( m_FilteredJoints ) );

    }
예제 #25
0
int CMinotaurIdle::UpdateState(CMinotaur* _agent)
{
	XMFLOAT3 curPos = *_agent->GetPosition();

	// Convert them for math
	XMVECTOR mathPos = XMLoadFloat3(&curPos);
	XMVECTOR mathTarget = XMLoadFloat3(_agent->GetPlayer()->GetPosition());

	// Find the vector between the two points
	XMVECTOR mathToVec = XMVectorSubtract(mathTarget, mathPos);
	XMVECTOR mathDistToTarget = XMVector3Length(mathToVec);
	/*if (mathDistToTarget.m128_f32[0] <= 1000.0f)
		return CMinotaur::eChaseState;

	if (m_fWaitTimer < 0)*/
		return CMinotaur::ePatrolState;

	//return CMinotaur::eIdleState;
}
예제 #26
0
XMVECTOR CSkeletonGroup::CalculateAlignment()
{

	// Calculate the avarage velocity
	XMVECTOR avgVelocity = XMVECTOR();
	for (size_t i = 0; i < m_vSkeletons.size(); i++)
	{
		CSkeleton* other = reinterpret_cast<CSkeleton*>(m_vSkeletons[i]);
		XMFLOAT3 vec = other->GetWorldVelocity();
		XMVECTOR otherVelocity = XMLoadFloat3(&vec);
		avgVelocity += otherVelocity;
	}
	avgVelocity /= (float)m_vSkeletons.size();
	avgVelocity.m128_f32[1] = 0.0f;

	if (XMVector3Length(avgVelocity).m128_f32[0] > 1.0f)
		avgVelocity = XMVector3Normalize(avgVelocity);

	return avgVelocity * ALIGNMENT_STRENGTH;

}
예제 #27
0
DWORD WINAPI ThreadedRaytracing (void* ptr)
{
	ThreadData_t& data = *reinterpret_cast<ThreadData_t*> (ptr);
	ThreadData_t copy = data;
	data.read = true;
	XMVECTOR curPos = *copy.currentPos;
	float distance = 0.0f;
	for (uint64_t i = 0; i < copy.size; i++)
	{
		XMVECTOR d = XMVector3Length (XMVectorSet (copy.data[i].r,
												   copy.data[i].g,
												   copy.data[i].b,
												   0.0f) - curPos);
		XMStoreFloat (&distance, d);
		if (distance < copy.range &&
			(distance < copy.data[i].a ||
			 copy.data[i].a < -0.5f))
			 copy.data[i].a = distance;
	}
	data.done++;
	return 0;
}
예제 #28
0
std::vector<VPCNTDesc> CollisionMesh::GetSupportingVertices(std::vector<VPCNTDesc> vertices, XMFLOAT3 normal)
{
  std::vector<VPCNTDesc> supportingVertices;
  for (int firstIndex = 0; firstIndex < vertices.size(); firstIndex ++)
  {
    VPCNTDesc &firstVert = vertices[firstIndex];
    XMFLOAT3 &firstNormal = firstVert.Normal;

    // we need to check the normal. Calculate using cross product.
    XMVECTOR supportingNormalVector = XMLoadFloat3(&firstNormal);
    XMVECTOR normalVector = XMLoadFloat3(&normal);
    XMVECTOR dotVector = XMVector3Dot(supportingNormalVector, normalVector) / (XMVector3Length(supportingNormalVector) * XMVector3Length(normalVector)) ;
    XMFLOAT3 dotProduct;
    XMStoreFloat3(&dotProduct, dotVector);

    if (dotProduct.x >= XMConvertToRadians(33.0f))
    {
      supportingVertices.push_back(firstVert);
    }
  }

  return supportingVertices;
}
예제 #29
0
void ParticleEmmiter::update(UpdatePackage * package)
{
	//clear the lines
	clear();
	//for every particle
	for (unsigned int i = 0; i < particles.size(); i++)
	{
		//if the particle is alive
		if (particles.at(i).life > 0)
		{
			//lower its life
			particles.at(i).life -= package->time->getDeltaTime();
			//create the line from the particle
			LineInstance line;
			line.color = XMFLOAT4(1.0f,0.5f,0.2f,1);
			line.n1 = particles.at(i).normal;
			line.n2 = particles.at(i).normal;
			//load the particles velocity
			XMVECTOR vel = XMLoadFloat3(&particles.at(i).velocity);
			//move the partlicce along
			XMStoreFloat3(&particles.at(i).position, XMLoadFloat3(&particles.at(i).position) + (XMLoadFloat3(&particles.at(i).velocity) * package->time->getDeltaTime()));
			//the the particle a=had reaches 15 units long
			if (XMVectorGetX(XMVector3Length(XMLoadFloat3(&particles.at(i).position) - XMLoadFloat3(&particles.at(i).endPosition))) > 15)
			{
				//move the end of the particle trail aswell
				XMStoreFloat3(&particles.at(i).endPosition, XMLoadFloat3(&particles.at(i).endPosition) + (XMLoadFloat3(&particles.at(i).velocity) * package->time->getDeltaTime()));
			}
			//store the line points
			line.p2 = particles.at(i).position;
			line.p1 = particles.at(i).endPosition;
			XMStoreFloat4x4(&line.model, XMMatrixIdentity());
			//add the line
			addLine(line);
		}
	}
}
예제 #30
0
	float Vector3::length() const
	{
		return XMVectorGetX(XMVector3Length(*this));
	}