예제 #1
0
void VideoComponent::render()
{
	if (m_playing && m_isOverlay)
	{
		// Render the overlay
		const float ww = (float)h3dGetNodeParamI( m_camId, H3DCamera::ViewportWidthI ) /
	                 (float)h3dGetNodeParamI( m_camId, H3DCamera::ViewportHeightI );

		//take the aspectRation into account for the x pos
		float x = m_x*ww;
		float w = m_w;
		if(m_stretchToAspect)
		{
			// and for the width if this is wanted
			w *= ww;
		}
						
		const float coords[] = 
		{
			x, m_y, 0, 1.0f,
			x, m_y+m_h, 0, 0,
			x+w, m_y+m_h, 1.0f, 0,
			x+w, m_y, 1.0f, 1.0f
		};
		h3dShowOverlays(coords, sizeof(coords) / 4, 1.0f,1.0f,1.0f,1.0f, m_material, 0);
	}
}
int QTerrainNode::blockSize() const
{
	if (m_xmlNode.hasAttribute("blocksize"))
		return m_xmlNode.attribute("blocksize").toInt();
	else
		return h3dGetNodeParamI(m_hordeID, H3DEXTTerrain::BlockSizeI );
}
예제 #3
0
파일: utils.cpp 프로젝트: cewbost/dlrts
void pickRay( H3DNode cameraNode, float nwx, float nwy,
              float *ox, float *oy, float *oz,
              float *dx, float *dy, float *dz )
{
	// Transform from normalized window [0, 1]
	// to normalized device coordinates [-1, 1]
	float cx( 2.0f * nwx - 1.0f );
	float cy( 2.0f * nwy - 1.0f );

	// Get projection matrix
	Matrix4f projMat;
	h3dGetCameraProjMat( cameraNode, projMat.x );

	// Get camera view matrix
	const float *camTrans;
	h3dGetNodeTransMats( cameraNode, 0x0, &camTrans );
	Matrix4f viewMat( camTrans );
	viewMat = viewMat.inverted();

	// Create inverse view-projection matrix for unprojection
	Matrix4f invViewProjMat = (projMat * viewMat).inverted();

	// Unproject
	Vec4f p0 = invViewProjMat * Vec4f( cx, cy, -1, 1 );
	Vec4f p1 = invViewProjMat * Vec4f( cx, cy, 1, 1 );
	p0.x /= p0.w; p0.y /= p0.w; p0.z /= p0.w;
	p1.x /= p1.w; p1.y /= p1.w; p1.z /= p1.w;

	if( h3dGetNodeParamI( cameraNode, H3DCamera::OrthoI ) == 1 )
	{
		float frustumWidth = h3dGetNodeParamF( cameraNode,  
								H3DCamera::RightPlaneF, 0 ) -
		                     	h3dGetNodeParamF( cameraNode,  
		                     	H3DCamera::LeftPlaneF, 0 );
		float frustumHeight = h3dGetNodeParamF( cameraNode, 
								H3DCamera::TopPlaneF, 0 ) -
		                      	h3dGetNodeParamF( cameraNode, 
		                      	H3DCamera::BottomPlaneF, 0 );

		Vec4f p2( cx, cy, 0, 1 );

		p2.x = cx * frustumWidth * 0.5f;
		p2.y = cy * frustumHeight * 0.5f;
		viewMat.x[12] = 0; viewMat.x[13] = 0; viewMat.x[14] = 0;
		p2 = viewMat.inverted() * p2;

		*ox = camTrans[12] + p2.x;
		*oy = camTrans[13] + p2.y;
		*oz = camTrans[14] + p2.z;
	}
	else
	{
		*ox = camTrans[12];
		*oy = camTrans[13];
		*oz = camTrans[14];
	}
	*dx = p1.x - p0.x;
	*dy = p1.y - p0.y;
	*dz = p1.z - p0.z;
}
예제 #4
0
파일: DemoApp.cpp 프로젝트: CZdravko/Horde
void DemoApp::resize(int width, int height) {
	H3DNode camID = GameEngine::entitySceneGraphID( m_camID );
	h3dSetNodeParamI( camID, H3DCamera::ViewportXI, 0 );
	h3dSetNodeParamI( camID, H3DCamera::ViewportYI, 0 );
	h3dSetNodeParamI( camID, H3DCamera::ViewportWidthI, width );
	h3dSetNodeParamI( camID, H3DCamera::ViewportHeightI, height );
	h3dResizePipelineBuffers( h3dGetNodeParamI( camID, H3DCamera::PipeResI ), width, height );
}
예제 #5
0
void SceneGraphComponent::getMeshData(MeshData* data)
{
	if (m_hordeID > 0)
	{
		H3DRes geoResource = 0;
		int vertexOffset = 0;
		int indexOffset = 0;
		switch(h3dGetNodeType(m_hordeID))
		{
		case H3DNodeTypes::Mesh:
			geoResource = h3dGetNodeParamI(h3dGetNodeParent(m_hordeID), H3DModel::GeoResI);
			data->NumVertices = h3dGetNodeParamI(m_hordeID, H3DMesh::VertREndI) - h3dGetNodeParamI(m_hordeID, H3DMesh::VertRStartI) + 1;
			data->NumTriangleIndices = h3dGetNodeParamI(m_hordeID, H3DMesh::BatchCountI);		
			data->VertRStart = h3dGetNodeParamI(m_hordeID, H3DMesh::VertRStartI);
			vertexOffset = h3dGetNodeParamI(m_hordeID, H3DMesh::VertRStartI) * 3;
			indexOffset = h3dGetNodeParamI(m_hordeID, H3DMesh::BatchStartI);
			break;
		case H3DNodeTypes::Model:
			geoResource = h3dGetNodeParamI(m_hordeID, H3DModel::GeoResI);
			data->NumVertices = h3dGetResParamI(geoResource, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoVertexCountI);
			data->NumTriangleIndices = h3dGetResParamI(geoResource, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoIndexCountI);		
			break;
		case H3DEXT_NodeType_Terrain:
			unloadTerrainGeoRes();
			geoResource = h3dextCreateTerrainGeoRes( 
				m_hordeID, 
				h3dGetNodeParamStr( m_hordeID, H3DNodeParams::NameStr ), 
				h3dGetNodeParamF( m_hordeID, H3DEXTTerrain::MeshQualityF, 0) );		
			data->NumVertices = h3dGetResParamI(geoResource, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoVertexCountI);
			data->NumTriangleIndices = h3dGetResParamI(geoResource, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoIndexCountI);		
			m_terrainGeoRes = geoResource;
			break;
		}
		float* vb = (float*)h3dMapResStream(geoResource, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoVertPosStream, true, false);
		data->VertexBase = new float[(data->NumVertices*3)];
		memcpy(data->VertexBase, vb+vertexOffset, sizeof(float)*data->NumVertices*3);
		h3dUnmapResStream(geoResource);

		//Triangle indices, must cope with 16 bit and 32 bit
		if (h3dGetResParamI(geoResource, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoIndices16I)) {
			unsigned short* tb = (unsigned short*)h3dMapResStream(geoResource, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoIndexStream, true, false);
			data->TriangleBase16 = new unsigned short[data->NumTriangleIndices];
			memcpy(data->TriangleBase16, tb+indexOffset, sizeof(unsigned short)*data->NumTriangleIndices);
			h3dUnmapResStream(geoResource);
		} else {
			unsigned int* tb = (unsigned int*)h3dMapResStream(geoResource, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoIndexStream, true, false);
			data->TriangleBase32 = new unsigned int[data->NumTriangleIndices];
			memcpy(data->TriangleBase32, tb+indexOffset, sizeof(unsigned int)*data->NumTriangleIndices);
			h3dUnmapResStream(geoResource);
		}
		//data->TriangleMode = Horde3D::getResourceParami(geoResource, GeometryResParams::TriangleMode);
	}
}
예제 #6
0
파일: DemoApp.cpp 프로젝트: dreamsxin/nawia
void DemoApp::resizeCb( void *userData, int width, int height )
{	
	DemoApp* app = static_cast<DemoApp*>(userData);
	H3DNode camID = GameEngine::entitySceneGraphID( app->m_camID );
	h3dSetNodeParamI( camID, H3DCamera::ViewportXI, 0 );
	h3dSetNodeParamI( camID, H3DCamera::ViewportYI, 0 );
	h3dSetNodeParamI( camID, H3DCamera::ViewportWidthI, width );
	h3dSetNodeParamI( camID, H3DCamera::ViewportHeightI, height );	
	h3dResizePipelineBuffers( h3dGetNodeParamI( camID, H3DCamera::PipeResI ), width, height );
}
예제 #7
0
void TentacleApplication::keyPressEvent( int key )
{
  if( key == 32 )		// Space
    _freeze = !_freeze;

  if( key == 260 )	// F3
  {
    if( h3dGetNodeParamI( _cam, H3DCamera::PipeResI ) == _hdrPipeRes )
      h3dSetNodeParamI( _cam, H3DCamera::PipeResI, _forwardPipeRes );
    else
      h3dSetNodeParamI( _cam, H3DCamera::PipeResI, _hdrPipeRes );
  }

  if( key == 264 )	// F7
    _debugViewMode = !_debugViewMode;

  if( key == 265 )	// F8
    _wireframeMode = !_wireframeMode;

  if( key == 266 )	// F9
    _showFPS = !_showFPS;

  if( key == 51 )// 3
  {
    //_currentSolver = _ikGSMMSolver;
    //_ikMethodString = "J transpose";
  } 

  if( key == 52 )	// 4
  {
    _currentSolver = _ikInvJacSolver;
    _ikMethodString = "J pseudoInv";
  }
  if( key == 53 )	// 5
  {
    //_currentSolver = _ikCCDSolver;
    //_ikMethodString = "CCD like";
  }
  if( key == 70 )	// F
    _freezeFly = !_freezeFly;

  if( key == 73 )// i
    _freezeIK = !_freezeIK;

  if( key == 80 )// p
    _ikStep= true;
}
예제 #8
0
파일: app.cpp 프로젝트: dreamsxin/nawia
void Application::keyPressEvent( int key )
{
	switch( key )
	{
	case '1':
		if( h3dIsSoundPlaying( _sound1 ) )
		{
			h3dPauseSound( _sound1 );
			h3dPauseSound( _sound2 );
		}
		else
		{
			h3dPlaySound( _sound1 );
			h3dPlaySound( _sound2 );
		}

		break;
	case '2':
		h3dRewindSound( _sound1 );
		h3dRewindSound( _sound2 );

		break;
	case '7':
		_soundLoop = !_soundLoop;

		h3dSetNodeParamI( _sound1, H3DSoundNodeParams::Loop, _soundLoop ? 1 : 0 );
		h3dSetNodeParamI( _sound2, H3DSoundNodeParams::Loop, _soundLoop ? 1 : 0 );
		break;
	case '8':
		// Rotate between the distance models
		switch( _distanceModel )
		{
		case H3DDistanceModels::None:
			_distanceModel = H3DDistanceModels::InverseDistance;
			break;
		case H3DDistanceModels::InverseDistance:
			_distanceModel = H3DDistanceModels::InverseDistanceClamped;
			break;
		case H3DDistanceModels::InverseDistanceClamped:
			_distanceModel = H3DDistanceModels::LinearDistance;
			break;
		case H3DDistanceModels::LinearDistance:
			_distanceModel = H3DDistanceModels::LinearDistanceClamped;
			break;
		case H3DDistanceModels::LinearDistanceClamped:
			_distanceModel = H3DDistanceModels::ExponentDistance;
			break;
		case H3DDistanceModels::ExponentDistance:
			_distanceModel = H3DDistanceModels::ExponentDistanceClamped;
			break;
		case H3DDistanceModels::ExponentDistanceClamped:
			_distanceModel = H3DDistanceModels::None;
			break;
		}

		h3dSetDistanceModel( _distanceModel );
		break;
	case GLFW_KEY_F3:
		if( h3dGetNodeParamI( _cam, H3DCamera::PipeResI ) == _hdrPipeRes )
			h3dSetNodeParamI( _cam, H3DCamera::PipeResI, _forwardPipeRes );
		else
			h3dSetNodeParamI( _cam, H3DCamera::PipeResI, _hdrPipeRes );

		break;
	case GLFW_KEY_F7:
		_debugViewMode = !_debugViewMode;
		h3dSetOption( H3DOptions::DebugViewMode, _debugViewMode ? 1.0f : 0.0f );
		break;
	case GLFW_KEY_F8:
		_wireframeMode = !_wireframeMode;
		h3dSetOption( H3DOptions::WireframeMode, _wireframeMode ? 1.0f : 0.0f );
		break;
	case GLFW_KEY_F6:
		_statMode += 1;

		if( _statMode > H3DUTMaxStatMode )
			_statMode = 0;

		break;
	}
}
예제 #9
0
파일: app.cpp 프로젝트: dreamsxin/nawia
void Application::mainLoop( float timeSinceLastFrame )
{
	keyHandler( timeSinceLastFrame );

	// Set camera parameters
	h3dSetNodeTransform( _cam, _x, _y, _z, _rx ,_ry, 0, 1, 1, 1 );

	_lightTimer += timeSinceLastFrame;

	// Has it gone a second since the light changed color?
	if( _lightTimer >= 1.0f )
	{
		// Set a random light color
		switch( rand() % 6 )
		{
		case 0:
			// Red
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 1.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 0.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 0.0f );
			break;
		case 1:
			// Green
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 0.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 1.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 0.0f );
			break;
		case 2:
			// Blue
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 0.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 0.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 1.0f );
			break;
		case 3:
			// Yellow
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 1.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 1.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 0.0f );
			break;
		case 4:
			// Purple
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 1.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 0.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 1.0f );
			break;
		case 5:
			// Cyan
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 0, 0.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 1, 1.0f );
			h3dSetNodeParamF( _light, H3DLight::ColorF3, 2, 1.0f );
			break;
		}

		// Reset the timer
		_lightTimer = 0.0f;
	}

	// Show stats
	h3dutShowFrameStats( _fontMatRes, _panelMatRes, _statMode );
	if( _statMode > 0 )
	{	
		displaySoundInfo();
	}

	// Show logo
	const float ww = (float)h3dGetNodeParamI( _cam, H3DCamera::ViewportWidthI ) /
	                 (float)h3dGetNodeParamI( _cam, H3DCamera::ViewportHeightI );
	const float ovLogo[] = { ww-0.4f, 0.8f, 0, 1,  ww-0.4f, 1, 0, 0,  ww, 1, 1, 0,  ww, 0.8f, 1, 1 };
	h3dShowOverlays( ovLogo, 4, 1.f, 1.f, 1.f, 1.f, _logoMatRes, 0 );

	// Render scene
	h3dRender( _cam );

	// Finish rendering of frame
	h3dFinalizeFrame();

	// Remove all overlays
	h3dClearOverlays();

	// Write all mesages to log file
	h3dutDumpMessages();
}
예제 #10
0
void Button::updateView(float mouseData[2], int clickType, wchar_t keyChar, vector<string> eventCompList) {

	if (getVisible() == true) {

		sentClickEvent = false;

		float posX = getPosX();
		float posY = getPosY();
		float height = getHeight();
		float width = getWidth();

		float transparency = getTransparency();

		if ((getFocusEffect() == true) && (getMouseOverContainer() == true)) transparency = 1.0f;


		if (getEnabled() == false)
			setActualTex(getDisabledTex());
		else {

			if ((isMouseOver(mouseData) == true) && (getMouseOverContainer())) {			
				if (getFocusEffect() == true)
					transparency = 1.0f;

				

				if (clickType == 0) {

					if (hintCounter < 1.0f)
						hintCounter += 1/GameEngine::FPS();

					if (getActualTex() != getPressedTex())
					{
					setActualTex(getHighlightTex());
					
					if (wasLeft) sendOnce = false;

					if ((sendOnce == false) && (wasLeft == true)) {
						sendOnce = true;
						wasOver = true;
						wasLeft = false;
						GUIEventData::sendToGUI(new GUIEventData(O_COMP_MOUSEOVER,this->getName()));
						sendEvents(O_COMP_MOUSEOVER, eventCompList);
	
					}
						if (hintCounter >= 1.0f) {
							if (!hint->getVisible() ) {

								//needed for aspect ratio (maximum width)
								int m_camID = GameEngine::entityWorldID("camera");
								int x,y, width, height;
								H3DNode camID = GameEngine::entitySceneGraphID( m_camID );
								x = h3dGetNodeParamI( camID, H3DCamera::ViewportXI);
								y = h3dGetNodeParamI( camID, H3DCamera::ViewportYI);
								width = h3dGetNodeParamI( camID, H3DCamera::ViewportWidthI);
								height = h3dGetNodeParamI( camID, H3DCamera::ViewportHeightI);

								float aspect = (float)width/(float)height;

								hint->setText(getHintText());
								float posX = mouseData[0]+0.03f;
								if (posX+ hint->getWidth() > aspect) posX = aspect - hint->getWidth() - 0.01f;
								hint->setPosX(posX);

								float posY = mouseData[1]+0.06f;
								if (posY+ hint->getHeight() > 1.0f) posY = mouseData[1] - hint->getHeight() - 0.06f;
								hint->setPosY(posY);

								hint->setVisible(true);
							}
						}
					}
				}

				if (clickType == 1) {
					setActualTex(getPressedTex());
					clickWasOver = true;
				}

				if ((clickType == -1) && (clickWasOver)) {
					setActualTex(getHighlightTex());

					if (wasLeft) sendOnce = false;

					if ((sendOnce == false) && (wasLeft == true)) {
						sendOnce = true;
						wasOver = true;
						wasLeft = false;
						GUIEventData::sendToGUI(new GUIEventData(O_COMP_MOUSEOVER,this->getName()));
						sendEvents(O_COMP_MOUSEOVER, eventCompList);
					}

					//prevent sending the same event multiple times
					if (oldClickType != clickType)
					{
						//send event to all listed components
						sendEvents(O_BUTTON_CLICKED, eventCompList);
						//send to GUI for sound
						GUIEventData::sendToGUI(new GUIEventData(O_BUTTON_CLICKED,this->getName()));
						sentClickEvent = true;
					}

				}

			}
			else {

				clickWasOver = false;

				setActualTex(getNormalTex());

				if (wasOver) sendOnce = false;

				if ((sendOnce == false) && (wasOver == true)) {
					sendOnce = true;
					wasOver = false;
					wasLeft = true;
					GUIEventData::sendToGUI(new GUIEventData(O_COMP_MOUSELEFT,this->getName()));
					sendEvents(O_COMP_MOUSELEFT, eventCompList);

					hint->setVisible(false);
					hintCounter = 0.0f;
					}

			}
		}

		oldClickType = clickType;

		float vals[] = {		posX, posY, 0, 1,  
			posX, posY+height, 0, 0,  
			posX+width, posY+height, 1, 0,  
			posX+width, posY, 1, 1 
		};

		h3dShowOverlays(vals, 4,1, 1, 1, transparency,getActualTex(), 0 );

	} else	if (!wasLeft) {
			//if a mouseleft event wasn't sent it's done here
			GUIEventData::sendToGUI(new GUIEventData(O_COMP_MOUSELEFT,this->getName()));
			wasLeft = true;
		}
}
	btCollisionShape* createCollisionShape()
	{
		if (mesh->getModelNode() == 0) mesh->registerStart();

		m_btTriangleMesh = new btTriangleMesh();
		H3DNode meshNode = h3dGetNodeChild(mesh->getModelNode(), 0); //TODO handle multi-mesh stuff
		if (meshNode == 0) throw Exception("Couldn't get mesh node.\n");
		H3DRes geoRes = h3dGetNodeParamI(mesh->getModelNode(), H3DModel::GeoResI);
		unsigned int numVertices = h3dGetNodeParamI(meshNode, H3DMesh::VertREndI) - h3dGetNodeParamI(meshNode, H3DMesh::VertRStartI) + 1;//get mesh vertices count
		unsigned int numTriangleIndices = h3dGetNodeParamI(meshNode, H3DMesh::BatchCountI);//get mesh triangle indices count
		unsigned int vertRStart = h3dGetNodeParamI(meshNode, H3DMesh::VertRStartI);//get the first vertex of the mesh
		int off = 3;


		std::cout << numVertices << " vertices.\n";
		std::cout << numTriangleIndices << " indices.\n";

		int vertexOffset = vertRStart * 3;
		int indexOffset = h3dGetNodeParamI(meshNode, H3DMesh::BatchStartI);

		float* vertexBase = (float*) h3dMapResStream(geoRes, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoVertPosStream, true, false);//gets pointer to the vertex data
		h3dUnmapResStream(geoRes);//closes vertex stream

		if(vertexBase) vertexBase += vertexOffset;

		unsigned int* TriangleBase32 = nullptr;
		unsigned short* TriangleBase16 = nullptr;

		if (h3dGetResParamI(geoRes, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoIndices16I))
		{
			unsigned short* tb = (unsigned short*)h3dMapResStream(geoRes, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoIndexStream, true, false);
			TriangleBase16 = new unsigned short[ numTriangleIndices ];
			memcpy(TriangleBase16, tb+indexOffset, sizeof(unsigned short)*numTriangleIndices);
			h3dUnmapResStream(geoRes);
			delete TriangleBase32;
		}
		else
		{
			unsigned int* tb = (unsigned int*)h3dMapResStream(geoRes, H3DGeoRes::GeometryElem, 0, H3DGeoRes::GeoIndexStream, true, false);
			TriangleBase32 = new unsigned int[numTriangleIndices];
			memcpy(TriangleBase32, tb+indexOffset, sizeof(unsigned int)*numTriangleIndices);
			h3dUnmapResStream(geoRes);
			delete TriangleBase16;
		}

		unsigned int indices[numTriangleIndices];

		bool index16 = false;
		if (TriangleBase16)
			index16 = true;

	    for (unsigned int i = 0; i < numTriangleIndices - 2; i += 3)
		 {
			unsigned int index1 = index16 ? (TriangleBase16[i]   - vertRStart) * 3 : (TriangleBase32[i]   - vertRStart) * 3;
			unsigned int index2 = index16 ? (TriangleBase16[i+1] - vertRStart) * 3 : (TriangleBase32[i+1] - vertRStart) * 3;
			unsigned int index3 = index16 ? (TriangleBase16[i+2] - vertRStart) * 3 : (TriangleBase32[i+2] - vertRStart) * 3;

			m_btTriangleMesh->addTriangle(
			   btVector3(vertexBase[index1], vertexBase[index1+1], vertexBase[index1+2] ),
			   btVector3(vertexBase[index2], vertexBase[index2+1], vertexBase[index2+2] ),
			   btVector3(vertexBase[index3], vertexBase[index3+1], vertexBase[index3+2]),
			   false
			);
		 }

	    return new btBvhTriangleMeshShape(m_btTriangleMesh, true, true);
	}