📄 cvtextur.cpp
字号:
#endif
/////////////////////////////////////////////////////////////
ChQvConeTextures::ChQvConeTextures( ChQvConeInstance *pInst, int iNumFacets )
: ChQvTextureMap(pInst), m_iNumFacets(iNumFacets)
{
float pi = atan(1.) * 4.;
float twoPi = pi * 2;
m_fStep = twoPi / m_iNumFacets;
//m_fStep = 1. / m_iNumFacets;
m_boolIsDefault = true;
};
#if defined(CH_USE_3DR)
PointF_t ChQvConeTextures::GetCoord3(int part, int facet, int vert)
{
PointF_t texCoord;
// assumes we start at top back, then go down & ccw
// we assume a quadstrip facet model
// each facet has two vertices; one at top and one bottom
switch( part )
{
case 0:
{
texCoord.x = facet / float(m_iNumFacets); // facets: 0 to numFacets, inclusive
texCoord.y = (vert & 1) ? 1. : 0.;
texCoord.z = 1;
break;
}
case 1:
{ // note bottom starts at 180 (front), and goes cw
float theta = m_fStep * vert + PI; // verts: 0 to numFacets, inclusive
texCoord.x = .5 + sin(theta) * .5; // opp direction from top
texCoord.y = .5 - cos(theta) * .5;
texCoord.z = 1;
break;
}
default:
{ // error
break;
}
}
// Transform the coords
texCoord.y = 1. - texCoord.y; // to vrml
((ChQvTexture2TransformRenderData*)(m_pInst->GetTexture2Transform()->GetRenderData()))
->Transform(texCoord.x, texCoord.y);
texCoord.y = 1. - texCoord.y; // back to 3dr
return texCoord;
};
#elif (defined(CH_USE_RLAB) || defined(CH_USE_D3D))
GxVec3f ChQvConeTextures::GetCoord3(ChQvConeInstance::Parts part, int facet, int vert)
{
GxVec3f texCoord;
// assumes we start at top back, then go down & ccw
// we assume a quadstrip facet model
// each facet has two vertices; one at top and one bottom
switch( part )
{
case ChQvConeInstance::Sides:
{
texCoord.x() = (facet + (.5 * vert)) / float(m_iNumFacets); //
texCoord.y() = (vert & 1) ? 0. : 1.; // middle is top
texCoord.z() = 1;
break;
}
case ChQvConeInstance::Bottom:
{ // note bottom starts at 180 (front), and goes cw
float theta = m_fStep * vert + PI; // verts: 0 to numFacets, inclusive
texCoord.x() = .5 + sin(theta) * .5; // opp direction from top
texCoord.y() = .5 - cos(theta) * .5;
texCoord.z() = 1;
break;
}
default:
{ // error
break;
}
}
// Transform the coords
texCoord.y() = 1. - texCoord.y(); // to vrml
((ChQvTexture2TransformRenderData*)(m_pInst->GetTexture2Transform()->GetRenderData()))
->Transform(texCoord.x(), texCoord.y());
texCoord.y() = 1. - texCoord.y(); // back to 3dr
return texCoord;
};
#endif
/////////////////////////////////////////////////////////////
ChQvCubeTextures::ChQvCubeTextures( ChQvCubeInstance *pInst ) : ChQvTextureMap(pInst)
{
m_boolIsDefault = true;
}
#if defined(CH_USE_3DR)
PointF_t ChQvCubeTextures::GetCoord3(int face, int vert)
{
PointF_t texCoord;
texCoord.x = (vert == 0 || vert == 3) ? 0. : 1.;
texCoord.y = (vert == 0 || vert == 1) ? 0. : 1.;
// Transform the coords
texCoord.y = 1. - texCoord.y; // to vrml
((ChQvTexture2TransformRenderData*)(m_pInst->GetTexture2Transform()->GetRenderData()))
->Transform(texCoord.x, texCoord.y);
texCoord.y = 1. - texCoord.y; // back to 3dr
texCoord.z = 1;
return texCoord;
};
#else
GxVec3f ChQvCubeTextures::GetCoord3(int face, int vert)
{
GxVec3f texCoord;
texCoord.x() = (vert == 0 || vert == 3) ? 0. : 1.;
texCoord.y() = (vert == 0 || vert == 1) ? 0. : 1.;
// Transform the coords
texCoord.y() = 1. - texCoord.y(); // to vrml
((ChQvTexture2TransformRenderData*)(m_pInst->GetTexture2Transform()->GetRenderData()))
->Transform(texCoord.x(), texCoord.y());
texCoord.y() = 1. - texCoord.y(); // back to 3dr
texCoord.z() = 1;
return texCoord;
};
#endif
//////////////////////////////////////////////////////////////////
ChQvCylinderTextures::ChQvCylinderTextures( ChQvCylinderInstance *pInst, int iNumFacets )
: ChQvTextureMap(pInst), m_iNumFacets(iNumFacets)
{
float pi = atan(1.) * 4.;
float twoPi = pi * 2;
m_fStep = twoPi / m_iNumFacets;
m_boolIsDefault = true;
};
#if defined(CH_USE_3DR)
PointF_t ChQvCylinderTextures::GetCoord3(int part, int facet, int vert)
{ // TODO get rid of this and use gxvec3f
PointF_t texCoord;
// assumes we start at top back, then go down & ccw
// we assume a quadstrip facet model
// each facet has two vertices; one at top and one bottom
switch( part )
{
case 0:
{
texCoord.x = facet / float(m_iNumFacets); // facets: 0 to numFacets, inclusive
texCoord.y = (vert & 1) ? 1. : 0.;
texCoord.z = 1;
break;
}
case 1:
{ // start at 0, and go ccw
float theta = m_fStep * vert; // verts: 0 to numFacets, inclusive
texCoord.x = .5 - sin(theta) * .5;
texCoord.y = .5 - cos(theta) * .5;
texCoord.z = 1;
break;
}
case 2:
{ // note bottom starts at 180 (front), and goes cw
float theta = m_fStep * vert + PI; // verts: 0 to numFacets, inclusive
texCoord.x = .5 + sin(theta) * .5; // opp direction from top
texCoord.y = .5 - cos(theta) * .5;
texCoord.z = 1;
break;
}
default:
{ // error
break;
}
}
// Transform the coords
texCoord.y = 1. - texCoord.y; // to vrml
((ChQvTexture2TransformRenderData*)(m_pInst->GetTexture2Transform()->GetRenderData()))
->Transform(texCoord.x, texCoord.y);
texCoord.y = 1. - texCoord.y; // back to 3dr
return texCoord;
};
#else
GxVec3f ChQvCylinderTextures::GetCoord3(ChQvCylinderInstance::Parts part, int facet, int vert)
{
GxVec3f texCoord; // 0 is sides, 1 is top, 2 is bottom
// assumes we start at top back, then go down & ccw
// we assume a quadstrip facet model
// each facet has two vertices; one at top and one bottom
switch( part )
{
case ChQvCylinderInstance::Sides:
{
if(vert > 1) facet++;
texCoord.x() = facet / float(m_iNumFacets); // facets: 0 to numFacets, inclusive
texCoord.y() = (vert & 1) ? 1. : 0.;
texCoord.z() = 1;
break;
}
case ChQvCylinderInstance::Top:
{ // start at 0, and go ccw
float theta = m_fStep * vert; // verts: 0 to numFacets, inclusive
texCoord.x() = .5 - sin(theta) * .5;
texCoord.y() = .5 - cos(theta) * .5;
texCoord.z() = 1;
break;
}
case ChQvCylinderInstance::Bottom:
{ // note bottom starts at 180 (front), and goes cw
float theta = m_fStep * vert + PI; // verts: 0 to numFacets, inclusive
texCoord.x() = .5 + sin(theta) * .5; // opp direction from top
texCoord.y() = .5 - cos(theta) * .5;
texCoord.z() = 1;
break;
}
default:
{ // error
break;
}
}
// Transform the coords
texCoord.y() = 1. - texCoord.y(); // to vrml
((ChQvTexture2TransformRenderData*)(m_pInst->GetTexture2Transform()->GetRenderData()))
->Transform(texCoord.x(), texCoord.y());
texCoord.y() = 1. - texCoord.y(); // back to rlab
return texCoord;
};
#endif
ChQvIFSTextures::ChQvIFSTextures( ChQvIFSInstance *pInst)
{
m_pInst = pInst;
QvIndexedFaceSet* pNode = (QvIndexedFaceSet*)(pInst->GetNode());
m_boolIsDefault = true;
// Ignore completely degenerate maps,
// it's probably our default node anyways.
// But we accept even a two point map
if(pInst->GetTextureCoordinate2()->point.num > 1)
{
m_pTx2 =(float*)((QvMFVec2f*)(pInst->GetTextureCoordinate2()->point.values));
m_boolIsDefault = false;
// Do we have a coord index array with our node?
if(pNode->textureCoordIndex.num > 1)
{
m_pIndices = pNode->textureCoordIndex.values;
m_numIndices = pNode->textureCoordIndex.num;
// Validate map indices, use defaults if bad
for(int j=0; j < pNode->textureCoordIndex.num && pNode->textureCoordIndex.values[j] != -1; j++)
{
if(pNode->textureCoordIndex.values[j] < -1 ||
pNode->textureCoordIndex.values[j] >= pInst->GetTextureCoordinate2()->point.num)
{
m_boolIsDefault = true;
break;
}
}
}
}
if(m_boolIsDefault)
{
// Compute default parameters
GxVec3f bounds[2], center;
QvCoordinate3 *pC3 = pInst->GetCoordinate3();
GetBoundingCube( &pNode->coordIndex, pC3, bounds[0], bounds[1], center);
float extent[3];
extent[0] = bounds[1].x() - bounds[0].x();
extent[1] = bounds[1].y() - bounds[0].y();
extent[2] = bounds[1].z() - bounds[0].z();
m_iMajor = 0;
if(extent[1] > extent[m_iMajor]) m_iMajor = 1;
if(extent[2] > extent[m_iMajor]) m_iMajor = 2;
m_iMinor = (m_iMajor+1)%3;
if(extent[(m_iMinor+1)%3] > extent[m_iMinor]) m_iMinor = (m_iMinor+1)%3;
m_fMajorLen = extent[m_iMajor];
if(m_iMinor==0) m_fMinorOff = bounds[0].x();
if(m_iMinor==1) m_fMinorOff = bounds[1].y();
if(m_iMinor==2) m_fMinorOff = bounds[0].z();
if(m_iMajor==0) m_fMajorOff = bounds[0].x();
if(m_iMajor==1) m_fMajorOff = bounds[1].y();
if(m_iMajor==2) m_fMajorOff = bounds[0].z();
#if !defined(CH_USE_3DR)
if(m_iMinor==1) m_fMinorOff = bounds[0].y();
if(m_iMajor==1) m_fMajorOff = bounds[0].y();
#endif
}
};
ChQvILSTextures::ChQvILSTextures( ChQvILSInstance *pInst) : ChQvIndexedTextures(pInst)
{
QvIndexedLineSet* pNode = (QvIndexedLineSet*)(pInst->GetNode());
m_boolIsDefault = true;
if(pInst->GetTextureCoordinate2()->point.num > 1)
{
m_pTx2 =(float*)((QvMFVec2f*)(pInst->GetTextureCoordinate2()->point.values));
m_boolIsDefault = false;
// Do we have a coord index array with our node?
if(pNode->textureCoordIndex.num > 1)
{
m_pIndices = pNode->textureCoordIndex.values;
m_numIndices = pNode->textureCoordIndex.num;
// Validate map indices, use defaults if bad
for(int j=0; j < pNode->textureCoordIndex.num && pNode->textureCoordIndex.values[j] != -1; j++)
{
if(pNode->textureCoordIndex.values[j] < -1 ||
pNode->textureCoordIndex.values[j] >= pInst->GetTextureCoordinate2()->point.num)
{
m_boolIsDefault = true;
break;
}
}
}
}
if(m_boolIsDefault)
{
m_boolIsDefault = true;
// Compute default parameters
GxVec3f bounds[2], center;
QvCoordinate3 *pC3 = pInst->GetCoordinate3();
GetBoundingCube( &pNode->coordIndex, pC3, bounds[0], bounds[1], center);
float extent[3];
extent[0] = bounds[1].x - bounds[0].x;
extent[1] = bounds[1].y - bounds[0].y;
extent[2] = bounds[1].z - bounds[0].z;
m_iMajor = 0;
if(extent[1] > extent[m_iMajor]) m_iMajor = 1;
if(extent[2] > extent[m_iMajor]) m_iMajor = 2;
m_iMinor = (m_iMajor+1)%3;
if(extent[(m_iMinor+1)%3] > extent[m_iMinor]) m_iMinor = (m_iMinor+1)%3;
m_fMajorLen = extent[m_iMajor];
if(m_iMinor==0) m_fMinorOff = bounds[0].x;
if(m_iMinor==1) m_fMinorOff = bounds[1].y;
if(m_iMinor==2) m_fMinorOff = bounds[0].z;
if(m_iMajor==0) m_fMajorOff = bounds[0].x;
if(m_iMajor==1) m_fMajorOff = bounds[1].y;
if(m_iMajor==2) m_fMajorOff = bounds[0].z;
}
};
#if defined(CH_USE_3DR)
#endif // 3DR
// end of file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -