Exemplo n.º 1
0
	QuadSceneNode::QuadSceneNode(float x, float y, float w, float h)
	{
		vertex[0] = Vertex3f(0,0,1);
		vertex[1] = Vertex3f(0,h,1);
		vertex[2] = Vertex3f(w,h,1);
		vertex[3] = Vertex3f(w,0,1);

		color[0] = Color3f(1,1,1);
		color[1] = Color3f(1,1,1);
		color[2] = Color3f(1,1,1);
		color[3] = Color3f(1,1,1);

		this->translate(x,y);
	}
Exemplo n.º 2
0
unsigned int MDCSurface_read(Surface& surface, const byte* buffer)
{
  mdcSurface_t mdcSurface;
  {
    PointerInputStream inputStream(buffer);
    istream_read_mdcSurface(inputStream, mdcSurface);
  }

  {
    surface.vertices().reserve(mdcSurface.numVerts);

    PointerInputStream xyzStream(buffer + mdcSurface.ofsXyzNormals);
    PointerInputStream stStream(buffer + mdcSurface.ofsSt);
    // read verts into vertex array - xyz, st, normal
    for(std::size_t i = 0; i < mdcSurface.numVerts; i++)
	  {
      mdcXyzNormal_t mdcXyzNormal;
      istream_read_mdcXyzNormal(xyzStream, mdcXyzNormal);
      mdcSt_t mdcSt;
      istream_read_mdcSt(stStream, mdcSt);

      surface.vertices().push_back(
        ArbitraryMeshVertex(
          Vertex3f( mdcXyzNormal.xyz[0] * MDC_XYZ_SCALE, mdcXyzNormal.xyz[1] * MDC_XYZ_SCALE, mdcXyzNormal.xyz[2] * MDC_XYZ_SCALE),
          DecodeNormal(reinterpret_cast<byte*>(&mdcXyzNormal.normal)),
          TexCoord2f(mdcSt.st[0], mdcSt.st[1])
        )
      );
    }
  }

  {
 	  surface.indices().reserve(mdcSurface.numTriangles * 3);

    PointerInputStream triangleStream(buffer + mdcSurface.ofsTriangles);

    for(std::size_t i = 0; i < mdcSurface.numTriangles; i++)
    {
      mdcTriangle_t triangle;
      istream_read_mdcTriangle(triangleStream, triangle);
      surface.indices().insert(triangle.indexes[0]);
      surface.indices().insert(triangle.indexes[1]);
      surface.indices().insert(triangle.indexes[2]);
    }
  }

  {
    mdcShader_t shader;
    PointerInputStream inputStream(buffer + mdcSurface.ofsShaders);
    istream_read_mdcShader(inputStream, shader);
    surface.setShader(shader.name);
  }
	
	surface.updateAABB();

  return mdcSurface.ofsEnd;
}
Exemplo n.º 3
0
inline ArbitraryMeshVertex MDLVertex_construct( const mdlHeader_t& header, const mdlXyzNormal_t& xyz, const mdlSt_t& st, bool facesfront ){
	return ArbitraryMeshVertex(
			   Vertex3f(
				   xyz.v[0] * header.scale[0] + header.scale_origin[0],
				   xyz.v[1] * header.scale[1] + header.scale_origin[1],
				   xyz.v[2] * header.scale[2] + header.scale_origin[2]
				   ),
			   Normal3f(
				   g_mdl_normals[xyz.lightnormalindex][0],
				   g_mdl_normals[xyz.lightnormalindex][1],
				   g_mdl_normals[xyz.lightnormalindex][2]
				   ),
			   TexCoord2f(
				   ( (float)st.s / header.skinwidth ) + ( ( st.onseam == MDL_ONSEAM && !facesfront ) ? 0.5f : 0.0f ),
				   (float)st.t / header.skinheight
				   )
			   );
}
Exemplo n.º 4
0
ArbitraryMeshVertex MD2Vertex_construct( const md2Header_t* pHeader, const md2Frame_t* pFrame, const md2XyzNormal_t* xyz, const md2St_t* st ){
	return ArbitraryMeshVertex(
			   Vertex3f(
				   xyz->v[0] * pFrame->scale[0] + pFrame->translate[0],
				   xyz->v[1] * pFrame->scale[1] + pFrame->translate[1],
				   xyz->v[2] * pFrame->scale[2] + pFrame->translate[2]
				   ),
			   Normal3f(
				   g_mdl_normals[xyz->lightnormalindex][0],
				   g_mdl_normals[xyz->lightnormalindex][1],
				   g_mdl_normals[xyz->lightnormalindex][2]
				   ),
			   TexCoord2f(
				   (float)st->s / pHeader->skinwidth,
				   (float)st->t / pHeader->skinheight
				   )
			   );
}
Exemplo n.º 5
0
GameObjectNode::GameObjectNode( GameObject *gameObject ) {
	this->gameObject_ = gameObject;
	this->setPosition( 0.0f, 0.0f, 0.0f );
	this->setRotation( 0.0f, 0.0f, 0.0f );
	this->setVelocity( 0.0f, 0.0f, 0.0f );
	this->setAcceleration( 0.0f, 0.0f, 0.0f );
	this->setAngleVelocity( 0.0f, 0.0f, 0.0f );
	this->displayListId_ = SceneNode::INVALID_HANDLE;

	// create bounding box
	if( gameObject->getModel() != NULL ) {
		std::vector<Vertex3f> *modelVertices = gameObject->getModel()->getVertices();
		float minX = (*modelVertices)[0].getX();
		float maxX = (*modelVertices)[0].getX();
		float minY = (*modelVertices)[0].getY();
		float maxY = (*modelVertices)[0].getY();
		float minZ = (*modelVertices)[0].getZ();
		float maxZ = (*modelVertices)[0].getZ();
		for ( std::vector<Vertex3f>::iterator i = (modelVertices->begin() + 1); i != modelVertices->end(); ++i ) {
			// x
			if ( i->getX() < minX )			minX = i->getX();
			else if ( i->getX() > maxX )	maxX = i->getX();
			// y
			if ( i->getY() < minY )			minY = i->getY();
			else if ( i->getY() > maxY )	maxY = i->getY();
			// z
			if ( i->getZ() < minZ )			minZ = i->getZ();
			else if ( i->getZ() > maxZ )	maxZ = i->getZ();
		}
		this->boundingBox_.push_back( Vertex3f( minX, minY, minZ ) );
		this->boundingBox_.push_back( Vertex3f( maxX, minY, minZ ) );
		this->boundingBox_.push_back( Vertex3f( maxX, maxY, minZ ) );
		this->boundingBox_.push_back( Vertex3f( minX, maxY, minZ ) );

		this->boundingBox_.push_back( Vertex3f( maxX, minY, maxZ ) );
		this->boundingBox_.push_back( Vertex3f( maxX, maxY, maxZ ) );
		this->boundingBox_.push_back( Vertex3f( minX, maxY, maxZ ) );
		this->boundingBox_.push_back( Vertex3f( minX, minY, maxZ ) );
	}
};
Exemplo n.º 6
0
void fhImmediateMode::Vertex2f(float x, float y)
{
  Vertex3f(x, y, 0.0f);
}
Exemplo n.º 7
0
void fhImmediateMode::Vertex3fv(const float* c)
{
  Vertex3f(c[0], c[1], c[2]);
}
Exemplo n.º 8
0
Vertex3f Vertex3f::operator+(const Vector3f& right) const{
	return(Vertex3f(x+right.x, y+right.y, z+right.z));
}
Exemplo n.º 9
0
Vertex3f Vertex3f::operator*(float right) const{
	return(Vertex3f(x*right, y*right, z*right));
}
Exemplo n.º 10
0
Vertex3f Vertex3f::operator-(const Vector3f& right) const{
	return(Vertex3f(x-right.x, y-right.y, z-right.z));
}
Exemplo n.º 11
0
void Tri_DrawScaledSprite( HSPRITE hSprite, int frame, int r, int g, int b, int a, const RenderMode renderMode, const float flScale, ITriCoordFallback& callback, const wrect_t* pSpriteRect )
{
	if( hSprite == INVALID_HSPRITE )
	{
		gEngfuncs.Con_DPrintf( "Tri_DrawScaledSprite: hSprite is invalid!\n" );
		return;
	}

	const int iOrigWidth = gEngfuncs.pfnSPR_Width( hSprite, frame );
	const int iOrigHeight = gEngfuncs.pfnSPR_Height( hSprite, frame );

	wrect_t subRect;

	if( pSpriteRect )
	{
		subRect = *pSpriteRect;
	}
	else
	{
		subRect.left = subRect.top = 0;
		subRect.right = iOrigWidth;
		subRect.bottom = iOrigHeight;
	}

	int x, y;

	//Fallback on Software; no scaling or render mode support. - Solokiller
	if( !IEngineStudio.IsHardware() )
	{
		//Always scale 1. - Solokiller
		callback.Calculate( hSprite, frame, subRect, 1.0f, x, y );

		gEngfuncs.pfnSPR_Set( hSprite, r, g, b );

		gEngfuncs.pfnSPR_DrawHoles( frame, x, y, pSpriteRect );

		return;
	}

	wrect_t rect;

	//Trim a pixel border around it, since it blends. - Solokiller
	rect.left = subRect.left * flScale + ( flScale - 1 );
	rect.top = subRect.top * flScale + ( flScale - 1 );
	rect.right = subRect.right * flScale - ( flScale - 1 );
	rect.bottom = subRect.bottom * flScale - ( flScale - 1 );

	const int iWidth = iOrigWidth * flScale;
	const int iHeight = iOrigHeight * flScale;

	callback.Calculate( hSprite, frame, rect, flScale, x, y );

	model_t* pCrosshair = const_cast<model_t*>( gEngfuncs.GetSpritePointer( hSprite ) );

	auto TriAPI = gEngfuncs.pTriAPI;

	TriAPI->SpriteTexture( pCrosshair, frame );

	TriAPI->Color4fRendermode( r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f, renderMode );
	TriAPI->RenderMode( renderMode );

	float flLeft = 0;
	float flTop = 0;
	float flRight = 1.0;
	float flBottom = 1.0f;

	int iImgWidth = iWidth;
	int iImgHeight = iHeight;

	AdjustSubRect( iWidth, iHeight, &flLeft, &flRight, &flTop, &flBottom, &iImgWidth, &iImgHeight, &rect );

	TriAPI->Begin( TriangleMode::TRI_QUADS );

	TriAPI->TexCoord2f( flLeft, flTop );
	TriAPI->Vertex3f( x, y, 0 );

	TriAPI->TexCoord2f( flRight, flTop );
	TriAPI->Vertex3f( x + iImgWidth, y, 0 );

	TriAPI->TexCoord2f( flRight, flBottom );
	TriAPI->Vertex3f( x + iImgWidth, y + iImgHeight, 0 );

	TriAPI->TexCoord2f( flLeft, flBottom );
	TriAPI->Vertex3f( x, y + iImgHeight, 0 );

	TriAPI->End();
}