예제 #1
0
void Picking::project(const physx::PxVec3& v, int& xi, int& yi, float& depth) const
{
	SampleRenderer::Renderer* renderer = mFrame.getRenderer();
	SampleRenderer::RendererProjection	projection = mFrame.getCamera().getProjMatrix();
	const PxTransform view = mFrame.getCamera().getViewMatrix().getInverse();

	PxVec3 pos = SampleRenderer::project(projection, view, v);
	///* Map x, y and z to range 0-1 */
	pos.x = (pos.x + 1 ) * 0.5f;
	pos.y = (pos.y + 1 ) * 0.5f;
	pos.z = (pos.z + 1 ) * 0.5f;
	
	PxU32 windowWidth  = 0;
	PxU32 windowHeight = 0;
	renderer->getWindowSize(windowWidth, windowHeight);

	/* Map x,y to viewport */
	pos.x *= windowWidth;
	pos.y *= windowHeight; 
	
	depth = (float)pos.z;

	xi = (int)(pos.x + 0.5); 
	yi = (int)(pos.y + 0.5); 
}
예제 #2
0
PxVec3 Picking::unProject(int x, int y, float depth) const
{
	SampleRenderer::Renderer* renderer = mFrame.getRenderer();
	const SampleRenderer::RendererProjection& projection = mFrame.getCamera().getProjMatrix();
	const PxTransform view = mFrame.getCamera().getViewMatrix().getInverse();

	PxU32 windowWidth  = 0;
	PxU32 windowHeight = 0;
	renderer->getWindowSize(windowWidth, windowHeight);
	
	const PxF32 outX = (float)x / (float)windowWidth;
	const PxF32 outY = (float)y / (float)windowHeight;

	return SampleRenderer::unproject(projection, view, outX * 2 -1, outY * 2 -1, depth * 2 - 1);
}
예제 #3
0
void SampleSubmarine::customizeRender()
{
	SampleRenderer::Renderer* renderer = getRenderer();
	const PxU32 yInc = 18;
	const RendererColor textColor(255, 255, 255, 255);

	PxU32 width, height;
	renderer->getWindowSize(width, height);
	char healthBar[20];
	PxU32 h = gSubmarineHealth;
	sprintf(healthBar, "Health:%c%c%c%c%c%c%c%c%c%c", (h>90?'I':' '), (h>80?'I':' '), (h>70?'I':' '),(h>60?'I':' '),(h>50?'I':' '), 
	(h>40?'I':' '), (h>30?'I':' '), (h>20?'I':' '),(h>10?'I':' '),(h>0?'I':' '));
	renderer->print(width-130, height-yInc, healthBar);	
	if(gTreasureFound)
		renderer->print(width-160, height-2*yInc, "Treasure Found!");	
}
void SampleCharacterCloth::customizeRender()
{
#if PX_SUPPORT_GPU_PHYSX
	SampleRenderer::Renderer* renderer = getRenderer();

	const PxU32 yInc = 18;
	const PxReal scale = 0.5f;
	const PxReal shadowOffset = 6.0f;
	PxU32 width, height;
	renderer->getWindowSize(width, height);

	PxU32 y = height-2*yInc;
	PxU32 x = width - 240;

	{
		const RendererColor textColor(255, 0, 0, 255);
		renderer->print(x, y, mUseGPU ? "Running on GPU" : "Running on CPU", scale, shadowOffset, textColor);
	}
#endif

}
void RenderMaterial::update(SampleRenderer::Renderer& renderer)
{
	const RendererMaterial::Variable* var = mRenderMaterialInstance->findVariable("windowWidth", RendererMaterial::VARIABLE_FLOAT);
	if(var)
	{
		PxU32 tmpWindowWidth, tmpWindowHeight;
		renderer.getWindowSize(tmpWindowWidth, tmpWindowHeight);

		const PxReal windowWidth = PxReal(tmpWindowWidth);
		mRenderMaterialInstance->writeData(*var, &windowWidth);
	}

}
예제 #6
0
void SampleTextureAsset::loadBMP(SampleRenderer::Renderer &renderer, FILE &file)
{
	PxToolkit::BmpLoader loader;
	bool ok = loader.loadBmp(&file);
	PX_ASSERT(ok);
	if(ok)
	{
		SampleRenderer::RendererTexture2DDesc tdesc;	
#if !defined(RENDERER_PS3)
		tdesc.format	= SampleRenderer::RendererTexture2D::FORMAT_B8G8R8A8;
#else
		tdesc.format	= SampleRenderer::RendererTexture2D::FORMAT_R8G8B8A8;
#endif
		tdesc.width     = loader.mWidth;
		tdesc.height    = loader.mHeight;
		tdesc.numLevels = 1;
		PX_ASSERT(tdesc.isValid());
		m_texture = renderer.createTexture2D(tdesc);
		PX_ASSERT(m_texture);
		if(m_texture)
		{
			PxU32 pitch  = 0;
			void *buffer = m_texture->lockLevel(0, pitch);
			PX_ASSERT(buffer);
			if(buffer)
			{
				const PxU32						levelWidth  = m_texture->getWidthInBlocks();
				const PxU32						levelHeight = m_texture->getHeightInBlocks();
				SampleRenderer::RendererColor*	levelDst    = (SampleRenderer::RendererColor*)buffer + levelWidth * levelHeight;
				const PxU8*						levelSrc    = (PxU8*)loader.mRGB;
				for(PxU32 row=0; row<levelHeight; row++)
				{
					levelDst -= levelWidth;
					// copy per pixel to handle RBG case
					for(PxU32 col=0; col<levelWidth; col++)
					{
						levelDst[col].r = *levelSrc++;
						levelDst[col].g = *levelSrc++;
						levelDst[col].b = *levelSrc++;
						levelDst[col].a = loader.mHasAlpha ? *levelSrc++ : 0xff;
					}
				}
			}
			m_texture->unlockLevel(0);
		}
	}
}
예제 #7
0
void SampleParticles::customizeRender()
{
	SampleRenderer::Renderer* renderer = getRenderer();

	// render the sight
	SampleRenderer::RendererColor sightColor(200, 40, 40, 127);
	PxReal sight[] = {  0.47f, 0.50f, 0.49f, 0.50f,	// line 1
						0.51f, 0.50f, 0.53f, 0.50f,	// line 2
						0.50f, 0.47f, 0.50f, 0.49f,	// line 3
						0.50f, 0.51f, 0.50f, 0.53f	// line 4
					 };

	renderer->drawLines2D(2, sight, sightColor);
	renderer->drawLines2D(2, sight + 4, sightColor);
	renderer->drawLines2D(2, sight + 8, sightColor);
	renderer->drawLines2D(2, sight + 12, sightColor);

	//settings for right lower corner info text (same hight as fps display)
	const PxU32 yInc = 18;
	const PxReal scale = 0.5f;
	const PxReal shadowOffset = 6.0f;
	PxU32 width, height;
	renderer->getWindowSize(width, height);

	PxU32 y = height-2*yInc;
	PxU32 x = width - 240;

	if (mLoadTextAlpha > 0)
	{
		const RendererColor textColor(255, 0, 0, PxU8(mLoadTextAlpha*255.0f));
		const char* message[3] = { "Particle count: Moderate", "Particle count: Medium", "Particle count: High" };
		renderer->print(x, y, message[mParticleLoadIndex], scale, shadowOffset, textColor);
		y -= yInc;
	}

#if PX_SUPPORT_GPU_PHYSX
	{
		const RendererColor textColor(255, 0, 0, 255);
		renderer->print(x, y, mRunOnGpu ? "Running on GPU" : "Running on CPU", scale, shadowOffset, textColor);
	}
#endif
}
예제 #8
0
void SampleParticles::helpRender(PxU32 x, PxU32 y, PxU8 textAlpha)
{
	SampleRenderer::Renderer* renderer = getRenderer();
	const PxU32 yInc = 18;
	const PxReal scale = 0.5f;
	const PxReal shadowOffset = 6.0f;
	const RendererColor textColor(255, 255, 255, textAlpha);
	const bool isMouseSupported = getApplication().getPlatform()->getSampleUserInput()->mouseSupported();
	const bool isPadSupported = getApplication().getPlatform()->getSampleUserInput()->gamepadSupported();
	const char* msg;

	if (isMouseSupported && isPadSupported)
		renderer->print(x, y += yInc, "Use mouse or right stick to rotate", scale, shadowOffset, textColor);
	else if (isMouseSupported)
		renderer->print(x, y += yInc, "Use mouse to rotate", scale, shadowOffset, textColor);
	else if (isPadSupported)
		renderer->print(x, y += yInc, "Use right stick to rotate", scale, shadowOffset, textColor);
	if (isPadSupported)
		renderer->print(x, y += yInc, "Use left stick to move",scale, shadowOffset, textColor);
	msg = mApplication.inputMoveInfoMsg("Press "," to move", CAMERA_MOVE_FORWARD,CAMERA_MOVE_BACKWARD, CAMERA_MOVE_LEFT, CAMERA_MOVE_RIGHT);
	if(msg)
		renderer->print(x, y += yInc, msg,scale, shadowOffset, textColor);
	msg = mApplication.inputInfoMsg("Press "," to move fast", CAMERA_SHIFT_SPEED, -1);
	if(msg)
		renderer->print(x, y += yInc, msg, scale, shadowOffset, textColor);
	msg = mApplication.inputInfoMsg("Press "," to shoot raygun", RAYGUN_SHOT, -1);
	if(msg)	
		renderer->print(x, y += yInc, msg,scale, shadowOffset, textColor);
	msg = mApplication.inputInfoMsg("Press "," to toggle various debug visualization", TOGGLE_VISUALIZATION, -1);
	if(msg)
		renderer->print(x, y += yInc, msg,scale, shadowOffset, textColor);
	msg = mApplication.inputInfoMsg("Press "," to change particle count", CHANGE_PARTICLE_CONTENT,-1);
	if(msg)
		renderer->print(x, y += yInc, msg,scale, shadowOffset, textColor);

#if defined(PX_WINDOWS)
	msg = mApplication.inputInfoMsg("Press "," to toggle CPU/GPU", TOGGLE_CPU_GPU, -1);
	if(msg)
		renderer->print(x, y += yInc, msg,scale, shadowOffset, textColor);
#endif

}
예제 #9
0
void SampleSubmarine::helpRender(PxU32 x, PxU32 y, PxU8 textAlpha)
{
	SampleRenderer::Renderer* renderer = getRenderer();
	const PxU32 yInc = 18;
	const PxReal scale = 0.5f;
	const PxReal shadowOffset = 6.0f;
	const RendererColor textColor(255, 255, 255, textAlpha);
	const bool isMouseSupported = getApplication().getPlatform()->getSampleUserInput()->mouseSupported();
	const bool isPadSupported = getApplication().getPlatform()->getSampleUserInput()->gamepadSupported();
	const char* msg;

	msg = mApplication.inputInfoMsg("Press "," to toggle various debug visualization", TOGGLE_VISUALIZATION, -1);
	if(msg)
		renderer->print(x, y += yInc, msg,scale, shadowOffset, textColor);
	msg = mApplication.inputInfoMsg("Press "," to restart", SCENE_RESET,-1);
	if(msg)
		renderer->print(x, y += yInc, msg,scale, shadowOffset, textColor);
	if (isMouseSupported && isPadSupported)
		renderer->print(x, y += yInc, "Use mouse or right stick to rotate the camera", scale, shadowOffset, textColor);
	else if (isMouseSupported)
		renderer->print(x, y += yInc, "Use mouse to rotate the camera", scale, shadowOffset, textColor);
	else if (isPadSupported)
		renderer->print(x, y += yInc, "Use right stick to rotate the camera", scale, shadowOffset, textColor);
	msg = mApplication.inputInfoMsg("Press "," to switch between submarine/crab/flyCam", CAMERA_SWITCH, -1);
	if(msg)
		renderer->print(x, y += yInc, msg,scale, shadowOffset, textColor);

	if(mCameraAttachedToActor == mSubmarineActor)
	{
		renderer->print(x, y += yInc, "Submarine Controller:", scale, shadowOffset, textColor);
		const char* msg = mApplication.inputInfoMsg("Press "," to move along view direction", SUBMARINE_FORWARD, SUBMARINE_BACKWARD);
		if(msg)
			renderer->print(x, y += yInc, msg,scale, shadowOffset, textColor);
		msg = mApplication.inputInfoMsg("Press "," to raise and dive", SUBMARINE_UP, SUBMARINE_DOWN);
		if(msg)
			renderer->print(x, y += yInc, msg,scale, shadowOffset, textColor);
	}
	else if(gCrab && (mCameraAttachedToActor == gCrab->getCrabBody()))
	{
		renderer->print(x, y += yInc, "Crab Controller:", scale, shadowOffset, textColor);
		if (isPadSupported)
			renderer->print(x, y += yInc, "Use left stick to move the crab", scale, shadowOffset, textColor);
		const char* msg = mApplication.inputMoveInfoMsg("Press "," to move the crab", CRAB_FORWARD, CRAB_BACKWARD, CRAB_LEFT, CRAB_RIGHT);
		if(msg)
			renderer->print(x, y += yInc, msg,scale, shadowOffset, textColor);
	}
	else
	{
		renderer->print(x, y += yInc, "Fly Cam Controller:", scale, shadowOffset, textColor);
		if (isPadSupported)
			renderer->print(x, y += yInc, "Use left stick to move",scale, shadowOffset, textColor);
		const char* msg = mApplication.inputMoveInfoMsg("Press ","  to move", CAMERA_MOVE_FORWARD,CAMERA_MOVE_BACKWARD, CAMERA_MOVE_LEFT, CAMERA_MOVE_RIGHT);
		if(msg)
			renderer->print(x, y += yInc, msg,scale, shadowOffset, textColor);
		msg = mApplication.inputInfoMsg("Press "," to move fast", CAMERA_SHIFT_SPEED, -1);
		if(msg)
			renderer->print(x, y += yInc, msg, scale, shadowOffset, textColor);
	}
}
예제 #10
0
void SampleTextureAsset::loadDDS(SampleRenderer::Renderer &renderer, FILE &file) 
{
#ifdef RENDERER_PSP2
	RENDERER_ASSERT(0, "DDS format currently unsupported on PSP2 convert dds to gxt please.");
#endif

	nv_dds::CDDSImage ddsimage;
	bool ok = ddsimage.load(&file, false);
	PX_ASSERT(ok);
	if(ok)
	{
		SampleRenderer::RendererTexture2DDesc tdesc;
		nv_dds::TextureFormat ddsformat = ddsimage.get_format();
		switch(ddsformat)
		{
		case nv_dds::TextureBGRA:      tdesc.format = SampleRenderer::RendererTexture2D::FORMAT_B8G8R8A8; break;
		case nv_dds::TextureDXT1:      tdesc.format = SampleRenderer::RendererTexture2D::FORMAT_DXT1;     break;
		case nv_dds::TextureDXT3:      tdesc.format = SampleRenderer::RendererTexture2D::FORMAT_DXT3;     break;
		case nv_dds::TextureDXT5:      tdesc.format = SampleRenderer::RendererTexture2D::FORMAT_DXT5;     break;
		default: break;
 		}
		tdesc.width     = ddsimage.get_width();
		tdesc.height    = ddsimage.get_height();
		// if there is 1 mipmap, nv_dds reports 0
		tdesc.numLevels = ddsimage.get_num_mipmaps()+1;
		PX_ASSERT(tdesc.isValid());
		m_texture = renderer.createTexture2D(tdesc);
		PX_ASSERT(m_texture);
		if(m_texture)
		{
			PxU32 pitch  = 0;
			void *buffer = m_texture->lockLevel(0, pitch);
			PX_ASSERT(buffer);
			if(buffer)
			{
				//PxU32 size = ddsimage.get_size();

				PxU8       *levelDst    = (PxU8*)buffer;
				const PxU8 *levelSrc    = (PxU8*)(unsigned char*)ddsimage;
				const PxU32 levelWidth  = m_texture->getWidthInBlocks();
				const PxU32 levelHeight = m_texture->getHeightInBlocks();
				const PxU32 rowSrcSize  = levelWidth * m_texture->getBlockSize();
				PX_ASSERT(rowSrcSize <= pitch); // the pitch can't be less than the source row size.
				for(PxU32 row=0; row<levelHeight; row++)
				{
					memcpy(levelDst, levelSrc, rowSrcSize);
					levelDst += pitch;
					levelSrc += rowSrcSize;
				}
			}
			m_texture->unlockLevel(0);

			for(PxU32 i=1; i<tdesc.numLevels; i++)
			{
				void *buffer = m_texture->lockLevel(i, pitch);
				PX_ASSERT(buffer);
				if(buffer && pitch )
				{
					const nv_dds::CSurface &surface = ddsimage.get_mipmap(i-1);
					//PxU32 size = surface.get_size();

					PxU8       *levelDst    = (PxU8*)buffer;
					const PxU8 *levelSrc    = (PxU8*)(unsigned char*)surface;
					const PxU32 levelWidth  = SampleRenderer::RendererTexture2D::getFormatNumBlocks(surface.get_width(),  m_texture->getFormat());
					const PxU32 levelHeight = SampleRenderer::RendererTexture2D::getFormatNumBlocks(surface.get_height(), m_texture->getFormat());
					const PxU32 rowSrcSize  = levelWidth * m_texture->getBlockSize();
					PX_ASSERT(rowSrcSize <= pitch); // the pitch can't be less than the source row size.
					for(PxU32 row=0; row<levelHeight; row++)
					{
						memcpy(levelDst, levelSrc, rowSrcSize);
						levelDst += pitch;
						levelSrc += rowSrcSize;
					}
				}
				m_texture->unlockLevel(i);
			}
		}
	}
}
예제 #11
0
void SampleTextureAsset::loadTGA(SampleRenderer::Renderer &renderer, FILE &file)
{
#ifdef RENDERER_ENABLE_TGA_SUPPORT

	tga_image* image = new tga_image();
	bool ok = (TGA_NOERR == tga_read_from_FILE( image, &file ));

	// flip it to make it look correct in the SampleFramework's renderer
	tga_flip_vert( image );

	PX_ASSERT(ok);
	if( ok )
	{
		SampleRenderer::RendererTexture2DDesc tdesc;
		int componentCount = image->pixel_depth/8;
		if( componentCount == 3 || componentCount == 4 )
		{
			tdesc.format = SampleRenderer::RendererTexture2D::FORMAT_B8G8R8A8;

			tdesc.width     = image->width;
			tdesc.height    = image->height;

			tdesc.numLevels = 1;
			PX_ASSERT(tdesc.isValid());
			m_texture = renderer.createTexture2D(tdesc);
			PX_ASSERT(m_texture);

			if(m_texture)
			{
				PxU32 pitch  = 0;
				void *buffer = m_texture->lockLevel(0, pitch);
				PX_ASSERT(buffer);
				if(buffer)
				{
					PxU8       *levelDst    = (PxU8*)buffer;
					const PxU8 *levelSrc    = (PxU8*)image->image_data;
					const PxU32 levelWidth  = m_texture->getWidthInBlocks();
					const PxU32 levelHeight = m_texture->getHeightInBlocks();
					const PxU32 rowSrcSize  = levelWidth * m_texture->getBlockSize();
					PX_ASSERT(rowSrcSize <= pitch); // the pitch can't be less than the source row size.
					for(PxU32 row=0; row<levelHeight; row++)
					{ 
						if( componentCount == 3 )
						{
							// copy per pixel to handle RBG case, based on component count
							for(PxU32 col=0; col<levelWidth; col++)
							{
								*levelDst++ = levelSrc[0];
								*levelDst++ = levelSrc[1];
								*levelDst++ = levelSrc[2];
								*levelDst++ = 0xFF; //alpha
								levelSrc += componentCount;
							}
						}
						else
						{
							memcpy(levelDst, levelSrc, rowSrcSize);
							levelDst += pitch;
							levelSrc += rowSrcSize;
						}
					}
				}
				m_texture->unlockLevel(0);
			}
		}
	}
	delete image;

#endif /* RENDERER_ENABLE_TGA_SUPPORT */
}
예제 #12
0
void SampleTextureAsset::loadPVR(SampleRenderer::Renderer& renderer, FILE& file)
{
#ifdef RENDERER_ENABLE_PVR_SUPPORT	
	fseek(&file, 0, SEEK_END);
	size_t size = ftell(&file);
	fseek(&file, 0, SEEK_SET);
	char* fileBuffer = new char[size+1];
	fread(fileBuffer, 1, size, &file);
	fclose(&file);
	fileBuffer[size] = '\0';
	
	const PVRTextureInfo info(fileBuffer);
	PX_ASSERT(info.data);
	
	SampleRenderer::RendererTexture2DDesc tdesc;
	if (info.glFormat == GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG)
	{
		tdesc.format = SampleRenderer::RendererTexture2D::FORMAT_PVR_4BPP;
	}
	else 
	{
		tdesc.format = SampleRenderer::RendererTexture2D::FORMAT_PVR_2BPP;
	}

	tdesc.width     = info.width;
	tdesc.height    = info.height;	
	tdesc.numLevels = info.mipCount + 1;
	tdesc.data = NULL;
	
	PX_ASSERT(tdesc.isValid());
	m_texture = renderer.createTexture2D(tdesc);
	PX_ASSERT(m_texture);
	if (!info.data)
	{
		delete[] fileBuffer;
		return;
	}
	
	PxU32 pitch  = 0;
	PxU8* levelDst = (PxU8*)m_texture->lockLevel(0, pitch);
	const PxU8* levelSrc = (PxU8*)info.data;

	PX_ASSERT(levelDst && levelSrc);
	{
		PxU32 levelWidth = tdesc.width;
		PxU32 levelHeight = tdesc.height;
		const PxU32 levelSize = m_texture->computeImageByteSize(levelWidth, levelHeight, tdesc.format);
		memcpy(levelDst, levelSrc, levelSize);
		levelSrc += levelSize;
	}
	m_texture->unlockLevel(0);
	
	for(PxU32 i=1; i<tdesc.numLevels; i++)
	{
		PxU8* levelDst = (PxU8*)m_texture->lockLevel(i, pitch);
		PX_ASSERT(levelDst);
		{
			const PxU32 levelWidth  = m_texture->getLevelDimension(tdesc.width, i);
			const PxU32 levelHeight = m_texture->getLevelDimension(tdesc.height, i);
			const PxU32 levelSize  = m_texture->computeImageByteSize(levelWidth, levelHeight, tdesc.format);
			memcpy(levelDst, levelSrc, levelSize);
			levelSrc += levelSize;
		}
		m_texture->unlockLevel(i);
	}
	
	delete[] fileBuffer;
	
#endif
}
예제 #13
0
void SampleTextureAsset::loadGXT(SampleRenderer::Renderer &renderer, FILE &file)
{
#ifdef RENDERER_ENABLE_GXT_SUPPORT
	char file2[512];

	strcpy(file2, getPath());

	char* endStr = strstr(file2,".dds");	
	strcpy(endStr, ".gxt");

	FILE *f = NULL;

	if(strstr(file2, "savedata0"))
	{
		f =  fopen(file2, "rb");
	}
	else
	{
		// add path its in samples folder
		char file3[512];
		sprintf(file3, "app0:%s%s", ASSET_DIR, file2);


		f = fopen(file3, "rb");
	}

	if(!f)
	{
		RENDERER_ASSERT(f, "Failed to load gxt.");	
	}

	fseek(f, 0, SEEK_END);
	size_t size = ftell(f);
	fseek(f, 0, SEEK_SET);
	char *buffer = new char[size+1];
	fread(buffer, 1, size, f);
	fclose(f);
	buffer[size] = '\0';

	SceGxtErrorCode err = sceGxtCheckData(buffer);

	RENDERER_ASSERT(err == SCE_OK, "GXT texture data not correct.");

	const SceGxtHeader *hdr = (const SceGxtHeader*) buffer;

	PxU32 textureIndex = 0;

	const SceGxtTextureInfo* info = (const SceGxtTextureInfo*)(hdr + 1) + textureIndex;

	SampleRenderer::RendererTexture2DDesc tdesc;
	tdesc.format = SampleRenderer::RendererTexture2D::FORMAT_GXT;
	tdesc.width     = info->width;
	tdesc.height    = info->height;	
	// temp just 1 
	tdesc.numLevels = 1 ;//info->mipCount;
	tdesc.data = buffer;

	PX_ASSERT(tdesc.isValid());
	m_texture = renderer.createTexture2D(tdesc);
	PX_ASSERT(m_texture);
	
	delete buffer;
#endif
}