Пример #1
0
bool idCameraDef::getCameraInfo(long time, idVec3_t &origin, idVec3_t &direction, float *fv) {


	if ((time - startTime) / 1000 > totalTime) {
		return false;
	}


	for (int i = 0; i < events.Num(); i++) {
		if (time >= startTime + events[i]->getTime() && !events[i]->getTriggered()) {
			events[i]->setTriggered(true);
			if (events[i]->getType() == idCameraEvent::EVENT_TARGET) {
				setActiveTargetByName(events[i]->getParam());
				getActiveTarget()->start(startTime + events[i]->getTime());
				//Com_Printf("Triggered event switch to target: %s\n",events[i]->getParam());
			} else if (events[i]->getType() == idCameraEvent::EVENT_TRIGGER) {
				//idEntity *ent = NULL;
				//ent = level.FindTarget( ent, events[i]->getParam());
				//if (ent) {
				//	ent->signal( SIG_TRIGGER );
				//	ent->ProcessEvent( &EV_Activate, world );
				//}
			} else if (events[i]->getType() == idCameraEvent::EVENT_FOV) {
				//*fv = fov = atof(events[i]->getParam());
			} else if (events[i]->getType() == idCameraEvent::EVENT_STOP) {
				return false;
			}
		}
	}

	origin = *cameraPosition->getPosition(time);
	
	*fv = fov.getFOV(time);

	idVec3_t temp = origin;

	int numTargets = targetPositions.Num();
	if (numTargets == 0) {
/*
		// follow the path
		if (cameraSpline.getActiveSegment() < count - 1) {
			temp = *cameraSpline.splinePoints[cameraSpline.getActiveSegment()+1];
			if (temp == origin) {
				int index = cameraSpline.getActiveSegment() + 2;
				while (temp == origin && index < count - 1) {
					temp = *cameraSpline.splinePoints[index++];
				}
			}
		}
*/
	} else {
		temp = *getActiveTarget()->getPosition(time);
	}
	
	temp -= origin;
	temp.Normalize();
	direction = temp;

	return true;
}
Пример #2
0
/*
================
idCameraDef::getCameraInfo
================
*/
bool idCameraDef::getCameraInfo(long time, idVec3 &origin, idVec3 &direction, float *fv) {
	char	buff[ 1024 ];
	int		i;

	if ((time - startTime) / 1000 <= totalTime) {

		for( i = 0; i < events.Num(); i++ ) {
			if (time >= startTime + events[i]->getTime() && !events[i]->getTriggered()) {
				events[i]->setTriggered(true);
				if (events[i]->getType() == idCameraEvent::EVENT_TARGET) {
					setActiveTargetByName(events[i]->getParam());
					getActiveTarget()->start(startTime + events[i]->getTime());
					//common->Printf("Triggered event switch to target: %s\n",events[i]->getParam());
				} else if (events[i]->getType() == idCameraEvent::EVENT_TRIGGER) {
#if 0
//FIXME: seperate game and editor spline code
					idEntity *ent;
					ent = gameLocal.FindEntity( events[i]->getParam() );
					if (ent) {
						ent->Signal( SIG_TRIGGER );
						ent->ProcessEvent( &EV_Activate, gameLocal.world );
					}
#endif
				} else if (events[i]->getType() == idCameraEvent::EVENT_FOV) {
					memset(buff, 0, sizeof(buff));
					strcpy(buff, events[i]->getParam());
					const char *param1 = strtok(buff, " \t,\0");
					const char *param2 = strtok(NULL, " \t,\0");
					fov.reset(fov.GetFOV(time), atof(param1), time, atoi(param2)); 
					//*fv = fov = atof(events[i]->getParam());
				} else if (events[i]->getType() == idCameraEvent::EVENT_CAMERA) {
				} else if (events[i]->getType() == idCameraEvent::EVENT_STOP) {
					return false;
				}
			}
		}
	} else {
	}

	origin = *cameraPosition->getPosition(time);
	
	*fv = fov.GetFOV(time);

	idVec3 temp = origin;

	int numTargets = targetPositions.Num();
	if (numTargets == 0) {
/*
		// follow the path
		if (cameraSpline.getActiveSegment() < count - 1) {
			temp = *cameraSpline.splinePoints[cameraSpline.getActiveSegment()+1];
			if (temp == origin) {
				int index = cameraSpline.getActiveSegment() + 2;
				while (temp == origin && index < count - 1) {
					temp = *cameraSpline.splinePoints[index++];
				}
			}
		}
*/
	} else {
		temp = *getActiveTarget()->getPosition(time);
	}
	
	temp -= origin;
	temp.Normalize();
	direction = temp;

	return true;
}
Пример #3
0
void idCameraDef::buildCamera() {
	int i;
	int lastSwitch = 0;
	idList<float> waits;
	idList<int> targets;

	totalTime = baseTime;
	cameraPosition->setTime(totalTime * 1000);
	// we have a base time layout for the path and the target path
	// now we need to layer on any wait or speed changes
	for (i = 0; i < events.Num(); i++) {
		idCameraEvent *ev = events[i];
		events[i]->setTriggered(false);
		switch (events[i]->getType()) {
			case idCameraEvent::EVENT_TARGET : {
				targets.Append(i);
				break;
			}
			case idCameraEvent::EVENT_FEATHER : {
				long startTime = 0;
				float speed = 0;
				long loopTime = 10;
				float stepGoal = cameraPosition->getBaseVelocity() / (1000 / loopTime);
				while (startTime <= 1000) {
					cameraPosition->addVelocity(startTime, loopTime, speed);
					speed += stepGoal;
					if (speed > cameraPosition->getBaseVelocity()) {
						speed = cameraPosition->getBaseVelocity();
					}
					startTime += loopTime;
				}

				startTime = totalTime * 1000 - 1000;
				long endTime = startTime + 1000;
				speed = cameraPosition->getBaseVelocity();
				while (startTime < endTime) {
					speed -= stepGoal;
					if (speed < 0) {
						speed = 0;
					}
					cameraPosition->addVelocity(startTime, loopTime, speed);
					startTime += loopTime;
				}
				break;

			}
			case idCameraEvent::EVENT_WAIT : {
				waits.Append(atof(events[i]->getParam()));

				//FIXME: this is quite hacky for Wolf E3, accel and decel needs
				// do be parameter based etc.. 
				long startTime = events[i]->getTime() - 1000;
				if (startTime < 0) {
					startTime = 0;
				}
				float speed = cameraPosition->getBaseVelocity();
				long loopTime = 10;
				float steps = speed / ((events[i]->getTime() - startTime) / loopTime);
				while (startTime <= events[i]->getTime() - loopTime) {
					cameraPosition->addVelocity(startTime, loopTime, speed);
					speed -= steps;
					startTime += loopTime;
				}
				cameraPosition->addVelocity(events[i]->getTime(), atof(events[i]->getParam()) * 1000, 0);

				startTime = events[i]->getTime() + atof(events[i]->getParam()) * 1000;
				long endTime = startTime + 1000;
				speed = 0;
				while (startTime <= endTime) {
					cameraPosition->addVelocity(startTime, loopTime, speed);
					speed += steps;
					startTime += loopTime;
				}
				break;
			}
			case idCameraEvent::EVENT_TARGETWAIT : {
				//targetWaits.Append(i);
				break;
			}
			case idCameraEvent::EVENT_SPEED : {
/*
				// take the average delay between up to the next five segments
				float adjust = atof(events[i]->getParam());
				int index = events[i]->getSegment();
				total = 0;
				count = 0;

				// get total amount of time over the remainder of the segment
				for (j = index; j < cameraSpline.numSegments() - 1; j++) {
					total += cameraSpline.getSegmentTime(j + 1) - cameraSpline.getSegmentTime(j);
					count++;
				}

				// multiply that by the adjustment
				double newTotal = total * adjust;
				// what is the difference.. 
				newTotal -= total;
				totalTime += newTotal / 1000;

				// per segment difference
				newTotal /= count;
				int additive = newTotal;

				// now propogate that difference out to each segment
				for (j = index; j < cameraSpline.numSegments(); j++) {
					cameraSpline.addSegmentTime(j, additive);
					additive += newTotal;
				}
				break;
*/
			}
		}
	}


	for (i = 0; i < waits.Num(); i++) {
		totalTime += waits[i];
	}

	// on a new target switch, we need to take time to this point ( since last target switch ) 
	// and allocate it across the active target, then reset time to this point
	long timeSoFar = 0;
	long total = totalTime * 1000;
	for (i = 0; i < targets.Num(); i++) {
		long t;
		if (i < targets.Num() - 1) {
			t = events[targets[i+1]]->getTime();
		} else {
			t = total - timeSoFar;
		}
		// t is how much time to use for this target
		setActiveTargetByName(events[targets[i]]->getParam());
		getActiveTarget()->setTime(t);
		timeSoFar += t;
	}
}
Пример #4
0
bool idCameraDef::getCameraInfo(long time, idVec3 &origin, idVec3 &direction, float *fv)
{

	char buff[1024];

	if((time - startTime) / 1000 > totalTime)
	{
		return false;
	}


	for(int i = 0; i < events.Num(); i++)
	{
		if(time >= startTime + events[i]->getTime() && !events[i]->getTriggered())
		{
			events[i]->setTriggered(true);

			if(events[i]->getType() == idCameraEvent::EVENT_TARGET)
			{
				setActiveTargetByName(events[i]->getParam());
				getActiveTarget()->start(startTime + events[i]->getTime());
				//Com_Printf("Triggered event switch to target: %s\n",events[i]->getParam());
			}
			else if(events[i]->getType() == idCameraEvent::EVENT_TRIGGER)
			{
				// empty!
			}
			else if(events[i]->getType() == idCameraEvent::EVENT_FOV)
			{
				memset(buff, 0, sizeof(buff));
				strcpy(buff, events[i]->getParam());
				const char *param1 = strtok(buff, " \t,\0");
				const char *param2 = strtok(NULL, " \t,\0");
				float len = (param2) ? atof(param2) : 0;
				float newfov = (param1) ? atof(param1) : 90;
				fov.reset(fov.getFOV(time), newfov, time, len);
				//*fv = fov = atof(events[i]->getParam());
			}
			else if(events[i]->getType() == idCameraEvent::EVENT_FADEIN)
			{
				float time = atof(events[i]->getParam());
				Cbuf_AddText(va("fade 0 0 0 0 %f", time));
				Cbuf_Execute();
			}
			else if(events[i]->getType() == idCameraEvent::EVENT_FADEOUT)
			{
				float time = atof(events[i]->getParam());
				Cbuf_AddText(va("fade 0 0 0 255 %f", time));
				Cbuf_Execute();
			}
			else if(events[i]->getType() == idCameraEvent::EVENT_CAMERA)
			{
				memset(buff, 0, sizeof(buff));
				strcpy(buff, events[i]->getParam());
				const char *param1 = strtok(buff, " \t,\0");
				const char *param2 = strtok(NULL, " \t,\0");

				if(param2)
				{
					loadCamera(atoi(param1), va("cameras/%s.camera", param2));
					startCamera(time);
				}
				else
				{
					loadCamera(0, va("cameras/%s.camera", events[i]->getParam()));
					startCamera(time);
				}

				return true;
			}
			else if(events[i]->getType() == idCameraEvent::EVENT_STOP)
			{
				return false;
			}
		}
	}

	origin = *cameraPosition->getPosition(time);

	CHECK_NAN_VEC(origin);

	*fv = fov.getFOV(time);

	idVec3 temp = origin;

	int numTargets = targetPositions.Num();

	if(numTargets == 0)
	{
		// empty!
	}
	else
	{
		temp = *getActiveTarget()->getPosition(time);
	}

	temp -= origin;
	temp.Normalize();
	direction = temp;

	return true;
}
Пример #5
0
void idCameraDef::buildCamera() {
	int i;
	//int lastSwitch = 0;
	idList<float> waits;
	idList<int> targets;

	totalTime = baseTime;
	cameraPosition->setTime(totalTime * 1000);
	// we have a base time layout for the path and the target path
	// now we need to layer on any wait or speed changes
	for (i = 0; i < events.Num(); i++) {
		//idCameraEvent *ev = events[i];
		events[i]->setTriggered(false);
		switch (events[i]->getType()) {
			case idCameraEvent::EVENT_TARGET : {
				targets.Append(i);
				break;
			}
			case idCameraEvent::EVENT_WAIT : {
				waits.Append(atof(events[i]->getParam()));
				cameraPosition->addVelocity(events[i]->getTime(), atof(events[i]->getParam()) * 1000, 0);
				break;
			}
			case idCameraEvent::EVENT_TARGETWAIT : {
				//targetWaits.Append(i);
				break;
			}
			case idCameraEvent::EVENT_SPEED : {
/*
				// take the average delay between up to the next five segments
				float adjust = atof(events[i]->getParam());
				int index = events[i]->getSegment();
				total = 0;
				count = 0;

				// get total amount of time over the remainder of the segment
				for (j = index; j < cameraSpline.numSegments() - 1; j++) {
					total += cameraSpline.getSegmentTime(j + 1) - cameraSpline.getSegmentTime(j);
					count++;
				}

				// multiply that by the adjustment
				double newTotal = total * adjust;
				// what is the difference.. 
				newTotal -= total;
				totalTime += newTotal / 1000;

				// per segment difference
				newTotal /= count;
				int additive = newTotal;

				// now propogate that difference out to each segment
				for (j = index; j < cameraSpline.numSegments(); j++) {
					cameraSpline.addSegmentTime(j, additive);
					additive += newTotal;
				}
				break;
*/
			}
    default: break; // FIXME: what about other idCameraEvent?
		}
	}


	for (i = 0; i < waits.Num(); i++) {
		totalTime += waits[i];
	}

	// on a new target switch, we need to take time to this point ( since last target switch ) 
	// and allocate it across the active target, then reset time to this point
	long timeSoFar = 0;
	long total = (int)(totalTime * 1000);
	for (i = 0; i < targets.Num(); i++) {
		long t;
		if (i < targets.Num() - 1) {
			t = events[targets[i+1]]->getTime();
		} else {
			t = total - timeSoFar;
		}
		// t is how much time to use for this target
		setActiveTargetByName(events[targets[i]]->getParam());
		getActiveTarget()->setTime(t);
		timeSoFar += t;
	}

	
}
Пример #6
0
bool idCameraDef::getCameraInfo(long time, idVec3 &origin, idVec3 &direction, float *fv) {

	char buff[1024];

	if ((time - startTime) / 1000 > totalTime) {
		return false;
	}


	for (int i = 0; i < events.Num(); i++) {
		if (time >= startTime + events[i]->getTime() && !events[i]->getTriggered()) {
			events[i]->setTriggered(true);
			if (events[i]->getType() == idCameraEvent::EVENT_TARGET) {
				setActiveTargetByName(events[i]->getParam());
				getActiveTarget()->start(startTime + events[i]->getTime());
				//Com_Printf("Triggered event switch to target: %s\n",events[i]->getParam());
			} else if (events[i]->getType() == idCameraEvent::EVENT_TRIGGER) {
				//idEntity *ent = NULL;
				//ent = level.FindTarget( ent, events[i]->getParam());
				//if (ent) {
				//	ent->signal( SIG_TRIGGER );
				//	ent->ProcessEvent( &EV_Activate, world );
				//}
			} else if (events[i]->getType() == idCameraEvent::EVENT_FOV) {
				memset(buff, 0, sizeof(buff));
				strcpy(buff, events[i]->getParam());
				const char *param1 = strtok(buff, " \t,\0");
				const char *param2 = strtok(NULL, " \t,\0");
				float len = (param2) ? atof(param2) : 0;
				float newfov = (param1) ? atof(param1) : 90;
				fov.reset(fov.getFOV(time), newfov, time, len); 
				//*fv = fov = atof(events[i]->getParam());
			} else if (events[i]->getType() == idCameraEvent::EVENT_FADEIN) {
				float time = atof(events[i]->getParam());
				Cbuf_AddText(va("fade 0 0 0 0 %f", time));
				Cbuf_Execute();
			} else if (events[i]->getType() == idCameraEvent::EVENT_FADEOUT) {
				float time = atof(events[i]->getParam());
				Cbuf_AddText(va("fade 0 0 0 255 %f", time));
				Cbuf_Execute();
			} else if (events[i]->getType() == idCameraEvent::EVENT_CAMERA) {
				memset(buff, 0, sizeof(buff));
				strcpy(buff, events[i]->getParam());
				const char *param1 = strtok(buff, " \t,\0");
				const char *param2 = strtok(NULL, " \t,\0");

				if(param2) {
					loadCamera(atoi(param1), va("cameras/%s.camera", param2));
					startCamera(time);
				} else {
					loadCamera(0, va("cameras/%s.camera", events[i]->getParam()));
					startCamera(time);
				}
				return true;
			} else if (events[i]->getType() == idCameraEvent::EVENT_STOP) {
				return false;
			}
		}
	}

	origin = *cameraPosition->getPosition(time);
	
	*fv = fov.getFOV(time);

	idVec3 temp = origin;

	int numTargets = targetPositions.Num();
	if (numTargets == 0) {
/*
		// follow the path
		if (cameraSpline.getActiveSegment() < count - 1) {
			temp = *cameraSpline.splinePoints[cameraSpline.getActiveSegment()+1];
			if (temp == origin) {
				int index = cameraSpline.getActiveSegment() + 2;
				while (temp == origin && index < count - 1) {
					temp = *cameraSpline.splinePoints[index++];
				}
			}
		}
*/
	} else {
    if( getActiveTarget()->numPoints() > 0 ) {
		  temp = *getActiveTarget()->getPosition(time);
    }
	}
	
	temp -= origin;
	temp.Normalize();
	direction = temp;

	return true;
}