Exemple #1
0
bool JsonLd::addContext(
   DynamicObject& context, DynamicObject& in, DynamicObject& out)
{
   bool rval = true;

   // "a" is automatically shorthand for rdf type
   DynamicObject ctx = (context.isNull() ? DynamicObject() : context.clone());
   ctx["a"] = RDF_TYPE;

   // TODO: should context simplification be an option? (ie: remove context
   // entries that are not used in the output)

   // setup output context
   DynamicObject& contextOut = out["#"];
   contextOut->setType(Map);

   // apply context
   _applyContext(ctx, contextOut, NULL, in, out);

   // clean up
   if(contextOut->length() == 0)
   {
      out->removeMember("#");
   }

   return rval;
}
Exemple #2
0
static DynamicObject _getExceptionGraph(
   DynamicObject& context, DynamicObject& autoContext, RdfaReader::Graph* g)
{
   DynamicObject rval(NULL);

   // clone auto context
   DynamicObject ctx = autoContext.clone();

   // use user-set context
   if(!context.isNull())
   {
      ctx = context.clone();
   }

   // save the old processor target and frame
   DynamicObject target = g->target;
   DynamicObject frame = g->frame;

   // use frame to embed error context in exception
   g->frame = DynamicObject();
   //g->frame["@context"] = JsonLd::createDefaultContext();
   g->frame["@type"] =
      "http://www.w3.org/ns/rdfa_processing_graph#Error";
   g->frame["http://www.w3.org/ns/rdfa_processing_graph#context"]->setType(Map);

   // finish processor graph
   g->target = DynamicObject();
   _finishGraph(ctx, g);
   rval = g->target;

   // reset old target and frame
   g->target = target;
   g->frame = frame;

   return rval;
}
Exemple #3
0
/*
	Retrieves a DynamicObject from the game library.
	Returns null if no object was found that matches name.
*/
DynamicObject * GameLibrary::getDynamicObject(string name) {
	// see if an instance of the object exists in dynamicObjects map.
	// if not load it in from memory, create it, and put it in the map.

	unordered_map<string, DynamicObject*> ::iterator it = dynamicObjects.find(name);

	DynamicObject *dynObj;
 	if(it != dynamicObjects.end())
	{
		//element found;
		dynObj = it->second;

		// create a clone of it.
		return dynObj->clone(this->mSceneManager);

	} else {
		// element was not found.
		// load it in and create instance 

		std::string fileName = "../TeamProject/GameData/DynamicObjects/" + name +".json";
		FILE* pFile = fopen(fileName.c_str(), "rb");
		
		if (pFile != NULL) {
			char buffer[65536];
			rapidjson::FileReadStream is(pFile, buffer, sizeof(buffer));
			rapidjson::Document document;
			document.ParseStream<0, rapidjson::UTF8<>, rapidjson::FileReadStream>(is);

			// File was opened successfully and parsed into JSON,
			// now we create the instance

			list<Ogre::String> meshNames;
			if (document.HasMember("meshNames")) {
				for (int i = 0; i < document["meshNames"].Size(); i++) {
					meshNames.push_back(document["meshNames"][i].GetString());
				}
			} else {
				meshNames.push_back("ERROR.MESH.mesh");
			}


			// Parse data for the construction of the rigid body

			double restitution;
			if (document.HasMember("restitution")) {
				restitution = document["restitution"].GetDouble();
			} else {
				restitution = 0.0;
			}

			int massTemp;
			if (document.HasMember("mass")) {
				massTemp = document["mass"].GetInt();
			} else {
				massTemp = 1;
			}


			// Parse scale info
			Ogre::Vector3 scale = Ogre::Vector3(1, 1, 1);
			if (document.HasMember("scale")) {
				scale = parseVector3(document["scale"]);
			} else 
			{
				scale = Ogre::Vector3(1, 1, 1);
			}

			// Needed for collisions 
			// interaction legend by diana 
			// -1 = no interaction 
			// 1 = teapots meaning they disappear (for now) 
			// 2 = tuna can (ending... for now) 
			int interaction;
			if (document.HasMember("interaction")) {
				interaction = document["interaction"].GetInt();
			} else {
				interaction = -1; // this means there's no interaction 
			}


			string collisionShape;
			if (document.HasMember("collisionShape")) {
				collisionShape = document["collisionShape"].GetString();
			} else {
				collisionShape = "btBoxShape";
			}


			
			// temp vars used for parsing collision shape size data
			btVector3 colDim3 = btVector3(1,1,1);
			btScalar colScala = 1;
			btScalar colScalb = 1;

			/* Parse the CollisionShape and its size size */
			

			// if no collision shape size is specified in the json file
			// base its size off of the dimensions of the mesh
			// For simplicity, this only works if the dynamic object has
			// one mesh. 

			Ogre::Vector3 meshDimensions;
			std::string s = std::to_string(meshNames.size()); 
			

			if (!document.HasMember("collisionShapeSize")) {

				// XXX: The collision shape auto sizing functionality is experimental
				// and needs to be tested.

				Ogre::Entity* tempEntity = mSceneManager->createEntity(meshNames.front());
				colDim3 = ogreToBulletVector3(tempEntity->getMesh()->getBounds().getHalfSize());
				colScala = tempEntity->getMesh()->getBoundingSphereRadius(); // radius
				colScalb = tempEntity->getMesh()->getBounds().getSize()[1]; // height
			
				// apply scale
				colDim3 = btVector3(colDim3[0] * scale.x, colDim3[1] * scale.y, colDim3[2] * scale.z);
				colScala = colScala * scale.x;
				colScalb = colScalb * scale.y;

			} else if(document.HasMember("collisionShapeSize")) {
				/// Note: FIgure out why it keeps going into this if block instead of the first one 
				if (document["collisionShapeSize"].Size() == 3) {
					colDim3 = ogreToBulletVector3(parseVector3(document["collisionShapeSize"]));
				}
				colScala = document["collisionShapeSize"][0].GetDouble();	
				colScalb = document["collisionShapeSize"][1].GetDouble();   
			} else {
				OutputDebugString("ERROR! Need to specify the collisionshape size!");
				// default collision shape sizes
				colDim3 = btVector3(1,1,1);
				colScala = 1;
				colScalb = 1;
			}


			
			// holds the actual collision shape of the object
			btCollisionShape *colShape;
			
			if (collisionShape.compare("btSphereShape") == 0) {
				colShape = new btSphereShape(colScala);
			} else if(collisionShape.compare("btBoxShape") == 0) {
				colShape = new btBoxShape(colDim3);
			} else if(collisionShape.compare("btCylinderShape") == 0) {
				colShape = new btCylinderShape(colDim3);
			} else if(collisionShape.compare("btCapsuleShape") == 0) {
				colShape = new btCapsuleShape(colScala, colScalb);
			} else {
				// default to box shape if no valid collision shape was found
				colShape = new btBoxShape(btVector3(1,1,1));
			}
			
			// XXX: Implement these other shapes as needed!
			/*
			else if(collisionShape.compare("btConeShape") == 0) {
				
			} else if(collisionShape.compare("btMultiSphereShape") == 0) {
				
			} else if(collisionShape.compare("btConvexHullShape") == 0) {
				
			} else if(collisionShape.compare("btConvexTriangleMeshShape") == 0) {
				
			} else if(collisionShape.compare("btCompoundShape") == 0) {
				
			}
			*/
			

			// create the rigid body

			// set position to 0,0,0 later change when placing in the game
			btDefaultMotionState* fallMotionState =
				new btDefaultMotionState( btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0, 0)));
			btScalar mass = (btScalar) massTemp;
			btVector3 fallInertia(0, 0, 0);
			colShape->calculateLocalInertia(mass, fallInertia);
				

			btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass, fallMotionState, colShape, fallInertia);
			fallRigidBodyCI.m_restitution = restitution;

			// Create the rigid body
			btRigidBody* tempRigidBody = new btRigidBody(fallRigidBodyCI);

			// New way
			DynamicObject *newD = new DynamicObject(meshNames, colShape, Ogre::Vector3(0,0,0), interaction, scale);

			// put it into the library
			dynamicObjects.emplace(name, newD);

			std::fclose(pFile);

			return newD->clone(this->mSceneManager);
		} else {
			// no file was found
			return NULL;
		}
	}
}