void CDX9Renderer::FillGradient(const rect& r, const color& c1, const color& c2, gradient_direction dir)
	{
		SetTexture(NULL);

		color vs[4];

		switch (dir) {
		case dir_up:
			SetVertices(vs, c2, c2, c1, c1);
			Quad(r, vs);
			break;
		case dir_down:
			SetVertices(vs, c1, c1, c2, c2);
			Quad(r, vs);
			break;
		case dir_left:
			SetVertices(vs, c2, c1, c2, c1);
			Quad(r, vs);
			break;
		case dir_right:
			SetVertices(vs, c1, c2, c1, c2);
			Quad(r, vs);
			break;
		}
	}
	void CDX9Renderer::FillGradient(const rect& r, cr_float angle, point hotspot, const color& c1, const color& c2, gradient_direction dir)
	{
		quad q((r - hotspot).rotate_to_quad(angle, r.topleft()));

		SetTexture(NULL);

		color vs[4];

		switch (dir) {
		case dir_up:
			SetVertices(vs, c2, c2, c1, c1);
			Quad(r, vs);
			break;
		case dir_down:
			SetVertices(vs, c1, c1, c2, c2);
			Quad(r, vs);
			break;
		case dir_left:
			SetVertices(vs, c2, c1, c2, c1);
			Quad(r, vs);
			break;
		case dir_right:
			SetVertices(vs, c1, c2, c1, c2);
			Quad(r, vs);
			break;
		}
	}
Exemplo n.º 3
0
Arquivo: Box.cpp Projeto: latuya23/rt2
Box::Box(glm::dvec3 minv, glm::dvec3 maxv) {
  m_min = minv;
  m_max = maxv;
  m_transform = glm::dmat4(1.0);
  m_boxId = Box::next_box_id();
  SetVertices();
  }
Exemplo n.º 4
0
 Polygon::Polygon(vec2* aVertices, unsigned int aCount) : GameObject("Polygon"),
     m_Shader(nullptr),
     m_AnchorPoint(0.0f, 0.0f),
     m_AnchorLocation(0.0f, 0.0f),
     m_Color(Color::BlueColor()),
     m_RenderMode(GL_TRIANGLE_FAN),
     m_IsFilled(true),
     m_PointSize(1.0f),
     m_TweenAnchorX(),
     m_TweenAnchorY(),
     m_TweenAlpha(),
     m_VertexArrayObject(0),
     m_VertexBufferObject(0)
 {
     //Set the shader as the default passthrough shader
     SetShader(ServiceLocator::GetShaderManager()->GetPassthroughShader());
     
     //Set the vertices
     SetVertices(aVertices, aCount);
     
     //Intialize the position and angle
     SetLocalPosition(vec2(0.0f, 0.0f));
     SetLocalAngle(0.0f);
     
     //Set the model matrix to dirty
     ModelMatrixIsDirty(true);
 }
Exemplo n.º 5
0
//**************************************************
// public functions
//**************************************************
bool wxSFIfShape::CreateFromXPM(const char* const* bits)
{
	bool fSuccess = false;

	// create bitmap from XPM
	m_Image = wxImage(bits);
	fSuccess = m_Image.IsOk();

	if(!fSuccess)
	{
		m_Image = wxImage(NoSource_xpm);
	}

	m_OriginalImage = m_Image;

	m_nRectSize.x = m_Image.GetWidth();
	m_nRectSize.y = m_Image.GetHeight();

	wxRealPoint diamond[4]={wxRealPoint(0,						m_Image.GetHeight()/2), 
							wxRealPoint(m_Image.GetWidth()/2,	0), 
							wxRealPoint(m_Image.GetWidth(),		m_Image.GetHeight()/2), 
							wxRealPoint(m_Image.GetWidth()/2,	m_Image.GetHeight())};
	SetVertices(4, diamond);

	if(m_fCanScale)
	{
		AddStyle(sfsSIZE_CHANGE);
	}
	else
		RemoveStyle(sfsSIZE_CHANGE);

	return fSuccess;
}
Exemplo n.º 6
0
	//! called during the initialization of the entity
	void TrailEntity::Init()
	{
		GraphicComponent* gc = GetComponent<GraphicComponent>();
		if (!gc)
		{
			gc = snew GraphicComponent();
			gc->SetRenderingPass(GraphicComponent::RP_3DTransparent);
			AddComponent(gc, true);
		}

		auto numTriangles = (m_NumEdges - 1) * 2;
		auto numVertices = numTriangles * 3;
		auto vb = GraphicsDriver::Instance()->CreateVertexBuffer();
		vb->SetName(GetClassName());
		vb->SetDynamic(true);
		vb->SetVertices(snew Vertex3D[numVertices], numVertices, Vertex3D::VF_Pos | Vertex3D::VF_UV | Vertex3D::VF_Color);
		vb->SetNumVertices(0);
		vb->SetApplyWorldTransforms(false);
		gc->SetVertexBuffer(vb);

		auto startingPos = GetAbsolutePosition();
		for (uint i = 0; i < m_NumEdges; ++i)
			m_Points.push_back(startingPos);

		super::Init();
	}
Exemplo n.º 7
0
Triangle::Triangle(void)
{
    //Renderable::Renderable();
    std::vector<GLfloat>* v = new std::vector<GLfloat>(g_vertex_buffer_data, g_vertex_buffer_data + sizeof(g_vertex_buffer_data) / sizeof(g_vertex_buffer_data[0]));
    SetVertices(v);
    free(v);
}
Exemplo n.º 8
0
Arquivo: Box.cpp Projeto: latuya23/rt2
Box::Box(glm::dvec3 minv, glm::dvec3 maxv, glm::dmat4 modelM) {
  m_min = minv;
  m_max = maxv;
  m_transform = modelM;
  m_boxId = Box::next_box_id();
  SetVertices();
}
Exemplo n.º 9
0
void TestSoftbody::DrawShadow(const RenderContext* pRenderContext)
{
    pRenderContext->GetPreShadowEffect()->SetWorldViewProjection(pRenderContext->GetCamera()->GetViewProjection());
	
	SetVertices();

    m_pSoftbodyMesh->Draw(pRenderContext->GetPreShadowEffect());
}
Exemplo n.º 10
0
void Square::SetPosition(GLfloat _X, GLfloat _Y)
{
	//position.X = _X;
	//position.Y = _Y;
	originPosition[0] = _X;
	originPosition[1] = _Y;
	SetVertices();
}
Exemplo n.º 11
0
cStarShape::cStarShape()
{
    // disable serialization of polygon vertices, because they are always set
    // in this constructor
	EnablePropertySerialization(wxT("vertices"), false);
    // set polygon vertices
	SetVertices(10, star);

    // initialize shape
    Initialize();
}
Exemplo n.º 12
0
void TestSoftbody::Draw(const RenderContext* pRenderContext)
{
    m_pEffect->SetWorldViewProjection(pRenderContext->GetCamera()->GetViewProjection());
    m_pEffect->SetWorld(Matrix::Identity);
    m_pEffect->SetDiffuseMap(m_pDiffuseMap);
    m_pEffect->SetSpecMap(m_pSpecMap);
    m_pEffect->SetGlossMap(m_pGlossMap);

	SetVertices();

    m_pSoftbodyMesh->Draw(m_pEffect);
}
Exemplo n.º 13
0
Square::Square(GLfloat _size)
{
	size = _size;
	//position.X = 0;
	//position.Y = 0;
	originPosition[0] = 0;
	originPosition[1] = 0;
	originPosition[2] = 0;
	r = (sqrtf( 2.0 ) * size)/2;
	angle = (GLfloat)(PI * 45 /180);
	SetVertices();
}
Exemplo n.º 14
0
void CollisionChain2D::SetVerticesAttr(const std::vector<unsigned char>& value)
{
    if (value.empty())
        return;

    std::vector<Vector2> vertices;

    MemoryBuffer buffer(value);
    while (!buffer.IsEof())
        vertices.push_back(buffer.ReadVector2());

    SetVertices(vertices);
}
Exemplo n.º 15
0
void VertexArray::SetTo2DQuad(float x1, float y1, float x2, float y2, float u1, float v1, float u2, float v2, float z)
{
	float vcorners[12];
	float uvs[8];
	int bfaces[6];
	SetVertexData2DQuad(x1,y1,x2,y2,u1,v1,u2,v2, vcorners, uvs, bfaces);
	for (int i = 2; i < 12; i += 3)
		vcorners[i] = z;
	SetFaces(bfaces, 6);
	SetVertices(vcorners, 12);
	SetTexCoordSets(1);
	SetTexCoords(0, uvs, 8);
}
Exemplo n.º 16
0
void CollisionChain2D::SetVerticesAttr(const PODVector<unsigned char>& value)
{
    if (value.Empty())
        return;

    PODVector<Vector2> vertices;

    MemoryBuffer buffer(value);
    while (!buffer.IsEof())
        vertices.Push(buffer.ReadVector2());

    SetVertices(vertices);
}
Exemplo n.º 17
0
void VertexArray::Add(
	const unsigned char newcol[], int newcolcount,
	const float newnorm[], int newnormcount,
	const float newvert[], int newvertcount,
	const int newfaces[], int newfacecount,
	const float newtc[], int newtccount)
{
	assert(texcoords.size() == 1);
	SetFaces(newfaces, newfacecount, faces.size(), vertices.size() / 3);
	SetVertices(newvert, newvertcount, vertices.size());
	SetNormals(newnorm, newnormcount, normals.size());
	SetColors(newcol, newcolcount, colors.size());
	SetTexCoords(0, newtc, newtccount, texcoords[0].size());
}
Exemplo n.º 18
0
    void VertexArray::Init(const TriangleMesh *mesh)
    {
        const int ctVertices = mesh->mPositions.size();
        const int ctIndices = mesh->mIndices.size();

        AddAttributes(mesh->GetVertexAttribDefs());
        Init(ctVertices, ctVertices);

        SetVertices(static_cast<const GLvoid*>(mesh->GetVertexArray().data()), 0, ctVertices);

        if(ctIndices > 0)
        {
            void *indices = mesh->GetIndices();
            SetIndices(indices, ctIndices, mesh->GetIndexType());
            delete[] indices;
        }
    }
Exemplo n.º 19
0
FaceMesh::FaceMesh()
{
	
	mVertices = new Vertices();
	mIndices = new Indices();

	mVertices->Allocate(sizeof(Vertex), 4);
	mIndices->Allocate(4);

	mVertices->PutValues(gVertices);
	mIndices->PutValues(gIndices);

	SetVertices(mVertices);
	SetIndices(mIndices);

	
	mIndices->mTriangleMode = TrianglesModeTrianglesStrip;
}
Exemplo n.º 20
0
void VertexArray::SetTo2DButton(float x, float y, float w, float h, float sidewidth, bool flip)
{
	float vcorners[12*3];
	float uvs[8*3];
	int bfaces[6*3];

	//y1 = 1.0 - y1;
	//y2 = 1.0 - y2;

	Vec2 corner1;
	Vec2 corner2;
	Vec2 dim;
	dim.Set(w,h);
	Vec2 center;
	center.Set(x,y);
	corner1 = center - dim*0.5;
	corner2 = center + dim*0.5;

	float x1 = corner1[0];
	float y1 = corner1[1];
	float x2 = corner2[0];
	float y2 = corner2[1];

	if (flip)
	{
		float y3 = y1;
		y1 = y2;
		y2 = y3;
	}

	//left
	SetVertexData2DQuad(x1-sidewidth,y1,x1,y2, 0,0,0.5,1, vcorners, uvs, bfaces);

	//center
	SetVertexData2DQuad(x1,y1,x2,y2, 0.5,0,0.5,1, &(vcorners[12]), &(uvs[8]), &(bfaces[6]), 4);

	//right
	SetVertexData2DQuad(x2,y1,x2+sidewidth,y2, 0.5,0,1,1, &(vcorners[12*2]), &(uvs[8*2]), &(bfaces[6*2]), 8);

	SetFaces(bfaces, 6*3);
	SetVertices(vcorners, 12*3);
	SetTexCoordSets(1);
	SetTexCoords(0, uvs, 8*3);
}
Exemplo n.º 21
0
void Flipper::PreRender(Sur * const psur)
{
   const float anglerad = ANGTORAD(m_d.m_StartAngle);
   //const float anglerad2 = ANGTORAD(m_d.m_EndAngle);

   m_d.m_FlipperRadius = m_d.m_FlipperRadiusMax;

   psur->SetFillColor(m_ptable->RenderSolid() ? RGB(192,192,192) : -1);
   psur->SetBorderColor(-1,false,0);
   psur->SetLineColor(RGB(0,0,0), false, 0);

   Vertex2D vendcenter;
   Vertex2D rgv[4];
   SetVertices(m_d.m_Center.x, m_d.m_Center.y, anglerad, &vendcenter, rgv, m_d.m_BaseRadius, m_d.m_EndRadius);

   psur->SetObject(this);

   psur->Polygon(rgv, 4);
   psur->Ellipse(m_d.m_Center.x, m_d.m_Center.y, m_d.m_BaseRadius);
   psur->Ellipse(vendcenter.x, vendcenter.y, m_d.m_EndRadius);
}
Exemplo n.º 22
0
void VertexArray::SetToBillboard(float x1, float y1, float x2, float y2)
{
	int bfaces[6];
	bfaces[0] = 0;
	bfaces[1] = 1;
	bfaces[2] = 2;
	bfaces[3] = 0;
	bfaces[4] = 2;
	bfaces[5] = 3;
	SetFaces(bfaces, 6);

	float normals[12];
	for (int i = 0; i < 12; i+=3)
	{
		normals[i] = 0;
		normals[i+1] = 0;
		normals[i+2] = 1;
	}
	SetNormals(normals, 12);

	//build this:
	//x1, y1, 0
	//x2, y1, 0
	//x2, y2, 0
	//x1, y2, 0
	float verts[12];
	verts[2] = verts[5] = verts[8] = verts[11] = 0.0;
	verts[0] = verts[9] = x1;
	verts[3] = verts[6] = x2;
	verts[1] = verts[4] = y1;
	verts[7] = verts[10] = y2;
	SetVertices(verts, 12);

	float tc[8];
	tc[0] = tc[1] = tc[3] = tc[6] = 0.0;
	tc[2] = tc[4] = tc[5] = tc[7] = 1.0;
	SetTexCoordSets(1);
	SetTexCoords(0, tc, 8);
}
Exemplo n.º 23
0
//**************************************************
bool wxSFIfShape::CreateFromImage(wxImage *image)
{
	bool fSuccess = true;

	if(image)
	{
		m_Image = *image;
		fSuccess = true;
	}
	else
		fSuccess = false;

	if(!fSuccess)
	{
		m_Image = wxImage(NoSource_xpm);
	}

	m_OriginalImage = m_Image;

	m_nRectSize.x = m_Image.GetWidth();
	m_nRectSize.y = m_Image.GetHeight();

	wxRealPoint diamond[4]={wxRealPoint(0,						m_Image.GetHeight()/2), 
							wxRealPoint(m_Image.GetWidth()/2,	0), 
							wxRealPoint(m_Image.GetWidth(),		m_Image.GetHeight()/2), 
							wxRealPoint(m_Image.GetWidth()/2,	m_Image.GetHeight())};
	SetVertices(4, diamond);

	if(m_fCanScale)
	{
		AddStyle(sfsSIZE_CHANGE);
	}
	else
		RemoveStyle(sfsSIZE_CHANGE);

	return fSuccess;
}
Exemplo n.º 24
0
 Polygon::Polygon(vec2* aVertices, unsigned int aCount, Shader* aShader) : GameObject("Polygon"),
     m_Shader(aShader),
     m_AnchorPoint(0.0f, 0.0f),
     m_AnchorLocation(0.0f, 0.0f),
     m_Color(Color::BlackColor()),
     m_RenderMode(GL_TRIANGLE_FAN),
     m_IsFilled(true),
     m_PointSize(1.0f),
     m_TweenAnchorX(),
     m_TweenAnchorY(),
     m_TweenAlpha(),
     m_VertexArrayObject(0),
     m_VertexBufferObject(0)
 {
     //Set the vertices
     SetVertices(aVertices, aCount);
 
     //Intialize the position and angle
     SetLocalPosition(vec2(0.0f, 0.0f));
     SetLocalAngle(0.0f);
     
     //Set the model matrix to dirty
     ModelMatrixIsDirty();
 }
void ModelLoader::CreateVertexBuffer( Vertex::VERTEX_TYPE type ) {
	aiMesh* mesh = scene->mMeshes[0];
	UINT count = mesh->mNumVertices;
	aiVector3D* vertices = mesh->mVertices;
	/*  The switch case looks like duplicated code.  It is not.	 vertData is a different type in each and SetVertices() is a template. */
	switch( type ) {
	case Vertex::BASIC_32:
	{
		std::vector<Vertex::Basic32> vertData( count );
		aiVector3D* normals = mesh->mNormals;
		aiVector3D* texCoords = mesh->mTextureCoords[0];
		for( UINT i = 0; i<count; ++i ) {
			UpdateExtents( vertices[i].x, vertices[i].y, vertices[i].z );
			vertData[i].Pos = XMFLOAT3( vertices[i].x, vertices[i].y, vertices[i].z );
			vertData[i].Normal = XMFLOAT3( normals[i].x, normals[i].y, normals[i].z );
			vertData[i].Tex = XMFLOAT2( texCoords[i].x, texCoords[i].y );
		}
		SetVertices( device, count, vertData.data() );
		break;
	}
	case Vertex::POS_NORMAL_TEX_TAN:
	{
		aiVector3D* normals = mesh->mNormals;
		aiVector3D* texCoords = mesh->mTextureCoords[0];
		aiVector3D* tangents = mesh->mTangents;
		std::vector<Vertex::PosNormalTexTan> vertData( count );
		for( UINT i = 0; i<count; ++i ) {
			UpdateExtents( vertices[i].x, vertices[i].y, vertices[i].z );
			vertData[i].Pos = XMFLOAT3( vertices[i].x, vertices[i].y, vertices[i].z );
			vertData[i].Normal = XMFLOAT3( normals[i].x, normals[i].y, normals[i].z );
			vertData[i].Tex = XMFLOAT2( texCoords[i].x, texCoords[i].y );
			vertData[i].TangentU = XMFLOAT4( tangents[i].x, tangents[i].y, tangents[i].z, 0.f );
		}
		SetVertices( device, count, vertData.data() );
		break;
	}
	case Vertex::POS_NORMAL_TEX_TAN_SKINNED:
	{
		aiVector3D* normals = mesh->mNormals;
		aiVector3D* texCoords = mesh->mTextureCoords[0];
		aiVector3D* tangents = mesh->mTangents;
		std::vector<Vertex::PosNormalTexTanSkinned> vertData( count );
		for( UINT i = 0; i<count; ++i ) {
			UpdateExtents( vertices[i].x, vertices[i].y, vertices[i].z );
			vertData[i].Pos = XMFLOAT3( vertices[i].x, vertices[i].y, vertices[i].z );
			vertData[i].Normal = XMFLOAT3( normals[i].x, normals[i].y, normals[i].z );
			vertData[i].Tex = XMFLOAT2( texCoords[i].x, texCoords[i].y );
			vertData[i].TangentU = XMFLOAT4( tangents[i].x, tangents[i].y, tangents[i].z, 0.f );
		}

		// Bone Data
		std::multimap<int, BoneWeight> vertexBoneWeight;
		for( unsigned int boneIndex = 0; boneIndex<mesh->mNumBones; ++boneIndex ) {
			auto bone = mesh->mBones[boneIndex];
			for( int i = 0; i<bone->mNumWeights; ++i ) {
				auto boneWeight = BoneWeight( boneIndex, bone->mWeights[i].mWeight );
				vertexBoneWeight.insert( std::pair<int, BoneWeight>( bone->mWeights[i].mVertexId, boneWeight ) );
			}
		}
		for( UINT i = 0; i<count; ++i ) {
			BYTE boneIndices[4] = { 0, 0, 0, 0 };
			float weights[4] = { 0, 0, 0, 0 };
			int j = 0;
			auto itlow = vertexBoneWeight.lower_bound( i );
			auto itup = vertexBoneWeight.upper_bound( i );
			assert( itlow!=itup ); // every vertex should have some influence
			for( auto it = itlow; it!=itup; ++it ) {
				if( j>3 ) {
					assert( false ); // only 4 boes should influence one vertex
					break;
				}
				boneIndices[j] = it->second.boneIndex;
				weights[j] = it->second.weight;
				++j;
			}
			vertData[i].BoneIndicies[0] = boneIndices[0];
			vertData[i].BoneIndicies[1] = boneIndices[1];
			vertData[i].BoneIndicies[2] = boneIndices[2];
			vertData[i].BoneIndicies[3] = boneIndices[3];
			vertData[i].Weights = XMFLOAT4( weights );
		}

		SetVertices( device, count, vertData.data() );
		break;
	}
	}
}
Exemplo n.º 26
0
	//! serializes the entity to/from a PropertyStream
	void ParticleGenerator::Serialize(PropertyStream& stream)
	{
		super::Serialize(stream);
		
		stream.Serialize("MaxParticles", &m_MaxParticles);
		stream.Serialize("ParticlesPerSecond", &m_ParticlesPerSecond);
		stream.Serialize("ParticleLife", &m_rParticleLife);
		stream.Serialize("ParticleSpeed", &m_rParticleInitialSpeed);
		stream.Serialize("ParticleSize", &m_fParticleSize);
		stream.Serialize("Direction", &m_vDirection);
		stream.Serialize("Gravity", &m_vGravity);
		stream.Serialize("EmitBox", &m_EmitBox);
		stream.Serialize("ActiveTime", &m_fActiveTime);
		stream.Serialize("EmitType", &m_eEmitType, ENUM_PARAMS1(g_strEmitTypeLiterals));
		E_ParticleShape shape = m_eParticleShape;
		stream.Serialize("ParticleShape", &shape, ENUM_PARAMS1(g_strParticleShapeLiterals));
		stream.Serialize("ConeAngle", &m_fConeAngle);
		stream.Serialize("SparkFactor", &m_fSparkFactor);		
		stream.Serialize("SizeFunc", &m_SizeFunc, ENUM_PARAMS1(g_strParticleSizeFuncLiterals));
		stream.Serialize("SizeFuncFactor", &m_SizeFuncFactor);
		stream.Serialize("ApplyWorldTransform", &m_bApplyWorldTransform);
		stream.Serialize("InstancedRendering", &m_bInstancedRendering);

		if(stream.GetMode() != SM_Read)
			return;
		
		switch(m_eEmitType)
		{
		case ET_Box:
			m_PreEmitFunctor = &ParticleGenerator::PreEmitNull;
			m_EmitFunctor = &ParticleGenerator::EmitBox;			
			break;

		case ET_Explosion:
			m_PreEmitFunctor = &ParticleGenerator::PreEmitNull;
			m_EmitFunctor = &ParticleGenerator::EmitExplosion;
			break;

		case ET_Cone:
			m_PreEmitFunctor = &ParticleGenerator::PreEmitCone;
			m_EmitFunctor = &ParticleGenerator::EmitCone;
			break;
		}

		switch (m_SizeFunc)
		{
		case SF_Constant:
			m_SizeFuncFunctor = &ParticleGenerator::SizeFuncConstant;
			break;

		case SF_Grow:
			m_SizeFuncFunctor = &ParticleGenerator::SizeFuncGrow;
			break;

		case SF_Shrink:
			m_SizeFuncFunctor = &ParticleGenerator::SizeFuncShrink;
			break;
		}
		
		m_vDirection.Normalize();
		m_fHalfSize = m_fParticleSize/2.0f;
		m_bActive = true;
		auto shapeChanged = (m_eParticleShape != shape);
		m_eParticleShape = shape;

		if(!IsInitialized())
			return;

		auto vb = GetComponent<GraphicComponent>()->GetVertexBuffer();
		vb->SetApplyWorldTransforms(m_bApplyWorldTransform);

		if (shapeChanged)
		{
			auto numParticleVertices = OnParticleShapeChanged(vb);
			vb->SetVertices(snew Vertex3D[m_MaxParticles*numParticleVertices], m_MaxParticles*numParticleVertices, Vertex3D::VF_Pos | Vertex3D::VF_UV | Vertex3D::VF_Color);			
		}	
	}	
Exemplo n.º 27
0
Triangle::Triangle(const Vertex& v1, const Vertex& v2,
                   const Vertex& v3) {
    SetVertices(v1, v2, v3); 
}
Exemplo n.º 28
0
//----------------------------------------------------------------------------
SegmentGraph::Edge::Edge (Vertex* vertex0, Vertex* vertex1)
{
    SetVertices(vertex0, vertex1);
}
Exemplo n.º 29
0
bool ON_Brep::ReadOld200( ON_BinaryArchive& file, int minor_version )
{
  bool rc = true;

  // read legacy trimmed surface collection from Rhino 2.0

  int face_count = 0;
  int edge_count = 0;
  int loop_count = 0;
  int trim_count = 0;
  int outer_flag = 0;

  ON_BoundingBox bnd_2d_bbox;
  int i, fi, fbi, fbcnt, bti, btcnt, twin_index;
  int ftype_flag, btype_flag, gcon_flag, mono_flag;
  char b;

  if (rc) rc = file.ReadInt( &face_count );
  if (rc) rc = file.ReadInt( &edge_count );
  if (rc) rc = file.ReadInt( &loop_count );
  if (rc) rc = file.ReadInt( &trim_count );

  if ( face_count < 1 || edge_count < 1 || loop_count < 1 || trim_count < 1 )
    rc = false;

  if (rc) rc = file.ReadInt( &outer_flag );
  if (rc) rc = file.ReadPoint( m_bbox.m_min );
  if (rc) rc = file.ReadPoint( m_bbox.m_max );

  // 2d curves
  m_C2.Reserve(trim_count);
  for ( i = 0; rc && i < trim_count; i++ ) {
    ON_PolyCurve* curve = new ON_PolyCurve();
    rc = curve->Read( file )?true:false;
    if ( curve->Count() == 1 ) {
      m_C2.Append( curve->HarvestSegment(0) );
      delete curve;
    }
    else
      m_C2.Append( curve );
  }
  const int c2_count = m_C2.Count();

  // 3d curves
  m_C3.Reserve(edge_count);
  for ( i = 0; rc && i < edge_count; i++ ) {
    ON_PolyCurve* curve = new ON_PolyCurve();
    rc = curve->Read( file )?true:false;
    if ( curve->Count() == 1 ) {
      m_C3.Append( curve->HarvestSegment(0) );
      delete curve;
    }
    else
      m_C3.Append( curve );
  }
  const int c3_count = m_C3.Count();

  // make a new edge for each 3d curve
  m_E.Reserve(c3_count);
  for ( i = 0; i < c3_count && rc; i++ )
  {
    NewEdge(i);
  }

  // 3d surfaces
  m_S.Reserve(face_count);
  for ( i = 0; rc && i < face_count; i++ ) {
    ON_NurbsSurface* surface = new ON_NurbsSurface();
    rc = surface->Read( file )?true:false;
    m_S.Append( surface );
  }

  ON_SimpleArray<int> te_index(trim_count);
  ON_SimpleArray<int> te_twin_index(trim_count);

  m_F.Reserve(face_count);
  m_L.Reserve(loop_count);
  m_T.Reserve(trim_count);

  for ( fi = 0; rc && fi < face_count; fi++ )
  {
    ftype_flag = 0;
    fbcnt = 0;
    ON_BrepFace& f = NewFace(fi);
    if (rc) rc = file.ReadInt( &i ); // legacy face index
    if (rc) rc = file.ReadInt( &i ); // OBSOLETE f.m_material_index
    int k = f.m_bRev;
    if (rc) rc = file.ReadInt( &k );
    if (rc) f.m_bRev = (k!=0);
    if (rc) rc = file.ReadInt( &ftype_flag );
    if (rc) rc = file.ReadPoint( f.m_bbox.m_min );
    if (rc) rc = file.ReadPoint( f.m_bbox.m_max );
    if (rc) rc = file.ReadInt( &fbcnt);
    if (fbcnt < 1 )
      rc = false;
    for ( fbi = 0; rc && fbi < fbcnt; fbi++ ) {
      btype_flag = 0;
      ON_BrepLoop::TYPE looptype = ON_BrepLoop::unknown;
      if (rc) rc = file.ReadInt( &i ); // legacy loop index
      if (rc) rc = file.ReadInt( &btype_flag );
      switch (btype_flag)
      {
      case 0:
        looptype = ON_BrepLoop::outer;
        break;
      case 1:
        looptype = ON_BrepLoop::inner;
        break;
      case -1:
        looptype = ON_BrepLoop::slit;
        break;
      default:
        looptype = ON_BrepLoop::unknown;
        break;
      }
      if (rc) rc = file.ReadDouble( 2, &bnd_2d_bbox.m_min.x );
      if (rc) rc = file.ReadDouble( 2, &bnd_2d_bbox.m_max.x );
      btcnt = 0;
      if (rc) rc = file.ReadInt( &btcnt );
      if (btcnt < 1 )
        rc = false;
      ON_BrepLoop& bnd = NewLoop(looptype,f);
      for ( bti = 0; rc && bti < btcnt; bti++ ) {
        ON_BrepTrim& trim = NewTrim(false,bnd,m_T.Count());
        te_index.Append(trim.m_trim_index);
        if (rc) rc = file.ReadInt( &i ); // legacy trim index
        if ( trim.m_trim_index != i )
        {
          ON_ERROR("ON_Brep::ReadOld200 - trim.m_trim_index out of synch.");
          //rc = false;
          //break;
        }
        if (rc) rc = file.ReadInt( &twin_index );
        te_twin_index.Append(twin_index);
        b = 0;
        if (rc) rc = file.ReadChar( &b ); // true if legacy trim managed 3d edge
        if (rc) rc = file.ReadInt( &trim.m_ei );
        if (b) {
          if ( trim.m_ei < 0 || trim.m_ei >= c3_count )
          {
            trim.m_ei = -1;
            ON_ERROR("ON_Brep::ReadOld201 - trim.m_ei out of range.");
            rc = false;
            break;
          }
        }
        if ( trim.m_trim_index >= 0 && trim.m_trim_index < c2_count )
          trim.m_c2i = trim.m_trim_index;
        else {
          ON_ERROR("ON_Brep::ReadOld200 - trim.m_trim_index out of range.");
          rc = false;
          trim.m_c2i = -1;
          break;
        }
        int k = trim.m_bRev3d;
        if (rc) rc = file.ReadInt(&k);
        if (rc) trim.m_bRev3d = (k!=0);
        if (rc) rc = file.ReadInt(&gcon_flag);
        if (rc) rc = file.ReadInt(&mono_flag);
        if (rc) rc = file.ReadDouble(&trim.m__legacy_3d_tol);
        if (rc) rc = file.ReadDouble(&trim.m__legacy_2d_tol);
      }
    }
  }

  // finish hooking trims to edges
  if (rc) {
    int trim_index;
    for ( i = 0; i < trim_count; i++ ) {
      trim_index = te_index[i];
      if ( trim_index >= 0 && trim_index < m_T.Count() )
        continue;
      twin_index = te_twin_index[i];
      if ( twin_index >= 0 && twin_index < m_T.Count() )
        continue;
      ON_BrepTrim& trim1 = m_T[trim_index];
      ON_BrepTrim& trim2 = m_T[twin_index];
      if ( trim1.m_ei >= 0 && trim1.m_ei < c2_count && trim2.m_ei < 0 )
        trim2.m_ei = trim1.m_ei;
      else if ( trim2.m_ei >= 0 && trim2.m_ei < c2_count && trim1.m_ei < 0 )
        trim1.m_ei = trim2.m_ei;
    }
    for ( i = 0; i < m_T.Count(); i++ ) {
      ON_BrepTrim& trim = m_T[i];
      ON_Curve* tcurve = m_C2[trim.m_c2i];
      trim.SetProxyCurve( tcurve );
      if ( trim.m_ei >= 0 && trim.m_ei < c3_count )
        m_E[trim.m_ei].m_ti.Append(trim.m_trim_index);
    }


    // finish setting flags
    SetTrimIsoFlags();
    SetTrimTypeFlags();

    // create 3d vertex information
    SetVertices();

    // set tols from values in file
    SetTolsFromLegacyValues();

  }
  else {
    Destroy();
  }

  if (rc) {
    // 3d render mesh geometry
    ON_Object* obj;
    for ( i = 0; rc && i < face_count; i++ ) {
      ON_BrepFace& f = m_F[i];
      file.ReadChar(&b);
      if (b) {
        obj = 0;
        rc = (file.ReadObject(&obj)==1)?true:false;
        f.m_render_mesh = ON_Mesh::Cast(obj);
        if ( !f.m_render_mesh )
          delete obj;
      }
    }
    if ( !rc ) {
      // delete render mesh geometry
      for ( i = 0; i < face_count; i++ ) {
        ON_BrepFace& f = m_F[i];
        if ( f.m_render_mesh ) {
          delete f.m_render_mesh;
          f.m_render_mesh = 0;
        }
      }
    }

    if (rc && minor_version >= 1) {
      // 3d analysis mesh geometry
      for ( i = 0; rc && i < face_count; i++ ) {
        ON_BrepFace& f = m_F[i];
        file.ReadChar(&b);
        if (b) {
          obj = 0;
          rc = file.ReadObject(&obj)?true:false;
          f.m_analysis_mesh = ON_Mesh::Cast(obj);
          if ( !f.m_analysis_mesh )
            delete obj;
        }
      }
      if ( !rc ) {
        // delete analysis mesh geometry
        for ( i = 0; i < face_count; i++ ) {
          ON_BrepFace& f = m_F[i];
          if ( f.m_analysis_mesh ) {
            delete f.m_analysis_mesh;
            f.m_analysis_mesh = 0;
          }
        }
      }
    }

    // fill in missing information
    ReadFillInMissingBoxes(*this);

    if (!rc ) {
      ON_ERROR("ON_Brep::ReadOld201() - trouble reading render/analysis meshes");
      rc = true;
    }
  }

  // 22 April 2003:
  //   Use outer_flag to set m_is_solid for closed solids
  //   with outward pointing normals.
  if ( 1 == outer_flag && IsSolid() )
    m_is_solid = 1;

  return rc;
}
Exemplo n.º 30
0
void VertexArray::SetTo2DBox(float x, float y, float w, float h, float marginwidth, float marginheight, float clipx)
{
	const unsigned int quads = 9;
	float vcorners[12*quads];
	float uvs[8*quads];
	int bfaces[6*quads];

	//y1 = 1.0 - y1;
	//y2 = 1.0 - y2;

	Vec2 corner1;
	Vec2 corner2;
	Vec2 dim;
	dim.Set(w,h);
	Vec2 center;
	center.Set(x,y);
	corner1 = center - dim*0.5;
	corner2 = center + dim*0.5;
	Vec2 margin;
	margin.Set(marginwidth, marginheight);

	float lxmax = std::max((corner1-margin)[0],std::min(clipx,corner1[0]));
	float cxmax = std::max(corner1[0],std::min(clipx,corner2[0]));
	float rxmax = std::max(corner2[0],std::min(clipx,(corner2+margin)[0]));
	float lumax = (lxmax-(corner1-margin)[0])/(corner1[0]-(corner1-margin)[0])*0.5;
	float rumax = (rxmax-corner2[0])/((corner2+margin)[0]-corner2[0])*0.5+0.5;

	//upper left
	SetVertexData2DQuad((corner1-margin)[0],(corner1-margin)[1],lxmax,corner1[1],
			    0,0,lumax,0.5, vcorners,uvs,bfaces);

	//upper center
	SetVertexData2DQuad(corner1[0],(corner1-margin)[1],cxmax,corner1[1],
			     0.5,0,0.5,0.5,
			     &(vcorners[12*1]),&(uvs[8*1]),&(bfaces[6*1]),4*1);

	//upper right
	SetVertexData2DQuad(corner2[0],(corner1-margin)[1],rxmax,corner1[1],
			    0.5,0,rumax,0.5,
			    &(vcorners[12*2]),&(uvs[8*2]),&(bfaces[6*2]),4*2);

	//center left
	SetVertexData2DQuad((corner1-margin)[0],corner1[1],lxmax,corner2[1],
			    0,0.5,lumax,0.5,
			    &(vcorners[12*3]),&(uvs[8*3]),&(bfaces[6*3]),4*3);

	//center center
	SetVertexData2DQuad(corner1[0],corner1[1],cxmax,corner2[1],
			    0.5,0.5,0.5,0.5,
			    &(vcorners[12*4]),&(uvs[8*4]),&(bfaces[6*4]),4*4);

	//center right
	SetVertexData2DQuad(corner2[0],corner1[1],rxmax,corner2[1],
			    0.5,0.5,rumax,0.5,
			    &(vcorners[12*5]),&(uvs[8*5]),&(bfaces[6*5]),4*5);

	//lower left
	SetVertexData2DQuad((corner1-margin)[0],corner2[1],lxmax,(corner2+margin)[1],
			    0,0.5,lumax,1,
			    &(vcorners[12*6]),&(uvs[8*6]),&(bfaces[6*6]),4*6);

	//lower center
	SetVertexData2DQuad(corner1[0],corner2[1],cxmax,(corner2+margin)[1],
			    0.5,0.5,0.5,1,
			    &(vcorners[12*7]),&(uvs[8*7]),&(bfaces[6*7]),4*7);

	//lower right
	SetVertexData2DQuad(corner2[0],corner2[1],rxmax,(corner2+margin)[1],
			    0.5,0.5,rumax,1,
			    &(vcorners[12*8]),&(uvs[8*8]),&(bfaces[6*8]),4*8);

	SetFaces(bfaces, 6*quads);
	SetVertices(vcorners, 12*quads);
	SetTexCoordSets(1);
	SetTexCoords(0, uvs, 8*quads);
}