Esempio n. 1
0
/*!
 Load \c float type value from file. The name of parameter is specified with
 \a lpKeyName. If the name matches the beginning of read line, the string
 after #DELIMITER will converted to \c float type value.
 @return If function fails, the return value is 0. When function fails, the
 value @ val is not overwritten. If function succeeds, the return value is 1.
 @param[in] fp Pointer to \c FILE structure.
 @param[in] lpKeyName The name of parameter.
 @param[out] val Pointer to \c float type value. Upon successful completion
 of this function, read value is copied to this variable.
 */
int16 LoadFloat(FILE *fp, const char *lpKeyName, AKFLOAT *val)
{
	char buf[64] = { '\0' };

	// ATTENTION! %ns should be modified according to the size of buf.
#ifdef AKEC_PRECISION_DOUBLE
	if (fscanf(fp, "%63s" DELIMITER "%lf", buf, val) != 2) {
#else
	if (fscanf(fp, "%63s" DELIMITER "%f", buf, val) != 2) {
#endif
		LOGE("%s: scanf error.", __FUNCTION__);
		return 0;
	}
	// Compare the read parameter name with given name.
	if (strncmp(buf, lpKeyName, sizeof(buf)) != 0) 
	{
		LOGE("%s: strncmp (%s) error.", __FUNCTION__, lpKeyName);
		return 0;
	}

	return 1;
}

/*!
 Load \c float type value from file and convert it to AKFVEC type
 structure. This function adds ".x", ".y" and ".z" to the last of parameter
 name and try to read value with combined name.
 @return If function fails, the return value is 0. When function fails, the
 output is undefined. If function succeeds, the return value is 1.
 @param[in] fp A opened \c FILE pointer.
 @param[in] lpKeyName The parameter name.
 @param[out] vec A pointer to AKFVEC structure. Upon successful completion
 of this function, read values are copied to this variable.
 */
int16 LoadFloatVec(FILE *fp, const char *lpKeyName, AKFVEC *vec)
{
	char keyName[64];
	int16 ret = 1;

	snprintf(keyName, sizeof(keyName), "%s.x", lpKeyName);
	ret = ret && LoadFloat(fp, keyName, &vec->u.x);

	snprintf(keyName, sizeof(keyName), "%s.y", lpKeyName);
	ret = ret && LoadFloat(fp, keyName, &vec->u.y);

	snprintf(keyName, sizeof(keyName), "%s.z", lpKeyName);
	ret = ret && LoadFloat(fp, keyName, &vec->u.z);

	return ret;
}
Esempio n. 2
0
Physics::Physics(ActorList const & actors, btIDebugDraw & debugger) : 
	actorList(actors), 
	debugger(debugger), 
	dispatcher(&collisionConfiguration), 
	dynamicsWorld(&dispatcher, &broadphase, &solver, &collisionConfiguration)
{	
		
	dynamicsWorld.setGravity(btVector3(0,LoadFloat("config/world.xml", "gravity"),0));   
	
	newActors(actors);
	
	/*turn on debugging*/
	#ifdef DEBUG_RENDERING
	debugger.setDebugMode(btIDebugDraw::DBG_DrawWireframe);
	dynamicsWorld.setDebugDrawer(&debugger);
	#endif
	
	// HeightMap * m = new HeightMap("esDc1.png");
	HeightMap const * m = HeightMapManager::GetHeightMap();
    btHeightfieldTerrainShape * heightfieldShape = new btHeightfieldTerrainShape(m->width, m->height,
					  m->map,
					  LoadFloat("config/world.xml","height_map_scale_y"),
					  -300, 300,
					  1, PHY_UCHAR, false);

	btTransform tr;
	tr.setIdentity();
	// tr.setOrigin(btVector3(-32*14, 0, -32*14));
	btVector3 localInertia(0,0,0);	
	
	heightfieldShape->setLocalScaling(btVector3(LoadFloat("config/world.xml","height_map_scale_x"), 1, LoadFloat("config/world.xml","height_map_scale_z")));

	btRigidBody* body = new btRigidBody(0,0,heightfieldShape,localInertia);	
	body->setWorldTransform(tr);

	dynamicsWorld.addRigidBody(body);
	

}
Esempio n. 3
0
/*!
 Load parameters from file which is specified with #CSPEC_SETTING_FILE.
 This function reads data from a beginning of the file line by line, and
 check parameter name sequentially. In otherword, this function depends on
 the order of eache parameter described in the file.
 @return If function fails, the return value is #DMT_FAIL. When function fails,
 the output is undefined. Therefore, parameters which are possibly overwritten
 by this function should be initialized again. If function succeeds, the
 return value is #DMT_SUCCESS.
 @param[out] prms A pointer to #AS9888PRMS structure. Loaded parameter is
 stored to the member of this structure.
 */
int16 LoadParameters(AS9888PRMS * prms)
{
	int16 ret;
	FILE *fp = NULL;

	//Open setting file for read.
	if ((fp = fopen(CSPEC_SETTING_FILE, "r")) == NULL) 
	{
		DMTERROR_STR("fopen");
		return DMT_FAIL;
	}

	ret = 1;

	/* Load data to HO */
	ret = ret && LoadFloatVec(fp, "HO", &prms->mfv_HO);
	/* Load FST_COMP */
	ret = ret && LoadFloat(fp, "t9eRt", &prms->m_cmp.t9eRt);
	ret = ret && LoadFloat(fp, "t9eLv", &prms->m_cmp.t9eLv);
	ret = ret && LoadFloatVec(fp, "kst", &prms->m_cmp.kst);
	ret = ret && LoadFloatVec(fp, "st", &prms->m_cmp.st);
	ret = ret && LoadFloatVec(fp, "kot", &prms->m_cmp.kot);
	ret = ret && LoadFloatVec(fp, "ot", &prms->m_cmp.ot);

	if (fclose(fp) != 0) 
	{
		DMTERROR_STR("fclose");
		ret = 0;
	}

	if (ret == 0) 
	{
		DMTERROR_STR(__FUNCTION__);
		return DMT_FAIL;
	}

	return DMT_SUCCESS;
}
Esempio n. 4
0
void AIInput::step(JeepActor* jeep, btVector3 const & pathDir1, btVector3 const & pathDir2, btVector3 const & trackVector, btVector3 const & segmentVec1, btVector3 const & segmentVec2) {
	btVector3 trackDirection = pathDir1;
	btVector3 actorHeading = quatRotate(jeep->orientation, btVector3(1,0,0)).normalize();

	AcceleratePressed = true;

	float angleToTrack = trackDirection.dot(actorHeading);
	float turnDir = trackDirection.cross(actorHeading).getY();
	if (turnDir > 0) turnDir = 1;
	else if (turnDir < 0) turnDir = -1;
	else turnDir = 0;

	int parallelize = 0;
	float parallelizationThreshold = LoadFloat("config/ai.xml","parallelization_threshold");
	float hardParallelizationThreshold = LoadFloat("config/ai.xml","hard_parallelization_threshold");
	if ((1.0 - angleToTrack) * turnDir > hardParallelizationThreshold) parallelize = 2;
	if ((1.0 - angleToTrack) * turnDir > parallelizationThreshold) parallelize = 1;
	else if ((1.0 - angleToTrack) * turnDir < -hardParallelizationThreshold) parallelize = -2;
	else if ((1.0 - angleToTrack) * turnDir < -parallelizationThreshold) parallelize = -1;

	int onTrack = 0;
	btVector3 pathVec = trackVector;
	float distFromTrack = pathVec.length();

	turnDir = trackDirection.cross(pathVec).getY();
	if (turnDir > 0) turnDir = 1;
	else if (turnDir < 0) turnDir = -1;
	else turnDir = 0;

	float distanceThreshold = LoadFloat("config/ai.xml","distance_threshold");
	float farDistanceThreshold = LoadFloat("config/ai.xml","far_distance_threshold");
	if (distFromTrack > farDistanceThreshold && turnDir > 0)  onTrack = 2;
	if (distFromTrack > distanceThreshold && turnDir > 0) onTrack = 1;
	else if (distFromTrack > farDistanceThreshold && turnDir < 0)  onTrack = -2;
	else if (distFromTrack > distanceThreshold && turnDir < 0) onTrack = -1;
	//std::cout << distFromTrack << std::endl;

	float distToNextSeg = segmentVec1.length();
	float distToNextSeg2 = segmentVec2.length();
	int turnAnticipation1 = 0;
	int turnAnticipation2 = 0;
	//std::cout << distToNextSeg << "\t" << distToNextSeg2 << std::endl;

	float turnAnticipationThreshold = LoadFloat("config/ai.xml","turn_anticipation_threshold");
	float farTurnAnticipationThreshold = LoadFloat("config/ai.xml","far_turn_anticipation_threshold");
	if (distToNextSeg < turnAnticipationThreshold) {
		trackDirection = pathDir1;
		angleToTrack = trackDirection.dot(actorHeading);
		turnDir = trackDirection.cross(actorHeading).getY();
		if (turnDir > 0) turnDir = 1;
		else if (turnDir < 0) turnDir = -1;
		else turnDir = 0;
		
		if ((1.0 - angleToTrack) * turnDir > 0.2) turnAnticipation1 = 2;
		else if ((1.0 - angleToTrack) * turnDir < -0.2) turnAnticipation1 = -2;
	}
	if (distToNextSeg2 < farTurnAnticipationThreshold) {
		trackDirection = pathDir2;
		angleToTrack = trackDirection.dot(actorHeading);
		turnDir = trackDirection.cross(actorHeading).getY();
		if (turnDir > 0) turnDir = 1;
		else if (turnDir < 0) turnDir = -1;
		else turnDir = 0;
		
		if ((1.0 - angleToTrack) * turnDir > 0.2) turnAnticipation2 = 1;
		else if ((1.0 - angleToTrack) * turnDir < -0.2) turnAnticipation2 = -1;
	}
	// std::cout << parallelize << " " << onTrack << " " << turnAnticipation1 << " " << turnAnticipation2 << std::endl;

	XAxis = parallelize + onTrack + turnAnticipation1 + turnAnticipation2;
	if (XAxis > 0) XAxis = 1;
	else if (XAxis < 0) XAxis = -1;
	else XAxis = 0;
}
void TerrainShader::LoadShineVariables(float shineDamper, float shine)
{
	LoadFloat(location_shineDamper, shineDamper);
	LoadFloat(location_shine, shine);
}
void TerrainShader::LoadLight(Light& light, float ambientLight)
{
	LoadVector(location_lightPosition, light.GetPosition());
	LoadVector(location_lightColor, light.GetColor());
	LoadFloat(location_ambientLight, ambientLight);
}