コード例 #1
0
ファイル: score.cpp プロジェクト: igraph/pcalg
double ScoreGaussL0PenScatter::local(const uint vertex, const std::set<uint>& parents) const
{
	double a;

	dout.level(3) << "Calculating local score...\n";

	// Cast parents set to Armadillo uvec
	arma::uvec parVec(_allowIntercept ? parents.size() + 1 : parents.size());
	std::copy(parents.begin(), parents.end(), parVec.begin());
	arma::uvec vVec(1);
	vVec[0] = vertex;

	// If intercept is allowed, add "fake parent" taking care of intercept
	if (_allowIntercept)
		parVec[parents.size()] = _vertexCount;
	dout.level(3) << "Vertex: " << vertex << "; parents (adjusted acc. to interc.): " << parVec << "\n";

	// Calculate value in the logarithm of maximum likelihood
	a = (*(_scatterMatrices[vertex]))(vertex, vertex);
	if (parVec.size()) {
		// TODO: evtl. wieder umschreiben, s.d. keine Cholesky-Zerlegung mehr
		// gebraucht wird: macht Code nämlich etwas langsamer... (wider Erwarten!)
		//arma::colvec b = arma::subvec(*(_scatterMatrices[vertex]), parents.begin(), parents.end(), vertex);
		arma::mat R;
		if (!arma::chol(R, _scatterMatrices[vertex]->submat(parVec, parVec)))
			return std::numeric_limits<double>::quiet_NaN();
		arma::colvec c = arma::solve(arma::trimatl(arma::trans(R)),
				_scatterMatrices[vertex]->submat(parVec, vVec));
		//a -= arma::as_scalar(arma::trans(b) * arma::solve(arma::submat(*(_scatterMatrices[vertex]), parents.begin(), parents.end(), parents.begin(), parents.end()), b));
		a -= arma::dot(c, c);
	}

	// Finish calculation of partial BIC score
	return -0.5*(1. + log(a/_dataCount[vertex]))*_dataCount[vertex] - _lambda*(1. + parents.size());
}
コード例 #2
0
void iPhysicsController::AddOutputValue(ePhysicsControllerOutput aOutput,
                                        ePhysicsControllerAxis aAxis,
                                        float afVal)
{
    cVector3f vVec(0,0,0);

    switch(aAxis)
        {
        case ePhysicsControllerAxis_X:
            vVec.x = afVal;
            break;
        case ePhysicsControllerAxis_Y:
            vVec.y = afVal;
            break;
        case ePhysicsControllerAxis_Z:
            vVec.z = afVal;
            break;
        }

    if(mbMulMassWithOutput) vVec = vVec * mpBody->GetMass();

    //Set the output to body space
    vVec = cMath::MatrixMul(mpBody->GetLocalMatrix().GetRotation(), vVec);


    switch(aOutput)
        {
        case ePhysicsControllerOutput_Torque:
            mpBody->AddTorque(vVec);
            break;
        case ePhysicsControllerOutput_Force:
            mpBody->AddForce(vVec);
            break;
        }
}
コード例 #3
0
ファイル: eff_all.cpp プロジェクト: vermagav/mechmod
vec3_t CPartEffects::RandomRoundVec( vec3_t vMin, vec3_t vMax )
{
	float flMin, flMax;

	flMin = vMin.Length( );
	flMax = vMax.Length( );

	vec3_t vVec( gEngfuncs.pfnRandomFloat( vMin.x, vMax.x ), gEngfuncs.pfnRandomFloat( vMin.y, vMax.y ),
		gEngfuncs.pfnRandomFloat( vMin.z, vMax.z ) );
	vVec = vVec.Normalize( ) * gEngfuncs.pfnRandomFloat( flMin, flMax );

	return vVec;
}
コード例 #4
0
ファイル: SFXBeam.cpp プロジェクト: alanhorizon/Transcendence
void CBeamEffectCreator::DrawBeamHeavyBlaster (CG16bitImage &Dest, SLineDesc &Line, SViewportPaintCtx &Ctx)

//	DrawBeamHeavyBlaster
//
//	Draws the appropriate beam

	{
	//	Convert to an angle relative to xTo, yTo

	CVector vVec(Line.xFrom - Line.xTo, Line.yFrom - Line.yTo);
	Metric rRadius;
	int iAngle = VectorToPolar(vVec, &rRadius);
	int iRadius = (int)rRadius;

	//	Can't deal with 0 sized lines

	if (iRadius == 0)
		return;

	CG16bitRegion Region;
	SPoint Poly[8];

	//	Compute some metrics

	int iLengthUnit = iRadius * (10 + m_iIntensity) / 40;
	int iWidthUnit = Max(1, iRadius * m_iIntensity / 60);

	//	Paint the outer-most glow

	WORD wColor = CG16bitImage::BlendPixel(Ctx.wSpaceColor, m_wSecondaryColor, 100);
	CreateBlasterShape(iAngle, 4 * iLengthUnit, 3 * iWidthUnit / 2, Poly);
	Region.CreateFromConvexPolygon(8, Poly);
	Region.Fill(Dest, Line.xTo, Line.yTo, wColor);

	//	Paint the inner transition

	wColor = CG16bitImage::BlendPixel(m_wSecondaryColor, m_wPrimaryColor, 128);
	wColor = CG16bitImage::BlendPixel(Ctx.wSpaceColor, wColor, 200);
	CreateBlasterShape(iAngle, 3 * iLengthUnit, iWidthUnit, Poly);
	Region.CreateFromConvexPolygon(8, Poly);
	Region.Fill(Dest, Line.xTo, Line.yTo, wColor);

	//	Paint the inner core

	CreateBlasterShape(iAngle, iLengthUnit, iWidthUnit - 1, Poly);
	Region.CreateFromConvexPolygon(8, Poly);
	Region.Fill(Dest, Line.xTo, Line.yTo, m_wPrimaryColor);
	}
コード例 #5
0
ファイル: score.cpp プロジェクト: igraph/pcalg
std::vector<double> ScoreGaussL0PenScatter::localMLE(const uint vertex, const std::set<uint>& parents) const
{
	std::vector<double> result(parents.size() + 2);
	std::set<uint>::iterator pi;
	arma::colvec b;
	arma::mat S_papa, S_pav;
	arma::uvec parVec;
	arma::uvec vVec(1);

	dout.level(3) << "Calculating local MLE...\n";

	// Get parents, copy them to Armadillo vector
	parVec.set_size(_allowIntercept ? parents.size() + 1 : parents.size());
	std::copy(parents.begin(), parents.end(), parVec.begin());
	if (_allowIntercept)
		parVec[parents.size()] = _vertexCount;
	vVec[0] = vertex;
	dout.level(3) << "Vertex: " << vertex << "; parents (adjusted acc. to interc.): " << parVec << "\n";

	// Initialize parameter for variance
	result[0] = _scatterMatrices[vertex]->at(vertex, vertex) / _dataCount[vertex];

	// Calculate regression coefficients
	if (parVec.size()) {
		S_pav = _scatterMatrices[vertex]->submat(parVec, vVec);
		S_papa = _scatterMatrices[vertex]->submat(parVec, parVec);
		b = arma::solve(S_papa, S_pav);

		// Correct error variance
		result[0] += (arma::dot(b, S_papa * b) - 2. * arma::dot(S_pav, b)) / _dataCount[vertex];

		// Store intercept, if requested (otherwise 0)
		result[1] = (_allowIntercept ? b(b.n_elem - 1) : 0.);

		// Copy coefficients to result vector
		std::copy(b.memptr(), b.memptr() + (_allowIntercept ? b.n_elem - 1 : b.n_elem), result.begin() + 2);
	}

	dout.level(3) << "Local MLE: " << result << "\n";

	return result;
}
コード例 #6
0
ファイル: PlayerVehicle.cpp プロジェクト: Arc0re/lithtech
void PlayerVehicle::Respawn()
{
    LTFLOAT fRespawnTime = m_fRespawnTime;

	if (fRespawnTime >= 0.0f)
	{
        g_pLTServer->SetObjectPos(m_hObject, &m_vOriginalPos);
        g_pLTServer->SetObjectRotation(m_hObject, &m_rOriginalRot);

        LTVector vZero(0, 0, 0);
        g_pLTServer->SetVelocity(m_hObject, &vZero);
        g_pLTServer->SetAcceleration(m_hObject, &vZero);
	}
	else
	{
		fRespawnTime = 0.0f;
	}


	// Try to set our dims (make sure we fit where we were placed)...

	LTVector vDims = m_vOriginalDims;
    if (g_pLTServer->SetObjectDims2(m_hObject, &vDims) == LT_ERROR)
	{
        g_pLTServer->SetObjectDims2(m_hObject, &vDims);
	}

 	LTVector vVec(0, 0, 0);
	g_pLTServer->SetAcceleration(m_hObject, &vVec);
	g_pLTServer->SetVelocity(m_hObject, &vVec);

	uint32 dwFlags = g_pLTServer->GetObjectFlags(m_hObject);
	dwFlags &= ~FLAG_VISIBLE;
	dwFlags &= ~FLAG_GRAVITY;
    g_pLTServer->SetObjectFlags(m_hObject, dwFlags);

	m_RespawnTimer.Start(fRespawnTime);
    SetNextUpdate(0.001f);

	MoveObjectToFloor(m_hObject);
}
コード例 #7
0
ファイル: PlayerVehicle.cpp プロジェクト: Arc0re/lithtech
void PlayerVehicle::Respawn()
{
    LTFLOAT fRespawnTime = m_fRespawnTime;

	if (fRespawnTime >= 0.0f)
	{
		g_pLTServer->SetObjectPos(m_hObject, &m_vOriginalPos);
		g_pLTServer->SetObjectRotation(m_hObject, &m_rOriginalRot);

        LTVector vZero(0, 0, 0);
		g_pPhysicsLT->SetVelocity(m_hObject, &vZero);
	}
	else
	{
		fRespawnTime = 0.0f;
	}


	// Try to set our dims (make sure we fit where we were placed)...

	LTVector vDims = m_vOriginalDims;
    if (g_pPhysicsLT->SetObjectDims(m_hObject, &vDims, SETDIMS_PUSHOBJECTS) == LT_ERROR)
	{
        g_pPhysicsLT->SetObjectDims(m_hObject, &vDims, 0);
	}

 	LTVector vVec(0, 0, 0);
	g_pPhysicsLT->SetVelocity(m_hObject, &vVec);

	g_pCommonLT->SetObjectFlags(m_hObject, OFT_Flags, FLAG_VISIBLE, FLAG_VISIBLE );

	m_RespawnTimer.Start(fRespawnTime);
    SetNextUpdate(UPDATE_NEXT_FRAME);

	MoveObjectToFloor(m_hObject);
}
コード例 #8
0
ファイル: SFXBeam.cpp プロジェクト: alanhorizon/Transcendence
void CBeamEffectCreator::DrawBeamLightning (CG16bitImage &Dest, SLineDesc &Line, SViewportPaintCtx &Ctx)

//	DrawBeamLightning
//
//	Draws the appropriate beam

	{
	//	The central part of the beam is different depending on the
	//	intensity.

	if (m_iIntensity < 4)
		{
		WORD wStart = CG16bitImage::BlendPixel(Ctx.wSpaceColor, m_wPrimaryColor, 128);
		Dest.DrawBiColorLine(Line.xFrom, Line.yFrom,
				Line.xTo, Line.yTo,
				3,
				Ctx.wSpaceColor,
				wStart);

		WORD wEnd = CG16bitImage::BlendPixel(Ctx.wSpaceColor, m_wPrimaryColor, 155);
		Dest.DrawBiColorLine(Line.xFrom, Line.yFrom,
				Line.xTo, Line.yTo,
				1,
				wEnd,
				m_wPrimaryColor);
		}
	else if (m_iIntensity < 10)
		{
		WORD wStart = CG16bitImage::BlendPixel(Ctx.wSpaceColor, m_wSecondaryColor, 155);
		Dest.DrawBiColorLine(Line.xFrom, Line.yFrom,
				Line.xTo, Line.yTo,
				5,
				Ctx.wSpaceColor,
				wStart);

		Dest.DrawBiColorLine(Line.xFrom, Line.yFrom,
				Line.xTo, Line.yTo,
				3,
				Ctx.wSpaceColor,
				m_wSecondaryColor);

		WORD wEnd = CG16bitImage::BlendPixel(Ctx.wSpaceColor, m_wPrimaryColor, 155);
		Dest.DrawBiColorLine(Line.xFrom, Line.yFrom,
				Line.xTo, Line.yTo,
				1,
				wEnd,
				m_wPrimaryColor);
		}
	else
		{
		//	Convert to an angle relative to xTo, yTo

		CVector vVec(Line.xFrom - Line.xTo, Line.yFrom - Line.yTo);
		Metric rRadius;
		int iAngle = VectorToPolar(vVec, &rRadius);
		int iRadius = (int)rRadius;

		//	Can't deal with 0 sized lines

		if (iRadius == 0)
			return;

		CG16bitRegion Region;
		SPoint Poly[8];

		//	Paint the outer-most glow

		WORD wColor = CG16bitImage::BlendPixel(Ctx.wSpaceColor, m_wSecondaryColor, 100);
		CreateBlasterShape(iAngle, iRadius, iRadius / 6, Poly);
		Region.CreateFromConvexPolygon(8, Poly);
		Region.Fill(Dest, Line.xTo, Line.yTo, wColor);

		//	Paint the inner transition

		wColor = CG16bitImage::BlendPixel(m_wSecondaryColor, m_wPrimaryColor, 128);
		wColor = CG16bitImage::BlendPixel(Ctx.wSpaceColor, wColor, 200);
		CreateBlasterShape(iAngle, iRadius * 2 / 3, iRadius / 7, Poly);
		Region.CreateFromConvexPolygon(8, Poly);
		Region.Fill(Dest, Line.xTo, Line.yTo, wColor);

		//	Paint the inner core

		CreateBlasterShape(iAngle, iRadius / 2, iRadius / 8, Poly);
		Region.CreateFromConvexPolygon(8, Poly);
		Region.Fill(Dest, Line.xTo, Line.yTo, m_wPrimaryColor);
		}

	//	Compute the half-way point

	int xHalf = (Line.xFrom + Line.xTo) / 2;
	int yHalf = (Line.yFrom + Line.yTo) / 2;

	//	Draw lightning

	int iCount = m_iIntensity + mathRandom(0, 2);
	for (int j = 0; j < iCount; j++)
		if (mathRandom(1, 2) == 1)
			DrawLightning(Dest, 
					xHalf, 
					yHalf, 
					Line.xTo, 
					Line.yTo, 
					m_wPrimaryColor, 
					LIGHTNING_POINT_COUNT, 
					0.5);
		else
			DrawLightning(Dest, 
					Line.xFrom, 
					Line.yFrom, 
					Line.xTo, 
					Line.yTo, 
					m_wSecondaryColor, 
					LIGHTNING_POINT_COUNT, 
					0.3);
	}
コード例 #9
0
void CTransitionAggregate::Load( ILTMessage_Read *pMsg, uint32 dwLoadFlags )
{
	if( !pMsg ) return;
	
	LOAD_HOBJECT( m_hObject );

	// The rest is dependent on the load type...

	if( dwLoadFlags != LOAD_TRANSITION ) return;
	
	HOBJECT hTransArea = g_pTransMgr->GetTransitionArea();
	if( !hTransArea ) return;
	
	TransitionArea *pTransArea = (TransitionArea*)g_pLTServer->HandleToObject( hTransArea );
	if( !pTransArea ) return;

	LTransform tfLocal;
	LTransform tfObjectWorld;
	LTVector vVelRel;
	LTransform const& tfTransAreaWorld = pTransArea->GetWorldTransform( );
	LTMatrix mRotation;
	tfTransAreaWorld.m_Rot.ConvertToMatrix( mRotation );

	LOAD_VECTOR( tfLocal.m_Pos );
	LOAD_ROTATION( tfLocal.m_Rot );
	LOAD_VECTOR( vVelRel );
	
	// Calc pos and rot based on offsets and current TransArea...

	tfObjectWorld.m_Pos = tfTransAreaWorld.m_Pos + ( mRotation * tfLocal.m_Pos );
	tfObjectWorld.m_Rot = tfTransAreaWorld.m_Rot * tfLocal.m_Rot;
	LTVector vVel = mRotation * vVelRel;

	if( IsPlayer( m_hObject ))
	{
		// Since the PlayerObj is controlled by the client we need to notify the
		// client of the rotation.  We are only worried about the Yaw since Roll doesn't 
		// matter and Pitch can be preserved on the client.


		CPlayerObj *pPlayer = (CPlayerObj*)g_pLTServer->HandleToObject( m_hObject );
		if( !pPlayer ) return;

		
		LTFLOAT		fYaw;
		LTVector	vF = tfObjectWorld.m_Rot.Forward();

		// We don't care about Roll...

		vF.y = 0.0f; 
		vF.Normalize();

		// Yaw = arctan( vF.x / vF.z );
		// atan2 is well defined even for vF.z == 0

		fYaw = (LTFLOAT)atan2( vF.x, vF.z );
		
		// Inform the client of the correct camera/player orientation...

		LTVector vVec( 0.0f, fYaw, 0.0f );
		
		CAutoMessage cMsg;
		cMsg.Writeuint8( MID_PLAYER_ORIENTATION );
		cMsg.Writeuint8( MID_ORIENTATION_YAW );
		cMsg.WriteLTVector( vVec );
		g_pLTServer->SendToClient(cMsg.Read(), pPlayer->GetClient(), MESSAGE_GUARANTEED);
		
	}

	g_pLTServer->SetObjectPos( m_hObject, &tfObjectWorld.m_Pos );
	g_pLTServer->SetObjectRotation( m_hObject, &tfObjectWorld.m_Rot );
	g_pPhysicsLT->SetVelocity( m_hObject, &vVel );
}