Example #1
0
/*!
	@function	BoxV2ToObject
	
	@abstract	Attempt to convert a VRML 2 Box node to a Quesa object.
	
	@param		ioNode		Node to convert.
	
	@result		An object reference, or NULL on failure.
*/
CQ3ObjectRef	BoxV2ToObject( PolyValue& ioNode )
{
	TQ3Vector3D		sizes = {
		2.0f, 2.0f, 2.0f
	};
	
	PolyValue::Dictionary&	theDict( ioNode.GetDictionary() );

	if (IsKeyPresent( theDict, "size" ))
	{
		PolyValue&	sizeField( theDict["size"] );
		
		if ( (sizeField.GetType() == PolyValue::kDataTypeArrayOfFloat) or
			(sizeField.GetType() == PolyValue::kDataTypeArrayOfInt) )
		{
			PolyValue::FloatVec&	theFloats( sizeField.GetFloatVec() );
			if (theFloats.size() == 3)
			{
				sizes.x = theFloats[0];
				sizes.y = theFloats[1];
				sizes.z = theFloats[2];
			}
		}
	}
	
	TQ3BoxData boxData = {
		{ -sizes.x/2, -sizes.y/2, -sizes.z/2 },
		{ 0.0f, sizes.y, 0.0f },
		{ 0.0f, 0.0f, sizes.z },
		{ sizes.x, 0.0f, 0.0f },
		NULL, NULL
	};
	
	CQ3ObjectRef	theObject( Q3Box_New( &boxData ) );
	
	return theObject;
}
Example #2
0
TQ3GroupObject MyNewModel()
{
	TQ3GroupObject			myGroup = NULL;
	TQ3GeometryObject		myBox;
	TQ3BoxData				myBoxData;
	TQ3ShaderObject			myIlluminationShader ;
	
	TQ3SetObject			faces[6] ;
	short					face ;
			
	// Create a group for the complete model.
	// do not use Q3OrderedDisplayGroup_New since in this
	// type of group all of the translations are applied before
	// the objects in the group are drawn, in this instance we 
	// dont want this.
	if ((myGroup = Q3DisplayGroup_New()) != NULL ) 
	{
			
		// Define a shading type for the group
		// and add the shader to the group
		myIlluminationShader = Q3PhongIllumination_New();
		Q3Group_AddObject(myGroup, myIlluminationShader);

		// set up the colored faces for the box data
		myBoxData.faceAttributeSet = faces;
		myBoxData.boxAttributeSet = NULL;
		MyColorBoxFaces( &myBoxData ) ;
		
		#define	kBoxSide		0.8F
		#define	kBoxSidePlusGap	0.1F

		// create the box itself
		Q3Point3D_Set(&myBoxData.origin, 0.0F, 0.0F, 0.0F);
		Q3Vector3D_Set(&myBoxData.orientation, 0.0F, kBoxSide, 0.0F);
		Q3Vector3D_Set(&myBoxData.majorAxis, 0.0F, 0.0F, kBoxSide);	
		Q3Vector3D_Set(&myBoxData.minorAxis, kBoxSide, 0.0F, 0.0F);	
		myBox = Q3Box_New(&myBoxData);
#if 0	// one box
		Q3Group_AddObject(myGroup, myBox);
#else	// 4 boxes
		{
			TQ3Vector3D				translation;
			translation.x =  0.0F;				
			translation.y = kBoxSidePlusGap; 
			translation.z =  0.0F;
			MyAddTransformedObjectToGroup( myGroup, myBox, &translation ) ;
			translation.x =  2 * kBoxSide;	
			translation.y = kBoxSidePlusGap; 
			translation.z =  0.0F;
			MyAddTransformedObjectToGroup( myGroup, myBox, &translation ) ;
			translation.x =  0.0F;				
			translation.y = kBoxSidePlusGap; 
			translation.z = -2 * kBoxSide;
			MyAddTransformedObjectToGroup( myGroup, myBox, &translation ) ;
			translation.x = -2 * kBoxSide;	
			translation.y = kBoxSidePlusGap; 
			translation.z =  0.0F;
			MyAddTransformedObjectToGroup( myGroup, myBox, &translation ) ;
		}
#endif
		for( face = 0; face < 6; face++) {
			if( myBoxData.faceAttributeSet[face] != NULL )
				Q3Object_Dispose(myBoxData.faceAttributeSet[face]);
		}
		
		if( myBox ) 
			Q3Object_Dispose( myBox );
	}
	
	// dispose of the objects we created here
	if( myIlluminationShader ) 
		Q3Object_Dispose(myIlluminationShader);	
			
	
	//	Done!
	return ( myGroup );
}