SW_And_OpenGLGuiHelper(CommonGraphicsApp* glApp, bool useOpenGL2, int swWidth, int swHeight, GLPrimitiveRenderer* primRenderer)
		: OpenGLGuiHelper(glApp, useOpenGL2),
		  m_swWidth(swWidth),
		  m_swHeight(swHeight),
		  m_rgbColorBuffer(swWidth, swHeight, TGAImage::RGB),
		  m_primRenderer(primRenderer)
	{
		m_depthBuffer.resize(swWidth * swHeight);
		CommonRenderInterface* render = getRenderInterface();
		m_image = new unsigned char[m_swWidth * m_swHeight * 4];

		m_textureHandle = render->registerTexture(m_image, m_swWidth, m_swHeight);
	}
Beispiel #2
0
void OpenGLGuiHelper::resetCamera(float camDist, float pitch, float yaw, float camPosX,float camPosY, float camPosZ)
{
    if (getRenderInterface() && getRenderInterface()->getActiveCamera())
    {
        getRenderInterface()->getActiveCamera()->setCameraDistance(camDist);
        getRenderInterface()->getActiveCamera()->setCameraPitch(pitch);
        getRenderInterface()->getActiveCamera()->setCameraYaw(yaw);
        getRenderInterface()->getActiveCamera()->setCameraTargetPosition(camPosX,camPosY,camPosZ);
    }
}
Beispiel #3
0
void OpenGLGuiHelper::copyCameraImageData(unsigned char* pixelsRGBA, int rgbaBufferSizeInPixels, float* depthBuffer, int depthBufferSizeInPixels, int startPixelIndex, int* widthPtr, int* heightPtr, int* numPixelsCopied)
{
    int w = m_data->m_glApp->m_window->getWidth()*m_data->m_glApp->m_window->getRetinaScale();
    int h = m_data->m_glApp->m_window->getHeight()*m_data->m_glApp->m_window->getRetinaScale();

    if (widthPtr)
        *widthPtr = w;
    if (heightPtr)
        *heightPtr = h;
    if (numPixelsCopied)
        *numPixelsCopied = 0;

    int numTotalPixels = w*h;
    int numRemainingPixels = numTotalPixels - startPixelIndex;
    int numBytesPerPixel = 4;//RGBA
    int numRequestedPixels  = btMin(rgbaBufferSizeInPixels,numRemainingPixels);
    if (numRequestedPixels)
    {
        if (startPixelIndex==0)
        {

            //quick test: render the scene
            getRenderInterface()->renderScene();
            //copy the image into our local cache
            m_data->m_rgbaPixelBuffer.resize(w*h*numBytesPerPixel);
            m_data->m_depthBuffer.resize(w*h);
            m_data->m_glApp->getScreenPixels(&(m_data->m_rgbaPixelBuffer[0]),m_data->m_rgbaPixelBuffer.size());
        }
        for (int i=0; i<numRequestedPixels*numBytesPerPixel; i++)
        {
            if (pixelsRGBA)
            {
                pixelsRGBA[i] = m_data->m_rgbaPixelBuffer[i+startPixelIndex*numBytesPerPixel];
            }
        }

        if (numPixelsCopied)
            *numPixelsCopied = numRequestedPixels;


    }


}
void	ImplicitClothExample::physicsDebugDraw(int debugFlags)
{

    CommonRenderInterface* renderer = m_guiHelper->getRenderInterface();

    b3AlignedObjectArray<unsigned int> indices;

    for (int i=0; i<m_cloth->springs.count; i++)
    {
        indices.push_back(m_cloth->springs[i].a);
        indices.push_back(m_cloth->springs[i].b);
    }
    float lineColor[4]= {0.4,0.4,1.0,1};
    renderer->drawLines(&m_cloth->X[0].x,lineColor,total_points,sizeof(float3),&indices[0],indices.size(),1);

    float pointColor[4]= {1,0.4,0.4,1};

//		renderer->drawPoints(&m_cloth->X[0].x,pointColor,total_points,sizeof(float3),3);


}
Beispiel #5
0
void TinyRendererSetup::stepSimulation(float deltaTime)
{
    m_internalData->updateTransforms();
    
    if (!m_useSoftware)
    {
        
        for (int i=0;i<m_internalData->m_transforms.size();i++)
        {
            m_guiHelper->getRenderInterface()->writeSingleInstanceTransformToCPU(m_internalData->m_transforms[i].getOrigin(),m_internalData->m_transforms[i].getRotation(),i);
        }
        m_guiHelper->getRenderInterface()->writeTransforms();
        m_guiHelper->getRenderInterface()->renderScene();
    } else
    {
        
        TGAColor clearColor;
        clearColor.bgra[0] = 200;
        clearColor.bgra[1] = 200;
        clearColor.bgra[2] = 200;
        clearColor.bgra[3] = 255;
        for(int y=0;y<m_internalData->m_height;++y)
        {
            for(int x=0;x<m_internalData->m_width;++x)
            {
                m_internalData->m_rgbColorBuffer.set(x,y,clearColor);
                m_internalData->m_depthBuffer[x+y*m_internalData->m_width] = -1e30f;
            }
        }


        ATTRIBUTE_ALIGNED16(btScalar modelMat2[16]);
        ATTRIBUTE_ALIGNED16(float viewMat[16]);
        ATTRIBUTE_ALIGNED16(float projMat[16]);
        CommonRenderInterface* render = this->m_app->m_renderer;
        render->getActiveCamera()->getCameraViewMatrix(viewMat);
        render->getActiveCamera()->getCameraProjectionMatrix(projMat);
            

        
        for (int o=0;o<this->m_internalData->m_renderObjects.size();o++)
        {
                
            const btTransform& tr = m_internalData->m_transforms[o];
            tr.getOpenGLMatrix(modelMat2);
            
                    
            for (int i=0;i<4;i++)
            {
                for (int j=0;j<4;j++)
                {
                    m_internalData->m_renderObjects[o]->m_modelMatrix[i][j] = float(modelMat2[i+4*j]);
                    m_internalData->m_renderObjects[o]->m_viewMatrix[i][j] = viewMat[i+4*j];
                    m_internalData->m_renderObjects[o]->m_projectionMatrix[i][j] = projMat[i+4*j];
                    
                    float eye[4];
                    float center[4];
                    render->getActiveCamera()->getCameraPosition(eye);
                    render->getActiveCamera()->getCameraTargetPosition(center);

                    m_internalData->m_renderObjects[o]->m_eye.setValue(eye[0],eye[1],eye[2]);
                    m_internalData->m_renderObjects[o]->m_center.setValue(center[0],center[1],center[2]);
                }
            }
            TinyRenderer::renderObject(*m_internalData->m_renderObjects[o]);
        }
        //m_app->drawText("hello",500,500);
        render->activateTexture(m_internalData->m_textureHandle);
        render->updateTexture(m_internalData->m_textureHandle,m_internalData->m_rgbColorBuffer.buffer());
        float color[4] = {1,1,1,1};
        m_app->drawTexturedRect(0,0,m_app->m_window->getWidth(), m_app->m_window->getHeight(),color,0,0,1,1,true);
    }
}
	virtual void render(const btDiscreteDynamicsWorld* rbWorld)
	{
		OpenGLGuiHelper::render(rbWorld);

		//clear the color buffer
		TGAColor clearColor;
		clearColor.bgra[0] = 255;
		clearColor.bgra[1] = 255;
		clearColor.bgra[2] = 255;
		clearColor.bgra[3] = 255;

		clearBuffers(clearColor);

		ATTRIBUTE_ALIGNED16(btScalar modelMat[16]);
		ATTRIBUTE_ALIGNED16(float viewMat[16]);
		ATTRIBUTE_ALIGNED16(float projMat[16]);

		CommonRenderInterface* render = getRenderInterface();

		render->getActiveCamera()->getCameraProjectionMatrix(projMat);
		render->getActiveCamera()->getCameraViewMatrix(viewMat);

		btVector3 lightDirWorld(-5, 200, -40);
		switch (1)  //app->getUpAxis())
		{
			case 1:
				lightDirWorld = btVector3(-50.f, 100, 30);
				break;
			case 2:
				lightDirWorld = btVector3(-50.f, 30, 100);
				break;
			default:
			{
			}
		};

		lightDirWorld.normalize();

		for (int i = 0; i < rbWorld->getNumCollisionObjects(); i++)
		{
			btCollisionObject* colObj = rbWorld->getCollisionObjectArray()[i];
			int colObjIndex = colObj->getUserIndex();
			int shapeIndex = colObj->getCollisionShape()->getUserIndex();
			if (colObjIndex >= 0 && shapeIndex >= 0)
			{
				TinyRenderObjectData* renderObj = 0;

				int* cptr = m_swInstances[colObjIndex];
				if (cptr)
				{
					int c = *cptr;
					TinyRenderObjectData** sptr = m_swRenderObjects[c];
					if (sptr)
					{
						renderObj = *sptr;
						//sync the object transform
						const btTransform& tr = colObj->getWorldTransform();
						tr.getOpenGLMatrix(modelMat);

						for (int i = 0; i < 4; i++)
						{
							for (int j = 0; j < 4; j++)
							{
								renderObj->m_projectionMatrix[i][j] = projMat[i + 4 * j];
								renderObj->m_modelMatrix[i][j] = modelMat[i + 4 * j];
								renderObj->m_viewMatrix[i][j] = viewMat[i + 4 * j];
							}
						}
						renderObj->m_localScaling = colObj->getCollisionShape()->getLocalScaling();
						renderObj->m_lightDirWorld = lightDirWorld;
						renderObj->m_lightAmbientCoeff = 0.6;
						renderObj->m_lightDiffuseCoeff = 0.35;
						renderObj->m_lightSpecularCoeff = 0.05;
						TinyRenderer::renderObject(*renderObj);
					}
				}
			}
		}

		for (int y = 0; y < m_swHeight; ++y)
		{
			unsigned char* pi = m_image + (y)*m_swWidth * 3;
			for (int x = 0; x < m_swWidth; ++x)
			{
				const TGAColor& color = getFrameBuffer().get(x, y);
				pi[0] = color.bgra[2];
				pi[1] = color.bgra[1];
				pi[2] = color.bgra[0];
				pi += 3;
			}
		}
		render->activateTexture(m_textureHandle);
		render->updateTexture(m_textureHandle, m_image);

		static int counter = 0;
		counter++;
		if ((counter & 7) == 0)
		{
			char filename[1024];
			sprintf(filename, "framebuf%d.tga", counter);
			getFrameBuffer().write_tga_file(filename, true);
		}
		float color[4] = {1, 1, 1, 1};
		m_primRenderer->drawTexturedRect(0, 0, m_swWidth, m_swHeight, color, 0, 0, 1, 1, true);
	}