Пример #1
0
static void MyColorBoxFaces( TQ3BoxData *myBoxData )
{
	TQ3ColorRGB				faceColor ;
	short 					face ;
	
	// sanity check - you need to have set up 
	// the face attribute set for the box data 
	// before calling this.
	
	if( myBoxData->faceAttributeSet == NULL )
		return ;
		
	// make each face of a box a different color
	
	for( face = 0; face < 6; face++) {
		
		myBoxData->faceAttributeSet[face] = Q3AttributeSet_New();
		switch( face ) {
			case 0:
				faceColor.r = 1.0F;
				faceColor.g = 0.0F;
				faceColor.b = 0.0F;
				break;
			
			case 1:
				faceColor.r = 0.0F;
				faceColor.g = 1.0F;
				faceColor.b = 0.0F;
				break;
			
			case 2:
				faceColor.r = 0.0F;
				faceColor.g = 0.0F;
				faceColor.b = 1.0F;
				break;
			
			case 3:
				faceColor.r = 1.0F;
				faceColor.g = 1.0F;
				faceColor.b = 0.0F;
				break;
			
			case 4:
				faceColor.r = 1.0F;
				faceColor.g = 0.0F;
				faceColor.b = 1.0F;
				break;
			
			case 5:
				faceColor.r = 0.0F;
				faceColor.g = 1.0F;
				faceColor.b = 1.0F;
				break;
		}
		Q3AttributeSet_Add(myBoxData->faceAttributeSet[face], kQ3AttributeTypeDiffuseColor, &faceColor);
	}
}
Пример #2
0
static CQ3ObjectRef	MakeDefaultAttSet()
{
	CQ3ObjectRef	theAtts( Q3AttributeSet_New() );
	if (theAtts.isvalid())
	{
		TQ3ColorRGB		defaultColor = { 1.0f, 1.0f, 1.0f };
		Q3AttributeSet_Add( theAtts.get(), kQ3AttributeTypeDiffuseColor, &defaultColor );
	}
	return theAtts;
}
Пример #3
0
// build a polygon that is a CIELab refrence
TQ3GeometryObject LogoWin2::NewPolyGCIELabRef(void)
{
	TQ3GeometryObject	geometryObject = NULL;
	//TQ3TriGridData		ciepoly;
	TQ3PolygonData ciepoly;
	TQ3Vertex3D			*vertices;
	long i;
	double	Lxy[4];
	double	lab[4];
	McoStatus	state;
	TQ3ColorRGB 		color  = { 0.0, 0.0, 0.0 };
	double big_ab,big_rgb;
	TQ3Param2D			param2D;

ciepoly.numVertices = NumCIExyzRef;
ciepoly.vertices = (TQ3Vertex3D *) NewPtr (NumCIExyzRef * sizeof(TQ3Vertex3D));
	if (ciepoly.vertices == NULL)	return NULL;
	
vertices = 	ciepoly.vertices;
	
ciepoly.polygonAttributeSet = NULL;
for (i=0; i<NumCIExyzRef; i++)
	{
	Lxy[0] = 50;
	Lxy[1] = CIExyzRef2[i*4+1];
	Lxy[2] = CIExyzRef2[i*4+2];
	
	vertices[i].point.x = Lxy[1];
	vertices[i].point.y = Lxy[2];
	vertices[i].point.z = 0.5;
	
	sxyztolab(Lxy,lab);
	
	big_ab = bigger(fabs(lab[1]),fabs(lab[2]));
	if (big_ab>127)
		{
		lab[1] = lab[1]*127/big_ab;
		lab[2] = lab[2]*127/big_ab;
		}
		
	labtonxyzinplace(lab,1);
	state = xyztorgb->compute(lab, monitor_z, 1);
	if(state != MCO_SUCCESS)
		return NULL;	

	
	big_rgb = bigger(lab[1],bigger(lab[2],lab[3]));
	if (big_rgb>255)
		{
		lab[0] = lab[0]*255/big_rgb;
		lab[1] = lab[1]*255/big_rgb;
		lab[2] = lab[2]*255/big_rgb;
		}
	color.r = lab[0]/256;
	color.g = lab[1]/256;
	color.b = lab[2]/256;
	vertices[i].attributeSet = Q3AttributeSet_New();
	Q3AttributeSet_Add(vertices[i].attributeSet, kQ3AttributeTypeDiffuseColor, &color);
	
	param2D.u = Lxy[1]*1.37;
	param2D.v = Lxy[2]*1.1;
								
	Q3AttributeSet_Add(vertices[i].attributeSet, kQ3AttributeTypeShadingUV, &param2D);

	}
	
geometryObject = Q3Polygon_New(&ciepoly);

for (i = 0; i < NumCIExyzRef; i++)
	Q3Object_Dispose(vertices[i].attributeSet);	
	
DisposePtr ((char *) vertices);
return	geometryObject;
}
Пример #4
0
TQ3GeometryObject	LogoWin2::NewLogoObject(void)
{
	TQ3GeometryObject	geometryObject = NULL;
	TQ3TriGridData		data;
	TQ3Vertex3D			*vertices;
	TQ3Vertex3D			norms;
	unsigned long		i,j,k;
	float				uuValue, vvValue,
						uuMin, uuMax, uuStep,
						vvMin, vvMax, vvStep,
						radius;
	TQ3Boolean			hasUVAttributes;
	TQ3Param2D			param2D;
	TQ3ColorRGB 		color  = { 0.0, 0.0, 0.0 };
	double 				*gammutSurface;
	double				lab[4];
	McoStatus			status;
	double				x,y,z,X,Y,Z;

	
	// uuValue is an angle used to revolve the cross section about the y axis
	// vvValue is an angle used to generate each half circular cross section

	uuMin =    0.0;
	uuMax =  360.0;
	vvMin = - 90.0;
	vvMax =   90.0;
		
	uuStep =  12.0;
	vvStep =  12.0;
		
	radius = 1.0;

	// Setup TQ3TriGridData 
	data.numRows		= (unsigned long) ((vvMax - vvMin) / vvStep) + 1;
	data.numColumns		= (unsigned long) ((uuMax - uuMin) / uuStep) + 1;
	data.facetAttributeSet	= NULL;
	data.triGridAttributeSet= NULL;

	data.vertices = (TQ3Vertex3D *) NewPtr (data.numRows * data.numColumns * sizeof(TQ3Vertex3D));
	if (data.vertices == NULL)	return NULL;

	// Set trigrid vertices and shading UVs, if it hasUVAttributes 
	vertices = data.vertices;
	i = 0;
	for (vvValue = vvMin; vvValue <= vvMax; vvValue += vvStep)
	{
		for (uuValue = uuMax; uuValue >= uuMin; uuValue -= uuStep)
		{
		vertices[i].point.x = uMath_Cos_Deg(vvValue) * uMath_Cos_Deg(uuValue) * radius;
		vertices[i].point.y = 1.5*uMath_Sin_Deg(vvValue) * radius;
		vertices[i].point.z = uMath_Cos_Deg(vvValue) * uMath_Sin_Deg(uuValue) * radius;	
		
		param2D.u = 1.0 - ((uuValue - uuMin) / (uuMax - uuMin));
		param2D.v = (vvValue - vvMin) / (vvMax - vvMin);
								
		vertices[i].attributeSet = Q3AttributeSet_New();
		Q3AttributeSet_Add(vertices[i].attributeSet, kQ3AttributeTypeShadingUV, &param2D);

		norms.point.x = uMath_Cos_Deg(vvValue) * uMath_Cos_Deg(uuValue) * (radius+1);
		norms.point.y = 1.5*uMath_Sin_Deg(vvValue)*(radius+1);
		norms.point.z = uMath_Cos_Deg(vvValue) * uMath_Sin_Deg(uuValue) * (radius+1);
		
		Q3AttributeSet_Add(vertices[i].attributeSet, kQ3AttributeTypeNormal, &norms);

		i++;
		}
	}

	geometryObject = Q3TriGrid_New (&data);

	for (i = 0; i < data.numRows * data.numColumns; i++)
		Q3Object_Dispose(vertices[i].attributeSet);

	DisposePtr ((char *) vertices);
		
	return	geometryObject;
} 
Пример #5
0
static TQ3GroupObject QD3DSupport_GroundInit(TQ3ShaderObject	groundShaderObject)
{
	long				i;
	TQ3GeometryObject	polygonObj = NULL;
	TQ3GroupPosition	myGroupPosition;
	TQ3GroupObject		groundGroup;
	TQ3PolygonData		polygonData;
	TQ3Vertex3D			vertices[kNumGrndTextureVertices] = {0,-3,GROUND_SIZE,nil,
															GROUND_SIZE,-3,GROUND_SIZE,nil,
															GROUND_SIZE,-3,-GROUND_SIZE,nil,
															0,-3,-GROUND_SIZE,nil};
	TQ3AttributeSet		attribs[kNumGrndTextureVertices] = {NULL, NULL, NULL, NULL};
	float				ambient = 1.0F;
	TQ3Param2D			uv[kNumGrndTextureVertices] = {0,0,1,0,1,1,0,1};



		if (groundShaderObject == NULL)

		{

			return NULL;

		}


		groundGroup =  Q3OrderedDisplayGroup_New();
		if (groundGroup == NULL)
		{
			return NULL;
		}
			
				/* ADD TEXTURE SHADER OBJECT TO GROUP */
		myGroupPosition = Q3Group_AddObject(groundGroup, groundShaderObject);
		if ( myGroupPosition == nil )
		{
			Utils_DisplayErrorMsg("Q3Group_AddObject failed!");
			goto outOfMem;
		}
		Q3Object_Dispose(groundShaderObject);


				/* CREATE VERTICES */
			
		for (i=0; i < kNumGrndTextureVertices; i++)
		{
			attribs[i] = Q3AttributeSet_New();	
			if( attribs[i] == NULL )
			{
				Utils_DisplayErrorMsg("Attribute set creation failed!");	
				goto outOfMem;
			}
			Q3AttributeSet_Add(attribs[i], kQ3AttributeTypeShadingUV, &uv[i]);
			vertices[i].attributeSet = attribs[i];
		}

				/* CREATE NEW POLYGON OBJECT */

		polygonData.numVertices = kNumGrndTextureVertices;
		polygonData.vertices = vertices;
		polygonData.polygonAttributeSet = nil;
		polygonObj = Q3Polygon_New(&polygonData);			
		
		if( polygonObj == NULL )
		{
			Utils_DisplayErrorMsg("Polygon_New failed!");	
			goto outOfMem;
		}
		
		for (i=0; i < kNumGrndTextureVertices; i++)
		{			
			Q3Object_Dispose(attribs[i]);
			attribs[i] = NULL;
		}

		myGroupPosition = Q3Group_AddObject(groundGroup, polygonObj);
		Q3Object_Dispose(polygonObj);
		if ( myGroupPosition == nil )
		{
			Utils_DisplayErrorMsg("Q3Group_AddObject failed!");	
			goto outOfMem;
		}
		
			/* Success! */
			
		return groundGroup;
		
			/* Error handling */
	outOfMem:
		if (groundGroup)
		{
			Q3Object_Dispose(groundGroup);
		}

		for (i=0; i < kNumGrndTextureVertices; i++)
		{			
			if( attribs[i] )
			{
				Q3Object_Dispose(attribs[i]);
			}
		}
		
		return NULL;
}
Пример #6
0
/*!
	@function	IndexedLineSetV1ToObject
	
	@abstract	Attempt to convert a VRML 1 IndexedLineSet node to a Quesa object.
	
	@param		ioNode			Node to convert.
	@param		inReader		The reader object.
	
	@result		An object reference, or NULL on failure.
*/
CQ3ObjectRef	IndexedLineSetV1ToObject( PolyValue& ioNode, CVRMLReader& inReader )
{
	CQ3ObjectRef	theObject( Q3DisplayGroup_New() );
	ThrowIfNullQuesaOb_( theObject );
	PolyValue::Dictionary&	theDict( ioNode.GetDictionary() );
	int	polylineNum = 0;
	
	// I am not going to bother with normals, so it is better not to use lighting.
	CQ3ObjectRef	theShader( Q3NULLIllumination_New() );
	ThrowIfNullQuesaOb_( theShader );
	Q3Group_AddObject( theObject.get(), theShader.get() );
	
	// Gather data
	PolyValue::IntVec		pointIndices;
	PolyValue::IntVec		colorIndices;
	GetIntVecFromField( theDict, "coordIndex", pointIndices );
	GetIntVecFromField( theDict, "materialIndex", colorIndices );
	StandardizeIndexVector( pointIndices );
	StandardizeIndexVector( colorIndices );
	const SVRML1State&	theState( inReader.GetVRML1State() );
	const std::vector<TQ3Point3D>&	thePoints( theState.coordinate3 );
	const std::vector<TQ3ColorRGB>&	theColors( theState.diffuseColor );
	bool isColorPerVertex( (theState.materialBinding == eVRML1Value_PER_VERTEX) or
		(theState.materialBinding == eVRML1Value_PER_VERTEX_INDEXED) );
	// Note: the VRML 1 spec, unlike the VRML 2 spec, indicates that colors
	// can be per segment rather than per polyline.  Currently I will not
	// support that.
	bool isColorPerPolyline( (theState.materialBinding == eVRML1Value_PER_PART) or
		(theState.materialBinding == eVRML1Value_PER_PART_INDEXED) or
		(theState.materialBinding == eVRML1Value_PER_FACE) or
		(theState.materialBinding == eVRML1Value_PER_FACE_INDEXED) );
	

	// Start building polylines
	std::vector<TQ3Vertex3D>	vertices;
	std::vector<CQ3ObjectRef>	vertAttSets;
	
	for (unsigned int i = 0; i < pointIndices.size(); ++i)
	{
		if (pointIndices[i] < 0)
		{
			// FInish a PolyLine
			TQ3PolyLineData	polyData;
			polyData.numVertices = vertices.size();
			polyData.vertices = &vertices[0];
			polyData.segmentAttributeSet = NULL;
			CQ3ObjectRef	polyAtts;
			if (not theColors.empty())
			{
				polyAtts = GetIndexedMaterial( inReader, 0 );
				
				if (isColorPerPolyline)
				{
					TQ3ColorRGB	polyColor;
					if (colorIndices.empty())
					{
						polyColor = theColors[ polylineNum ];
					}
					else
					{
						polyColor = theColors[ colorIndices[polylineNum] ];
					}
					Q3AttributeSet_Add( polyAtts.get(), kQ3AttributeTypeDiffuseColor,
						&polyColor );
				}

				polyData.polyLineAttributeSet = polyAtts.get();
			}
			else
			{
				polyData.polyLineAttributeSet = NULL;
			}
			CQ3ObjectRef	polyLine( Q3PolyLine_New( &polyData ) );
			ThrowIfNullQuesaOb_( polyLine );
			Q3Group_AddObject( theObject.get(), polyLine.get() );
			vertices.clear();
			vertAttSets.clear();
			polylineNum += 1;
		}
		else
		{
			TQ3Vertex3D	aVertex;
			aVertex.point = thePoints[ pointIndices[i] ];
			if (isColorPerVertex and (not theColors.empty()))
			{
				TQ3ColorRGB	vertColor;
				if (colorIndices.empty())
				{
					vertColor = theColors[ pointIndices[i] ];
				}
				else
				{
					vertColor = theColors[ colorIndices[i] ];
				}
				CQ3ObjectRef	vertAtts( Q3AttributeSet_New() );
				ThrowIfNullQuesaOb_( vertAtts );
				Q3AttributeSet_Add( vertAtts.get(), kQ3AttributeTypeDiffuseColor,
					&vertColor );
				vertAttSets.push_back( vertAtts );
				aVertex.attributeSet = vertAtts.get();
			}
			else
			{
				aVertex.attributeSet = NULL;
			}
			vertices.push_back( aVertex );
		}
	}

	if (polylineNum == 0)
	{
		// no sense returning an empty display group
		theObject = CQ3ObjectRef();
	}
	
	return theObject;
}
Пример #7
0
/*!
	@function	IndexedLineSetV2ToObject
	
	@abstract	Attempt to convert a VRML 2 IndexedLineSet node to a Quesa object.
	
	@param		ioNode			Node to convert.
	@param		inReader		The reader object.
	
	@result		An object reference, or NULL on failure.
*/
CQ3ObjectRef	IndexedLineSetV2ToObject( PolyValue& ioNode )
{
	CQ3ObjectRef	theObject( Q3DisplayGroup_New() );
	ThrowIfNullQuesaOb_( theObject );
	
	// The VRML 2 spec says that lines are not lit.
	CQ3ObjectRef	theShader( Q3NULLIllumination_New() );
	ThrowIfNullQuesaOb_( theShader );
	Q3Group_AddObject( theObject.get(), theShader.get() );
	
	PolyValue::Dictionary&	theDict( ioNode.GetDictionary() );
	
	// Gather data from fields
	std::vector<TQ3Point3D>	thePoints;
	std::vector<TQ3ColorRGB>	theColors;
	PolyValue::IntVec		pointIndices;
	PolyValue::IntVec		colorIndices;
	
	GetNodeArray( theDict, "coord", "Coordinate", "point", thePoints );
	GetNodeArray( theDict, "color", "Color", "color", theColors );
	
	GetIntVecFromField( theDict, "coordIndex", pointIndices );
	GetIntVecFromField( theDict, "colorIndex", colorIndices );
	StandardizeIndexVector( pointIndices );
	StandardizeIndexVector( colorIndices );
	
	bool	isColorPerVertex = true;
	if (IsKeyPresent( theDict, "colorPerVertex" ))
	{
		PolyValue&	theNode( theDict[ "colorPerVertex" ] );
		if (theNode.GetType() == PolyValue::kDataTypeBool)
		{
			isColorPerVertex = theNode.GetBool();
		}
	}
	
	// Start building polylines
	std::vector<TQ3Vertex3D>	vertices;
	std::vector<CQ3ObjectRef>	vertAttSets;
	int	polylineNum = 0;
	
	for (unsigned int i = 0; i < pointIndices.size(); ++i)
	{
		if (pointIndices[i] < 0)
		{
			// FInish a PolyLine
			TQ3PolyLineData	polyData;
			polyData.numVertices = vertices.size();
			polyData.vertices = &vertices[0];
			polyData.segmentAttributeSet = NULL;
			CQ3ObjectRef	polyAtts;
			if ((not isColorPerVertex) and (not theColors.empty()))
			{
				TQ3ColorRGB	polyColor;
				if (colorIndices.empty())
				{
					polyColor = theColors[ polylineNum ];
				}
				else
				{
					polyColor = theColors[ colorIndices[polylineNum] ];
				}
				polyAtts = CQ3ObjectRef( Q3AttributeSet_New() );
				ThrowIfNullQuesaOb_( polyAtts );
				Q3AttributeSet_Add( polyAtts.get(), kQ3AttributeTypeDiffuseColor,
					&polyColor );
				polyData.polyLineAttributeSet = polyAtts.get();
			}
			else
			{
				polyData.polyLineAttributeSet = NULL;
			}
			CQ3ObjectRef	polyLine( Q3PolyLine_New( &polyData ) );
			ThrowIfNullQuesaOb_( polyLine );
			Q3Group_AddObject( theObject.get(), polyLine.get() );
			vertices.clear();
			vertAttSets.clear();
			polylineNum += 1;
		}
		else
		{
			TQ3Vertex3D	aVertex;
			aVertex.point = thePoints[ pointIndices[i] ];
			if (isColorPerVertex and (not theColors.empty()))
			{
				TQ3ColorRGB	vertColor;
				if (colorIndices.empty())
				{
					vertColor = theColors[ pointIndices[i] ];
				}
				else
				{
					vertColor = theColors[ colorIndices[i] ];
				}
				CQ3ObjectRef	vertAtts( Q3AttributeSet_New() );
				ThrowIfNullQuesaOb_( vertAtts );
				Q3AttributeSet_Add( vertAtts.get(), kQ3AttributeTypeDiffuseColor,
					&vertColor );
				vertAttSets.push_back( vertAtts );
				aVertex.attributeSet = vertAtts.get();
			}
			else
			{
				aVertex.attributeSet = NULL;
			}
			vertices.push_back( aVertex );
		}
	}
	
	if (polylineNum == 0)
	{
		// no sense returning an empty display group
		theObject = CQ3ObjectRef();
	}
	
	
	return theObject;
}