//The function recursively builds up the transformation of the pThing 
//until it's in room-space coordinates
HRESULT C2DThingCoordTransformer::BuildTransformation(IThing * pThing, IThing * pParentThing)
{
	IVector * pVector = NULL;
	HRESULT hr = S_OK;
	IThing* pTmpParentThing = NULL;
	D3DRMMATRIX4D tmpMatrix;
	float flScaleX, flScaleY, flScaleZ;
	float flThingX, flThingY, flThingZ, // Position of current Thing having cells edited
	      flThingDirX, flThingDirY, flThingDirZ; // Orientation of current Thing having cells edited

	if (!pThing || !pParentThing)
		goto EXIT_FAIL;

	// Store the position Vector of the Thing
	hr = pThing->get_ObjectProperty(bstrPosition, (IObjectProperty **) &pVector);
	if( FAILED(hr) || !pVector) goto EXIT_FAIL;
	hr = pVector->get(&flThingX, &flThingY, &flThingZ);
	if( FAILED(hr) ) goto EXIT_FAIL;
	SAFERELEASE(pVector);

	// Get the Scale Vector of the Thing
	hr = pThing->get_ObjectProperty(bstrScale, (IObjectProperty **) &pVector);
	if( FAILED(hr) || !pVector) goto EXIT_FAIL;
	hr = pVector->get(&flScaleX, &flScaleY, &flScaleZ);
	if( FAILED(hr) ) goto EXIT_FAIL;
	SAFERELEASE(pVector);

	// Store the Direction Vector of the Thing
	hr = pThing->get_ObjectProperty(bstrDirection, (IObjectProperty **) &pVector);
	if( FAILED(hr) ) goto EXIT_FAIL;
	hr = pVector->get(&flThingDirX, &flThingDirY, &flThingDirZ);
	if( FAILED(hr) ) goto EXIT_FAIL;
	SAFERELEASE(pVector);

	IdentityMatrix(&tmpMatrix);
	ScaleMatrix(&tmpMatrix, flScaleX, flScaleY, flScaleZ);
	RotateMatrix(&tmpMatrix, flThingDirX, flThingDirY, flThingDirZ);
	TranslateMatrix(&tmpMatrix, flThingX, flThingY, flThingZ);
	PostMultiplyMatrix(&m_d3dMatrix, &tmpMatrix);

	IdentityMatrix(&tmpMatrix);
	TranslateMatrix(&tmpMatrix, -flThingX, -flThingY, -flThingZ);
	InverseRotateMatrix(&tmpMatrix, flThingDirX, flThingDirY, flThingDirZ);
	ScaleMatrix(&tmpMatrix, 1.0f / flScaleX, 1.0f / flScaleY, 1.0f / flScaleZ);
	PostMultiplyMatrix(&m_d3dInverseMatrix, &tmpMatrix);

	hr = pParentThing->get_Container(&pTmpParentThing);
	if ( SUCCEEDED(hr) && pTmpParentThing)
	{
		BuildTransformation(pParentThing, pTmpParentThing);
	}


EXIT_FAIL:
	SAFERELEASE(pTmpParentThing);
	SAFERELEASE(pVector);
	return hr;
}
Пример #2
0
void Initialize (int argc, char *argv[])
{
  GLenum GlewInitResult;
  TempString = (char *) malloc (512 + strlen(WINDOW_TITLE_PREFIX));
  InitWindow (argc, argv);
  glewExperimental = GL_TRUE;
  GlewInitResult = glewInit();
  if (GLEW_OK != GlewInitResult) {
    fprintf (stderr,
	     "ERROR: %s\n",
	     glewGetErrorString (GlewInitResult) );
    exit (EXIT_FAILURE);
  }
  fprintf (stdout, "INFO: OpengGL Vertion: %s\n", glGetString (GL_VERSION));
  glGetError ();

  glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
  
  glEnable (GL_DEPTH_TEST);
  glDepthFunc (GL_LESS);
  ExitOnGLError ("ERROR: Could not set OpenGL depth testing options");
  
  glEnable (GL_CULL_FACE);
  glCullFace (GL_BACK);
  glFrontFace (GL_CCW);
  ExitOnGLError ("ERROR: Could not set OpenGL culling options");
  
  ModelMatrix = IDENTITY_MATRIX;
  ProjectionMatrix = IDENTITY_MATRIX;
  ViewMatrix = IDENTITY_MATRIX;
  TranslateMatrix (&ViewMatrix, 0, 0, -2);

  CreateCube ();
}
Пример #3
0
bool CSTransform::Translate(std::string translate, bool concatenate)
{
	double matrix[16];

	std::vector<std::string> tl_vec = SplitString2Vector(translate, ',');
	ParameterScalar ps_translate[3];
	double tl_double_vec[3];
	if (tl_vec.size()>3)
		std::cerr << "CSTransform::Translate: Warning: Number of arguments for operation: \"Translate\" with arguments: \"" << translate << "\" is larger than expected, skipping unneeded! " << std::endl;
	else if (tl_vec.size()<3)
	{
		std::cerr << "CSTransform::Translate: Error: Number of arguments for operation: \"Translate\" with arguments: \"" << translate << "\" is invalid! Skipping" << std::endl;
		return false;
	}

	for (int n=0;n<3;++n)
	{
		ps_translate[n].SetParameterSet(m_ParaSet);
		ps_translate[n].SetValue(tl_vec.at(n));
		int EC = ps_translate[n].Evaluate();
		if (EC!=0)
			return false;
		tl_double_vec[n]=ps_translate[n].GetValue();
	}

	if (TranslateMatrix(matrix, tl_double_vec)==false)
		return false;

	ApplyMatrix(matrix,concatenate);
	AppendList(TRANSLATE,ps_translate,3);
	return true;
}
Пример #4
0
Файл: track.c Проект: one-k/rmov
/*
  call-seq: translate(x, y)
  
  Offset a track's position by x and y values respectively.
  
  Values should be in pixels.
*/
static VALUE track_translate(VALUE obj, VALUE x, VALUE y)
{
  MatrixRecord matrix;
  GetTrackMatrix(TRACK(obj), &matrix);
  TranslateMatrix(&matrix, FloatToFixed(NUM2DBL(x)), FloatToFixed(NUM2DBL(y)));
  SetTrackMatrix(TRACK(obj), &matrix);
  return obj;
}
Пример #5
0
void CSTransform::Translate(const double translate[3], bool concatenate)
{
	double matrix[16];

	if (TranslateMatrix(matrix, translate)==false)
		return;

	ApplyMatrix(matrix,concatenate);
	AppendList(TRANSLATE,translate,3);
}
Пример #6
0
void DisplayJPEGAndDisposeHandle( Handle imageData )
{
	OSErr err;
	Rect naturalBounds;
	MatrixRecord matrix;
	SInt32 gapH, gapV;
	Fixed scaleH, scaleV;
	Rect boundsRect;
	GraphicsImportComponent grip;
	Rect windowPortRect;
	static char gifSentinel[] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
	static char jpegSentinel[] = {0xFF,0xD9,0xFF,0xD9,0xFF,0xD9,0xFF,0xD9,0xFF,0xD9,0xFF,0xD9,0xFF,0xD9,0xFF,0xD9};
	Ptr sentinel;
	Size sentinelSize;
	
	if( !imageData )
	{
		ofLogNotice() << "NO IMAGE DATA" << endl;
	}	else {
		
		ofImage image;
		//ofPixels pixels();
		//pixels = imageData;
		//image.setFromPixels((const unsigned char *)imageData);
		//string image
		//image.saveImage(ofToDataPath(ofGetTimestampString()+".jpg", OF_IMAGE_QUALITY_BEST));
		
		ofLogError() << "WE HAVE DATA!" << endl;
	}

	return;
	
again:
	
	ofLogError() << "Again called";
	if( 'G' == **imageData ) {
		grip = gripG;
		// for GIF:
		// FF FF FF FF will ensure that the bit parser aborts, since you can't
		// have two consecutive all-ones symbols in the LZW codestream --
		// you can sometimes have one (say, a 9-bit code), but after consuming
		// it the code width increases (so we're now using 10-bit codes) 
		// and the all-ones code won't be valid for a while yet.
		sentinel = gifSentinel;
		sentinelSize = sizeof(gifSentinel);
	}
	else {
		grip = gripJ;
		// for JPEG:
		// FF D9 FF D9 will ensure (a) that the bit-parser aborts, since FF D9
		// is an "unstuffed" FF and hence illegal in the entropy-coded datastream,
		// and (b) be long enough to stop overreads.
		sentinel = jpegSentinel;
		sentinelSize = sizeof(jpegSentinel);
	}
	
	//•• add sentinel pattern to the end of the handle.
	err = PtrAndHand( sentinel, imageData, sentinelSize );
	
	err = GraphicsImportSetDataHandle( grip, imageData );
	if( err )
	{
		
		ofLogNotice() << "GraphicsImportSetDataHandle Error" << endl;
		goto bail;
	}
	err = GraphicsImportGetNaturalBounds( grip, &naturalBounds );
	if( err )
	{
		
		ofLogNotice() << "GraphicsImportGetNaturalBounds Error" << endl;
		goto bail;
	}
	
	//GetPortBounds( GetWindowPort( window ), &windowPortRect );
	gapH = windowPortRect.right - naturalBounds.right;
	gapV = windowPortRect.bottom - naturalBounds.bottom;
	
	if( gapH >= 0 ) {
		gapH = ((UInt16)Random()) % gapH;
		scaleH = fixed1;
	}
	else {
		gapH = 0;
		scaleH = FixDiv( windowPortRect.right, naturalBounds.right );
	}
	
	if( gapV >= 0 ) {
		gapV = ((UInt16)Random()) % gapV;
		scaleV = fixed1;
	}
	else {
		gapV = 0;
		scaleV = FixDiv( windowPortRect.bottom, naturalBounds.bottom );
	}
	
	// need to use smaller scale of the two, and then recalc the other gap.
	if( scaleH > scaleV ) {
		scaleH = scaleV;
		gapH = windowPortRect.right - FixMul(scaleH, naturalBounds.right);
		gapH = ((UInt16)Random()) % gapH;
	} else if( scaleH < scaleV ) {
		scaleV = scaleH;
		gapV = windowPortRect.bottom - FixMul(scaleV, naturalBounds.bottom);
		gapV = ((UInt16)Random()) % gapV;
	}
	
	SetIdentityMatrix( &matrix );
	ScaleMatrix( &matrix, scaleH, scaleV, 0, 0 );
	TranslateMatrix( &matrix, gapH<<16, gapV<<16 );
	
	err = GraphicsImportSetMatrix( grip, &matrix );
	if( err ) goto bail;
	
	err = GraphicsImportDraw( grip );
	if( err ) goto bail;
	
	err = GraphicsImportGetBoundsRect( grip, &boundsRect );
	if( err ) goto bail;
	InsetRect( &boundsRect, -1, -1 );
	//SetPortWindowPort( window );
	FrameRect( &boundsRect );
	
	if( scanForAnotherImageMarker(imageData))
	{
		 ofLogError() << "again: scanForAnotherImageMarker" << endl;
		goto again;
	}
	
bail:
	DisposeHandle( imageData );

	//gDrewJPEG = true;
}
Пример #7
0
GLuint platformLoadTextureFile(string theFilename, bool generateMipmaps, int *width, int *height)
{
#ifdef QuickTimeInstalled
	GLuint					textureName;				// the "name" by which OpenGL knows the texture
	unsigned char 			*pImageBuffer;				// the buffer that contains the image data 
	GWorldPtr				pGWorld;					// a gworld to load the image into
	
	int						imageDepth;
	
	FSSpec 					fsspecImage;				// FSSpec of the image to load
#ifdef __APPLE__	
	CFURLRef				imageURL;
	FSRef					imagefsRef;
#endif
	
	OSStatus				err = noErr;				// err return value
	long					rowStride;					// length, in bytes, of a pixel row in the image
	GraphicsImportComponent giComp;						// component for importing image
	MatrixRecord			matrix;
	Rect 					rectImage;					// rectangle of source image
	PixMapHandle			hPixMap;					// handle to image pix map
	ImageDescriptionHandle	hImageDesc;					// handle to image description used to get image depth

	long					imageWidth;
	long					imageHeight;
	float					imageAspect;
	long					textureWidth;
	long					textureHeight;



	// get the full path to the texture file
	string fileLocation;
	fileLocation = pathToResourceDirectory() + theFilename;



#ifdef __APPLE__	
	// create a URL to the file from the C string
	imageURL = CFURLCreateWithBytes (kCFAllocatorDefault, (UInt8 *)fileLocation.c_str(), fileLocation.length(), kCFStringEncodingASCII, NULL);
	if (imageURL == NULL)
	{
		cout << "error getting URL for image file (image file may not exist): " << theFilename << endl;
		return 0;
	}


	// get a FSRef from the URL
	if (!CFURLGetFSRef(imageURL, &imagefsRef))
	{
		cout << "error getting FSRef for image file:: " << theFilename << endl;
		CFRelease(imageURL);
		return 0;
	}
	

	// get the FSSpec from the FSRef
	if (FSGetCatalogInfo (&imagefsRef, kFSCatInfoNone, NULL, NULL, &fsspecImage, NULL))
	{
		cout << "error getting FSSpec for image file: " << theFilename << endl;
		CFRelease(imageURL);
		return 0;
	}
	
	
	// release the URL (not needed any more)
	CFRelease(imageURL);
#endif

#ifdef _WIN32
	// get an FSSpec from the pathname
	if (NativePathNameToFSSpec ((char *)fileLocation.c_str(), &fsspecImage, kErrorIfFileNotFound))
	{
		cout << "error getting FSSpec for image file: " << fileLocation << endl;
		return 0;
	}
#endif


	// save the onscreen graphics port
	GDHandle	origDevice;
	CGrafPtr	origPort;
	GetGWorld (&origPort, &origDevice);


	// get an importer for the file
	err = GetGraphicsImporterForFileWithFlags (&fsspecImage, &giComp, kDontUseValidateToFindGraphicsImporter);
	if (err != noErr) return 0;

	
	// get the image bounds
	err = GraphicsImportGetNaturalBounds (giComp, &rectImage); 
	if (err != noErr) return 0;


	// create a handle for the image description and lock it
	hImageDesc = (ImageDescriptionHandle) NewHandle (sizeof (ImageDescriptionHandle)); 
	HLock ((Handle) hImageDesc);


	// retrieve the image description
	err = GraphicsImportGetImageDescription (giComp, &hImageDesc); 
	if (err != noErr) return 0;
	
	
	// find width and height
	imageWidth = (int) (rectImage.right - rectImage.left);
	imageHeight = (int) (rectImage.bottom - rectImage.top);

	
	// now calculate the aspect ratio (width/height), used to restore image correctly
	imageAspect = ((float) imageWidth) / ((float) imageHeight);

	
	// get the image's pixel depth
	imageDepth = (**hImageDesc).depth;

	
	// find nearest acceptable texture size (width and height) for the image
	textureWidth = GetTextureDimFromImageDim (imageWidth);
	textureHeight = GetTextureDimFromImageDim (imageHeight);
	
	
	// pass the optimised (and scaled) size back out to the caller
	*width = textureWidth;
	*height = textureHeight;


	// set texture rectangle for creation of GWorld
#ifdef __APPLE__
	SetRect (&rectImage, 0, 0, (int) textureWidth, (int) textureHeight);
#endif
#ifdef _WIN32
	MacSetRect (&rectImage, 0, 0, (int) textureWidth, (int) textureHeight);
#endif

	// set stride in bytes width of image * 4 bytes per pixel
	rowStride = textureWidth * 4;
	
	// build new buffer exact size of image (stride * height)
	pImageBuffer = (unsigned char *) NewPtr (rowStride * textureHeight); 


	// check we got the buffer we wanted
	if (pImageBuffer == NULL)
	{
		// failed - release the component and return an error
		CloseComponent(giComp);
		return 0;
	}

	
	// create a new gworld using our unpadded buffer, setting the pixel type correctly for the expected image depth
#ifdef __BIG_ENDIAN__
	QTNewGWorldFromPtr (&(pGWorld), k32ARGBPixelFormat, &rectImage, NULL, NULL, 0, pImageBuffer, rowStride);
#else
	QTNewGWorldFromPtr (&(pGWorld), k32RGBAPixelFormat, &rectImage, NULL, NULL, 0, pImageBuffer, rowStride);
#endif
	
	
	// could we allocate the GWorld?
	if (pGWorld == NULL)
	{
		// failed - release the buffer, component and return an error
		DisposePtr ((Ptr) pImageBuffer);
		CloseComponent(giComp);
		return 0;
	}


	// build a transformation matrix to scale the image to the texture size
	// this also flips the image horizontally, so that texture coordinates map correctly
	float	horizontalScale = (float) textureWidth / (float) imageWidth;
	float	verticalScale = (float) textureHeight / (float) imageHeight;

	SetIdentityMatrix (&matrix);
	ScaleMatrix (&matrix, X2Fix(horizontalScale), X2Fix(-verticalScale), 0, 0);
	TranslateMatrix (&matrix, 0, X2Fix((float)textureHeight));


	// set the matrix as the importer matrix
	err = GraphicsImportSetMatrix(giComp, &matrix); 

	// set the destination of the importer component
	if (err == noErr) err = GraphicsImportSetGWorld (giComp, pGWorld, NULL);
	
	// ensure lossless decompression (if the CODEC supports this)
	if (err == noErr) err = GraphicsImportSetQuality(giComp, codecLosslessQuality); 

	if (err != noErr)
	{
		// failed - release the GWorld, buffer, component and return an error
		DisposeGWorld (pGWorld);
		DisposePtr ((Ptr) pImageBuffer);
		CloseComponent(giComp);
		return 0;
	}

	// get the address of the GWorld's pixmap
	hPixMap = GetGWorldPixMap (pGWorld);
	
	// if everything looks good draw the image to the locked pixmap
	if ((hPixMap) && (LockPixels (hPixMap)))
		GraphicsImportDraw (giComp);
	else
	{
		// the pixmap doesn't exist, or we couldn't lock it
		// release the GWorld, buffer, component and return an error
		DisposeGWorld (pGWorld);
		DisposePtr ((Ptr) pImageBuffer);
		CloseComponent(giComp);
		return 0;
	}


	// for images without an alpha channel, initialise the alpha bytes since QuickTime won't
	if (imageDepth < 32)
	{
#ifdef __BIG_ENDIAN__
		for( unsigned char *p = pImageBuffer; p < pImageBuffer + (rowStride * textureHeight); p+=4)
			*p = 0xFF;
#else
		for( unsigned char *p = pImageBuffer+3; p < pImageBuffer + (rowStride * textureHeight) +3; p+=4)
			*p = 0xFF;
#endif
	}

	// unlock the pixmap
	UnlockPixels (hPixMap);
	
	
	// dump the component
	CloseComponent(giComp);

	
	// set image width in groups (pixels), accounts for border this ensures proper image alignment row to row
	glPixelStorei (GL_UNPACK_ROW_LENGTH, textureWidth);


	// generate a "name" for the texture
	glGenTextures (1, &textureName);
	
	
	// create the texture in OpenGL
	glBindTexture(GL_TEXTURE_2D, textureName);



	// tell OpenGL about the texture and have GLU build mipmaps
#ifdef __BIG_ENDIAN__
	glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pImageBuffer);
#else
	glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, pImageBuffer);
#endif
	if (generateMipmaps)
#ifdef __BIG_ENDIAN__
	if (gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, textureWidth, textureHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, pImageBuffer) != 0)
#else
	if (gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, textureWidth, textureHeight, GL_RGBA, GL_UNSIGNED_BYTE, pImageBuffer) != 0)
#endif
	
	
	// good time to check for errors?
	openGLCheckError();
	

	// finished with the GWorld but not the image buffer (it's used by OpenGL as the "live" image buffer)
	DisposeGWorld (pGWorld);

	// restore the current graphics port we saved earlier
	SetGWorld(origPort, origDevice);


	// all done - return the texture name
	return textureName; 
#endif // QuickTimeInstalled
}
Пример #8
0
void CoGXEventTrigger::BuildMesh()
{
	MATRIX4		matScale;
	MATRIX4		matPos;
	MATRIX4		matRot,matRotX,matRotY,matRotZ;
	MATRIX4		matWorld;

	VECTOR3		v3PointList[2];
	v3PointList[0] = m_v3DefaultLength;
	VECTOR3_MUL_FLOAT(v3PointList+1,&m_v3DefaultLength,-1.0f);

	CalcBoundingMesh(v3PointList,2,&m_colMeshDesc);
	
	SetScaleMatrix(&matScale,&m_EventTriggerDesc.v3Scale);

	SetRotationXMatrix(&matRotX,m_EventTriggerDesc.v3Rot.x);
	SetRotationYMatrix(&matRotY,m_EventTriggerDesc.v3Rot.y);
	SetRotationZMatrix(&matRotZ,m_EventTriggerDesc.v3Rot.z);
		
	MatrixMultiply2(&matRot,&matRotX,&matRotY);
	MatrixMultiply2(&matRot,&matRot,&matRotZ);

	TranslateMatrix(&matPos,&m_EventTriggerDesc.v3Pos);
	
	MatrixMultiply2(&matWorld,&matRot,&matPos);
	MatrixMultiply2(&matWorld,&matScale,&matWorld);

	TransformVector3_VPTR1(m_colMeshDesc.boundingBox.v3Oct,&matWorld,8);
	TransformVector3_VPTR1(&m_colMeshDesc.boundingSphere.v3Point,&matWorld,1);

	CGXMap*	pMap = m_pExecutive->GetGXMap();
	if (pMap)
	{
		if (m_dwClipperIndex != 0xffffffff)
			pMap->UpdateDynamicObject(m_dwClipperIndex);
	}
	
	// 트리거와 개체의 충돌을 위해 면을 계산해놓는다.

	// 인덱스 순서.
	// 326	x
	// 451	-x
	// 034	y
	// 561	-y
	// 012	z
	// 654	-z
	DWORD	PlaneIndex[18]=	{ 3, 2, 6, 4, 5, 1, 0, 3, 4, 5, 6, 1, 0, 1, 2, 6, 5, 4	};

	DWORD	i;
	for( i = 0; i < 6; i++)
	{
		VECTOR3	v3Tri[3];
		v3Tri[0] = m_colMeshDesc.boundingBox.v3Oct[PlaneIndex[i*3+0]];
		v3Tri[1] = m_colMeshDesc.boundingBox.v3Oct[PlaneIndex[i*3+1]];
		v3Tri[2] = m_colMeshDesc.boundingBox.v3Oct[PlaneIndex[i*3+2]];

		CalcPlaneEquation(&m_pPlane[i],v3Tri);
//		MakePLANE( &m_pPlane[i], &m_colMeshDesc.boundingBox.v3Oct[PlaneIndex[i*3+0]], &m_colMeshDesc.boundingBox.v3Oct[PlaneIndex[i*3+1]], &m_colMeshDesc.boundingBox.v3Oct[PlaneIndex[i*3+2]]);
	}

}