Exemplo n.º 1
0
void EngineEntityT::Draw(bool FirstPersonView, const VectorT& ViewerPos) const
{
    MatSys::Renderer->PushMatrix(MatSys::RendererI::MODEL_TO_WORLD);
    MatSys::Renderer->PushLightingParameters();

    unsigned short Ent_Heading;
    unsigned short Ent_Pitch;
    unsigned short Ent_Bank;

    Entity->GetBodyOrientation(Ent_Heading, Ent_Pitch, Ent_Bank);

    // Get the currently set lighting parameters.
    const float* PosL=MatSys::Renderer->GetCurrentLightSourcePosition();
    VectorT      LightSourcePos   =VectorT(PosL[0], PosL[1], PosL[2]);
    float        LightSourceRadius=MatSys::Renderer->GetCurrentLightSourceRadius();

    const float* PosE=MatSys::Renderer->GetCurrentEyePosition();
    VectorT      EyePos=VectorT(PosE[0], PosE[1], PosE[2]);


    // Starting from world space, compute the position of the light source in model space.
    LightSourcePos=LightSourcePos-Entity->GetOrigin();         // Convert into unrotated model space.
    LightSourcePos=LightSourcePos.GetRotZ(-90.0+float(Ent_Heading)/8192.0*45.0);
    LightSourcePos=scale(LightSourcePos, 1.0/25.4);

    // Don't forget to scale the radius of the light source appropriately down (into model space), too.
    LightSourceRadius/=25.4f;


    // Do the same for the eye: Starting from world space, compute the position of the eye in model space.
    EyePos=EyePos-Entity->GetOrigin();         // Convert into unrotated model space.
    EyePos=EyePos.GetRotZ(-90.0+float(Ent_Heading)/8192.0*45.0);
    EyePos=scale(EyePos, 1.0/25.4);


    // Set the modified (now in model space) lighting parameters.
    MatSys::Renderer->SetCurrentLightSourcePosition(float(LightSourcePos.x), float(LightSourcePos.y), float(LightSourcePos.z));
    MatSys::Renderer->SetCurrentLightSourceRadius(LightSourceRadius);
    MatSys::Renderer->SetCurrentEyePosition(float(EyePos.x), float(EyePos.y), float(EyePos.z));


    // Set the ambient light color for this entity.
    // Paradoxically, this is not a global, but rather a per-entity value that is derived from the lightmaps that are close to that entity.
    const Vector3fT AmbientEntityLight=Entity->GetGameWorld()->GetAmbientLightColorFromBB(Entity->GetDimensions(), Entity->GetOrigin());
    MatSys::Renderer->SetCurrentAmbientLightColor(AmbientEntityLight.x, AmbientEntityLight.y, AmbientEntityLight.z);


    MatSys::Renderer->Translate(MatSys::RendererI::MODEL_TO_WORLD, float(Entity->GetOrigin().x), float(Entity->GetOrigin().y), float(Entity->GetOrigin().z));
    MatSys::Renderer->RotateZ  (MatSys::RendererI::MODEL_TO_WORLD, 90.0f-float(Ent_Heading)/8192.0f*45.0f);
    MatSys::Renderer->Scale    (MatSys::RendererI::MODEL_TO_WORLD, 25.4f);

    Entity->Draw(FirstPersonView, (float)length(ViewerPos-Entity->GetOrigin()));


    MatSys::Renderer->PopLightingParameters();
    MatSys::Renderer->PopMatrix(MatSys::RendererI::MODEL_TO_WORLD);
}
Exemplo n.º 2
0
VectorT HSVToRGB(VectorT hsv){
	int i;
	float f, p, q, t;
	float h,s,v;
	float r,g,b;
	h=hsv.x;
	s=hsv.y;
	v=hsv.z;

	if( s == 0 ) {
		// achromatic (grey)
		return VectorT(v,v,v);
	}

	h /= 60;			// sector 0 to 5
	i = (int)floor( h );
	f = h - i;			// factorial part of h
	p = v * ( 1 - s );
	q = v * ( 1 - s * f );
	t = v * ( 1 - s * ( 1 - f ) );

	switch( i ) {
		case 0:
			r = v;
			g = t;
			b = p;
			break;
		case 1:
			r = q;
			g = v;
			b = p;
			break;
		case 2:
			r = p;
			g = v;
			b = t;
			break;
		case 3:
			r = p;
			g = q;
			b = v;
			break;
		case 4:
			r = t;
			g = p;
			b = v;
			break;
		default:		// case 5:
			r = v;
			g = p;
			b = q;
			break;
	}
	return VectorT(r,g,b);

}
Exemplo n.º 3
0
VectorT valueToRedGreen(float n){
	if(n<0) n=0;
	VectorT color(0,0,0);
	if(n>1.0) n-=(int)n;
	int block=(int)(n/.5);
	float v=(n-(block*.5f))/.5f;
	switch(block){
		case 0: color=VectorT(1,v,0); break;
		case 1: color=VectorT(1-v,1,0); break;
		case 2: color=VectorT(0,1,0); break;
	}
	return color;
}
Exemplo n.º 4
0
EntFuncLadderT::EntFuncLadderT(const EntityCreateParamsT& Params)
    : BaseEntityT(Params,
                  EntityStateT(VectorT(),   // Origin
                               VectorT(),   // Velocity
                               BoundingBox3T<double>(Vector3dT()),
                               0,           // Heading
                               0,           // Pitch
                               0,           // Bank
                               0,
                               0,
                               0,           // ModelIndex
                               0,           // ModelSequNr
                               0.0,         // ModelFrameNr
                               0,           // Health
                               0,           // Armor
                               0,           // HaveItems
                               0,           // HaveWeapons
                               0,           // ActiveWeaponSlot
                               0,           // ActiveWeaponSequNr
                               0.0))        // ActiveWeaponFrameNr
   // RootNode(Params.RootNode)
{
    assert(CollisionModel!=NULL);   // A ladder entity without collision model is useless.

    // Registering the clip model with the clip world is very important, so that we cannot run "into" ladder brushes.
    // !!! Note that ladder brushes are currently always at the origin (0, 0, 0).
    // !!! That is the only reason why we don't need to call e.g. ClipModel.SetOrigin()
    // !!! AND don't need to provide the Cl_UnserializeFrom() method!
    ClipModel.Register();


    // Corresponding to this entities CollisionModelT, use the related btCollisionShape
    // for adding a btRigidBody (which "is a" btCollisionObject) to the PhysicsWorld.
    btCollisionShape* LadderShape=CollisionModel->GetBulletAdapter();

    m_RigidBody=new btRigidBody(btRigidBody::btRigidBodyConstructionInfo(0, NULL /*MotionState*/, LadderShape, btVector3(0, 0, 0)));
    m_RigidBody->setUserPointer(this);  // This entity is associated to the m_RigidBody.

    PhysicsWorld->AddRigidBody(m_RigidBody);
}
Exemplo n.º 5
0
 typename viennacl::enable_if< viennacl::is_mtl4< typename viennacl::traits::tag_of< MatrixT >::type >::value,
                               VectorT>::type
 prod(MatrixT const& matrix, VectorT const& vector)
 {
   return VectorT(matrix * vector);
 }