Ejemplo n.º 1
0
/*	Loads and parses material.
	Returns false on complete failure.
*/
Material_t *Material_Load(const char *ccPath)
{
	Material_t  *mNewMaterial;
	void        *cData;
	char		cPath[PLATFORM_MAX_PATH],
				cMaterialName[64] = { 0 };

	// Ensure that the given material names are correct!
	if (ccPath[0] == ' ')
		Sys_Error("Invalid material path! (%s)\n", ccPath);

	if (!material_initialized)
	{
		Con_Warning("Attempted to load material, before initialization! (%s)\n", ccPath);
		return NULL;
	}

	// Update the given path with the base path plus extension.
	sprintf(cPath, "%s%s.material", g_state.cMaterialPath, ccPath);

	// Check if it's been cached already...
	mNewMaterial = Material_GetByPath(cPath);
	if(mNewMaterial)
		return mNewMaterial;

	cData = COM_LoadHeapFile(cPath);
	if(!cData)
	{
		Con_Warning("Failed to load material! (%s) (%s)\n", cPath, ccPath);
		return NULL;
	}

	Script_StartTokenParsing((char*)cData);

	if(!Script_GetToken(true))
	{
		Con_Warning("Failed to get initial token! (%s) (%i)\n",ccPath,iScriptLine);
		return NULL;
	}
	else if (cToken[0] != '{')
	{
		if (!strcmp(cToken, "material_version"))
		{
			Script_GetToken(false);
		}
		else	// Probably a name...
		{
			// Copy over the given name.
			strncpy(cMaterialName, cToken, sizeof(cMaterialName));
			if (cMaterialName[0] == ' ')
				Sys_Error("Invalid material name!\n");

			// Check if it's been cached already...
			mNewMaterial = Material_GetByName(cMaterialName);
			if (mNewMaterial)
			{
				Con_Warning("Attempted to load duplicate material! (%s) (%s) vs (%s) (%s)\n",
					ccPath, cMaterialName,
					mNewMaterial->cPath, mNewMaterial->cName);

				free(cData);

				return mNewMaterial;
			}
		}

		Script_GetToken(true);

		if (cToken[0] != '{')
		{
			Con_Warning("Missing '{'! (%s) (%i)\n", ccPath, iScriptLine);

			goto MATERIAL_LOAD_ERROR;
		}
	}

	// Assume that the material hasn't been cached yet, so allocate a new copy of one.
	mNewMaterial = Material_Allocate();
	if (!mNewMaterial)
	{
		Con_Warning("Failed to allocate material! (%s)\n",ccPath);

		goto MATERIAL_LOAD_ERROR;
	}

	if (cMaterialName[0])
		strncpy(mNewMaterial->cName, cMaterialName, sizeof(mNewMaterial->cName));
	else
	{
		char cIn[PLATFORM_MAX_PATH];
		strncpy(cIn, ccPath, sizeof(cIn));

		// Otherwise just use the filename.
		ExtractFileBase(cIn, mNewMaterial->cName);
	}

	strncpy(mNewMaterial->cPath, ccPath, sizeof(mNewMaterial->cPath));

	for (;;)
	{
		if(!Script_GetToken(true))
		{
			Con_Warning("End of field without closing brace! (%s) (%i)\n",ccPath,iScriptLine);

			goto MATERIAL_LOAD_ERROR;
		}

		material_currentcontext = MATERIAL_FUNCTION_MATERIAL;

		// End
		if (cToken[0] == '}')
		{
			// TODO: Load material data at the END!

			return mNewMaterial;
		}
		// Start
		else if (cToken[0] == SCRIPT_SYMBOL_FUNCTION)
			Material_CheckFunctions(mNewMaterial);
	}

MATERIAL_LOAD_ERROR:
	free(cData);

	return NULL;
}
Ejemplo n.º 2
0
void State_ParkourController_Shoot(GObject* obj, State* state)
{
    //Get the members of the state
    struct State_ParkourController_Members* members = (struct State_ParkourController_Members*)state->members;

    //Get a reference to the camera
    Camera* cam = RenderingManager_GetRenderingBuffer()->camera;


    if(InputManager_GetInputBuffer().mouseLock)
    {
        //IF we can shoot again
        if(members->shootTimer >= members->shootCooldown)
        {
            //Get the forward vector of the camera
            Vector direction;
            Vector_INIT_ON_STACK(direction, 3);

            Matrix_SliceRow(&direction, cam->rotationMatrix, 2, 0, 3);
            Vector_Scale(&direction, -1.0f);

            //Create the bullet object
            GObject* bullet = GObject_Allocate();
            GObject_Initialize(bullet);

            //Set the appearance
            bullet->mesh = AssetManager_LookupMesh("Cube");
            //bullet->texture = AssetManager_LookupTexture("White");
            bullet->material = Material_Allocate();
            Material_Initialize(bullet->material, AssetManager_LookupTexture("Jacob"));
            //*Matrix_Index(bullet->material->colorMatrix, 1, 1) = 0.0f;
            //*Matrix_Index(bullet->material->colorMatrix, 2, 2) = 0.0f;

            //Create ridgid body
            bullet->body = RigidBody_Allocate();
            RigidBody_Initialize(bullet->body, bullet->frameOfReference, 1.0f);
            bullet->body->coefficientOfRestitution = 0.2f;
            bullet->body->rollingResistance = 0.2f;
            bullet->body->staticFriction = 0.4f;
            bullet->body->dynamicFriction = 0.2f;

            //Create collider
            bullet->collider = Collider_Allocate();
            ConvexHullCollider_Initialize(bullet->collider);
            ConvexHullCollider_MakeRectangularCollider(bullet->collider->data->convexHullData, 2.0f, 2.0f, 2.0f);

            //Position bullet
            Vector transform;
            Vector_INIT_ON_STACK(transform, 3);

            Vector_GetScalarProduct(&transform, &direction, 2.8243f);
            Vector_Increment(&transform, obj->frameOfReference->position);
            GObject_Translate(bullet, &transform);

            Vector_Copy(&transform, &Vector_ZERO);
            transform.components[2] = 1.0f;
            GObject_Rotate(bullet, &transform, 3.14159f);

            //Scale bullet
            Vector_Copy(&transform, &Vector_ZERO);
            transform.components[0] = transform.components[1] = transform.components[2] = 0.5f;
            GObject_Scale(bullet, &transform);

            //Apply impulse
            Vector_Scale(&direction, 25.0f);
            RigidBody_ApplyImpulse(bullet->body, &direction, &Vector_ZERO);

            //Add the remove state
            State* state = State_Allocate();
            State_Remove_Initialize(state, 7.0f);
            GObject_AddState(bullet, state);

            //Add the bullet to the world
            ObjectManager_AddObject(bullet);

            //Set shoot timer to 0
            members->shootTimer = 0.0f;
        }
    }
}
Ejemplo n.º 3
0
///
//Initializes the scene within the engine.
//This must be done after all engine components are initialized.
void InitializeScene(void)
{
	///
	//Camera controller simulation
	GObject* cam = GObject_Allocate();
	GObject_Initialize(cam);

	State* state = State_Allocate();

	cam->body = RigidBody_Allocate();
	RigidBody_Initialize(cam->body, cam->frameOfReference, 1.0f);
	cam->body->coefficientOfRestitution = 0.1f;


	cam->collider = Collider_Allocate();
	AABBCollider_Initialize(cam->collider, 2.5f, 3.0f, 2.5f, &Vector_ZERO);

	State_ParkourController_Initialize(state, 7.0f, 10.0f, 0.05f, 50.0f, 0.1f);

	GObject_AddState(cam,state);

	ObjectManager_AddObject(cam);

	//Create floor
	GObject* block = GObject_Allocate();
	GObject_Initialize(block);

	block->mesh = AssetManager_LookupMesh("Cube");

	block->collider = Collider_Allocate();
	AABBCollider_Initialize(block->collider, 2.0f, 2.0f, 2.0f, &Vector_ZERO);

	block->body = RigidBody_Allocate();
	RigidBody_Initialize(block->body, block->frameOfReference, 0.0f);
	block->body->freezeTranslation = block->body->freezeRotation = 1;
	block->body->dynamicFriction = block->body->staticFriction = 0.1f;
	block->body->rollingResistance = 0.25f;

	Vector v;
	Vector_INIT_ON_STACK(v, 3);
	v.components[0] = v.components[2] = 40.0f;
	v.components[1] = 1.0f;

	GObject_Scale(block, &v);

	Vector_Copy(&v, &Vector_ZERO);
	v.components[1] = -10.0f;

	GObject_Translate(block, &v);

	ObjectManager_AddObject(block);
	
	//Create sphere

	block = GObject_Allocate();
	GObject_Initialize(block);

	block->mesh = AssetManager_LookupMesh("Sphere");
	block->material = Material_Allocate();
	Material_Initialize(block->material, AssetManager_LookupTexture("Earth"));

	//*Matrix_Index(block->material->colorMatrix, 2, 2) = 0.0f;
	//*Matrix_Index(block->material->colorMatrix, 1, 1) = 0.0f;


	block->collider = Collider_Allocate();
	SphereCollider_Initialize(block->collider, 1.0f);

	block->body = RigidBody_Allocate();
	RigidBody_Initialize(block->body, block->frameOfReference, 0.0f);
	block->body->dynamicFriction = block->body->staticFriction = 1.0f;

	block->body->coefficientOfRestitution = 0.9f;

	Vector_Copy(&v, &Vector_ZERO);
	v.components[0] = -3.0f;
	v.components[1] = 5.0f;
	v.components[2] = -10.0f;

	GObject_Translate(block, &v);

	Vector_Copy(&v, &Vector_ZERO);
	v.components[0] = v.components[1] = v.components[2] = 10.0f;
	GObject_Scale(block, &v);
	
	ObjectManager_AddObject(block);
	
	
	
	//Set gravity
	
	Vector* gravity = Vector_Allocate();
	Vector_Initialize(gravity, 3);
	gravity->components[1] = -9.81f;
	
	PhysicsManager_AddGlobalAcceleration(gravity);	
}