void QModelNode::activate()
{
	float minX, minY, minZ, maxX, maxY, maxZ;
	h3dGetNodeAABB(m_hordeID, &minX, &minY, &minZ, &maxX, &maxY, &maxZ);

	unsigned int cameraID = HordeSceneEditor::instance()->glContext()->activeCam();
	float leftPlane = h3dGetNodeParamF(cameraID, H3DCamera::LeftPlaneF, 0 );
	float rightPlane = h3dGetNodeParamF(cameraID, H3DCamera::RightPlaneF, 0);
	float bottomPlane = h3dGetNodeParamF(cameraID, H3DCamera::BottomPlaneF, 0);
	float topPlane = h3dGetNodeParamF(cameraID, H3DCamera::TopPlaneF, 0);
	float nearPlane = h3dGetNodeParamF(cameraID, H3DCamera::NearPlaneF, 0);

	const float* camera = 0;
	H3DNode parentNode = h3dGetNodeParent(cameraID);
	h3dGetNodeTransMats(parentNode, 0, &camera); 
	if ( !camera ) return;
	
	/** 
	 * (maxX - minX)                           =   width of the bounding box 
	 * rightPlane / (rightPlane - leftPlane)   =   right fraction of the viewing frustum
	 */
	float offsetX = (maxX - minX) * rightPlane / (rightPlane - leftPlane);
	float offsetY = (maxY - minY) * topPlane / (topPlane - bottomPlane);
	QMatrix4f newCamTrans = QMatrix4f::TransMat(maxX - offsetX, maxY - offsetY, maxZ);
	newCamTrans.translate(0, 0, qMax(nearPlane * offsetX / rightPlane, nearPlane * offsetY / topPlane));		
	h3dSetNodeTransMat(cameraID, (QMatrix4f(camera).inverted() * newCamTrans).x);	
}
Beispiel #2
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);
	}
}
//////////////////////////
//Instance funcitons
Joint::Joint(H3DNode id) : m_horde_id(id), m_dofr( DOFRestrictions::FULL_FREEDOM ), m_model_hID(0)
{
#if defined PLATFORM_WIN
	memcpy_s(m_name, 32, h3dGetNodeParamStr( id, H3DNodeParams::NameStr ), 32);
#else
    memcpy(m_name, h3dGetNodeParamStr( id, H3DNodeParams::NameStr ), 32);
#endif

	//find joint's model (agent)
	H3DNode node = m_horde_id;
	while(h3dGetNodeType(node) != H3DNodeTypes::Model)
		node = h3dGetNodeParent(node);
	m_model_hID = node;
	m_model_eID = GameEngine::sceneGraphEntityID(m_model_hID);

	update();
}
Beispiel #4
0
void SceneGraphComponent::sendTransformation()
{
	if (m_hordeID > 0)
	{
//		printf("Inside send Transformation with hID: %d\n", m_hordeID);
		const float* parentMat = 0;
		// since the event transformation is absolute we have to create a relative transformation matrix for Horde3D
		h3dGetNodeTransMats(h3dGetNodeParent(m_hordeID), 0, &parentMat);		
		if (parentMat) h3dSetNodeTransMat(m_hordeID, (Matrix4f(parentMat).inverted() * Matrix4f(m_transformation)).x);
		else printf("no parent MAT\n");
		// ensure reset of Horde3D transformation flag since we have updated it from the GameEngine and such don't need to be informed 
		// when calling SceneGraphComponent::update() (note that the node transformed flag will be set again if someone else will update
		// the transformation from outside, so this way of avoiding unnecessary updates should be safe)
		h3dCheckNodeTransFlag( m_hordeID, true );
		//printf("SceneGraphComponent::setTransformation\n\t %.3f, %.3f, %.3f\n", transformation[12], transformation[13], transformation[14]);
		m_visibilityFlag = 0;
	}
}
Joint* Joint::getParent()
{
	H3DNode p = h3dGetNodeParent(m_horde_id);
	return (p==0) ? 0 : getInstance(p);
}