Exemplo n.º 1
0
void CZoneEdge::buildMatrix (NLMISC::CMatrix& mat, const CLigoConfig &config) const
{
	// Build a transformation matrix
	mat.identity();
	mat.rotateZ ((float)Pi*(float)_Rotation/2.f);
	mat.setPos (CVector (config.CellSize*(float)_OffsetX, config.CellSize*(float)_OffsetY, 0));
}
Exemplo n.º 2
0
void CVegetableEditor::update()
{
	// Vegetable: manage collision snapping if wanted and possible
	if(_VegetableSnapToGround && _VegetableLandscape)
	{
		// get matrix from camera.
		NLMISC::CMatrix	matrix = Modules::objView().getScene()->getCam().getMatrix();

		// snap To ground.
		NLMISC::CVector pos = matrix.getPos();
		// if succes to snap to ground
		if(_VegetableCollisionEntity->snapToGround(pos))
		{
			pos.z+= _VegetableSnapHeight;
			matrix.setPos(pos);
			// reset the moveListener and the camera.
			Modules::objView().get3dMouseListener()->setMatrix(matrix);
			Modules::objView().getScene()->getCam().setMatrix(matrix);
		}
	}
}
Exemplo n.º 3
0
// ***************************************************************************
void COutpost::initOutpost ()
{
    // remove the outpost from col, if any
    removeOutpost();

    // Add collisions, if correclty setuped
    if (_OutpostId > -1)
    {
        // Register RZ_MAX_BUILDING_PER_OUTPOST observers for the RZ_MAX_BUILDING_PER_OUTPOST buildings
        uint i;
        for (i=0; i<RZ_MAX_BUILDING_PER_OUTPOST; i++)
        {
            // Put the ZC pacs_prim
            TPacsPrimMap::iterator pbIt = PacsPrims.find(NLMISC::strlwr(NLMISC::CFile::getFilenameWithoutExtension(ClientCfg.ZCPacsPrim)));
            if (pbIt != PacsPrims.end())
            {
                // Build the building matrix
                NLMISC::CMatrix instanceMatrix;
                instanceMatrix.identity();
                instanceMatrix.setRot(_Buildings[i].Rotation);
                instanceMatrix.setPos(_Buildings[i].Position);

                // Compute orientation and position
                NLMISC::CVector pos;
                float			angle;
                NLPACS::UMoveContainer::getPACSCoordsFromMatrix(pos, angle, instanceMatrix);

                // insert the matching primitive block
                if (PACS)
                    PACS->addCollisionnablePrimitiveBlock(pbIt->second, 0, 1, &_AddedPrims, angle, pos, true, CVector(1,1,1));
            }
        }
    }

    // add 3D if needed
    if(_Village)
        _Village->initOutpost();
}
/** Load and compute the bbox of the models that are contained in a given instance group
  * \return true if the computed bbox is valid
  */
static void computeIGBBox(const NL3D::CInstanceGroup &ig, CLightingBBox &result, TShapeMap &shapeMap)
{
	result = CLightingBBox(); // starts with void result
	bool firstBBox = true;	
	/// now, compute the union of all bboxs
	for (CInstanceGroup::TInstanceArray::const_iterator it = ig._InstancesInfos.begin(); it != ig._InstancesInfos.end(); ++it)
	{		
		CLightingBBox currBBox;
		
		bool validBBox = false;
		/// get the bbox from file or from map
		if (shapeMap.count(it->Name)) // already loaded ?
		{
			currBBox = shapeMap[it->Name];
			validBBox = true;
		}
		else // must load the shape to get its bbox
		{		
			std::string shapePathName;
			std::string toLoad = it->Name;
			if (getExt(toLoad).empty()) toLoad += ".shape";
			shapePathName = NLMISC::CPath::lookup(toLoad, false, false);

			if (shapePathName.empty())
			{
				nlwarning("Unable to find shape %s", it->Name.c_str());				
			}
			else
			{
				CIFile shapeInputFile;
				
				if (shapeInputFile.open (shapePathName.c_str()))
				{					
					NL3D::CShapeStream shapeStream;
					try
					{
						shapeStream.serial (shapeInputFile);
						// NB Nico :
						// Deal with water shape -> their 'Receiving' box is set to 'void'
						// this prevent the case where a huge surface of water will cause the zone it is attached to (the 'Zone'
						// field in the villages sheets) to load all the zones that the water surface cover. (This caused
						// an 'out of memory error' in the zone lighter due to too many zone being loaded)
						
						// FIXME : test for water case hardcoded for now						
						CWaterShape *ws = dynamic_cast<CWaterShape *>(shapeStream.getShapePointer());
						if (ws)
						{
							CAABBox bbox;
							shapeStream.getShapePointer()->getAABBox(bbox);
							currBBox.OccludingBox = CPotentialBBox(bbox); // occluding box is used, though the water shape
																		 // doesn't cast shadow -> the tiles flag ('above', 'intersect', 'below water')
																		 // are updated inside the zone_lighter
							currBBox.ReceivingBox.IsVoid = true; // no lighted by the zone lighter !!!
							currBBox.removeVoid();
							shapeMap[it->Name] = currBBox;							
						}
						else
						{

							CAABBox bbox;
							shapeStream.getShapePointer()->getAABBox(bbox);
							currBBox.OccludingBox = CPotentialBBox(bbox);
							currBBox.ReceivingBox = CPotentialBBox(bbox);
							currBBox.removeVoid();
							shapeMap[it->Name] = currBBox;
						}
						validBBox = true;
					}
					
					catch (NLMISC::Exception &e)
					{
						nlwarning("Error while loading shape %s. \n\t Reason : %s ", it->Name.c_str(), e.what());
					}				
				}
				else
				{
					nlwarning("Unable to open shape file %s to get its bbox", it->Name.c_str());
				}
			}
		}


		if (validBBox)
		{
			/// build the model matrix
			NLMISC::CMatrix mat;
			mat.scale(it->Scale);
			NLMISC::CMatrix rotMat;
			rotMat.setRot(it->Rot);
			mat = rotMat * mat;
			mat.setPos(it->Pos);

			/// transform the bbox
			currBBox.transform(mat);
			currBBox.removeVoid();			
			if (firstBBox)
			{
				result = currBBox;
				firstBBox = false;
			}
			else // add to previous one
			{						
				result.makeUnion(currBBox);
			}			
		}		
	}	
}