Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup spawn param target #163

Merged
merged 2 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 0 additions & 121 deletions source/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,127 +478,6 @@ void Session::endLogging() {
}
}

// Comment these since they are unused
/** Spawn a randomly parametrized target */
//void FPSciApp::spawnParameterizedRandomTarget(float motionDuration=4.0f, float motionDecisionPeriod=0.5f, float speed=2.0f, float radius=10.0f, float scale=2.0f) {
// Random& rng = Random::threadCommon();
//
// // Construct a reference frame
// // Remove the vertical component
// Vector3 Z = -activeCamera()->frame().lookVector();
// debugPrintf("lookatZ = [%.4f, %.4f, %.4f]\n", Z.x, Z.y, Z.z);
// debugPrintf("origin = [%.4f, %.4f, %.4f]\n", activeCamera()->frame().translation.x, activeCamera()->frame().translation.y, activeCamera()->frame().translation.z);
// Z.y = 0.0f;
// Z = Z.direction();
// Vector3 Y = Vector3::unitY();
// Vector3 X = Y.cross(Z);
//
// // Make a random vector in front of the player in a narrow field of view
// Vector3 dir = (-Z + X * rng.uniform(-1, 1) + Y * rng.uniform(-0.5f, 0.5f)).direction();
//
// // Ray from user/camera toward intended spawn location
// Ray ray = Ray::fromOriginAndDirection(activeCamera()->frame().translation, dir);
//
// //distance = rng.uniform(2.0f, distance - 1.0f);
// const shared_ptr<FlyingEntity>& target =
// spawnTarget(ray.origin() + ray.direction() * radius,
// scale, false,
// Color3::wheelRandom());
//
// // Choose some destination locations based on speed and motionDuration
// const Point3& center = ray.origin();
// Array<Point3> destinationArray;
// // [radians/s] = [m/s] / [m/radians]
// float angularSpeed = speed / radius;
// // [rad] = [rad/s] * [s]
// float angleChange = angularSpeed * motionDecisionPeriod;
//
// destinationArray.push(target->frame().translation);
// int tempInt = 0;
// for (float motionTime = 0.0f; motionTime < motionDuration; motionTime += motionDecisionPeriod) {
// // TODO: make angle change randomize correction, should be placed on circle around previous point
// float pitch = 0.0f;
// float yaw = tempInt++ % 2 == 0 ? angleChange : -angleChange;
// //float yaw = rng.uniform(-angleChange, angleChange);
// //float pitch = rng.uniform(-angleChange, angleChange);
// const Vector3& dir = CFrame::fromXYZYPRRadians(0.0f, 0.0f, 0.0f, yaw, pitch, 0.0f).rotation * ray.direction();
// ray.set(ray.origin(), dir);
// destinationArray.push(center + dir * radius);
// }
// target->setSpeed(speed); // m/s
// // debugging prints
// for (Point3* p = destinationArray.begin(); p != destinationArray.end(); ++p) {
// debugPrintf("[%.2f, %.2f, %.2f]\n", p->x, p->y, p->z);
// }
// target->setDestinations(destinationArray, center);
//}
//
///** Spawn a random non-parametrized target */
//void Session::spawnRandomTarget() {
// Random& rng = Random::threadCommon();
//
// bool done = false;
// int tries = 0;
//
// // Construct a reference frame
// // Remove the vertical component
// Vector3 Z = -activeCamera()->frame().lookVector();
// Z.y = 0.0f;
// Z = Z.direction();
// Vector3 Y = Vector3::unitY();
// Vector3 X = Y.cross(Z);
//
// do {
// // Make a random vector in front of the player in a narrow field of view
// Vector3 dir = (-Z + X * rng.uniform(-1, 1) + Y * rng.uniform(-0.3f, 0.5f)).direction();
//
// // Make sure the spawn location is visible
// Ray ray = Ray::fromOriginAndDirection(activeCamera()->frame().translation, dir);
// float distance = finf();
// scene()->intersect(ray, distance);
//
// if ((distance > 2.0f) && (distance < finf())) {
// distance = rng.uniform(2.0f, distance - 1.0f);
// const shared_ptr<FlyingEntity>& target =
// spawnTarget(ray.origin() + ray.direction() * distance,
// rng.uniform(0.1f, 1.5f), rng.uniform() > 0.5f,
// Color3::wheelRandom());
//
// // Choose some destination locations
// const Point3& center = ray.origin();
// Array<Point3> destinationArray;
// destinationArray.push(target->frame().translation);
// for (int i = 0; i < 20; ++i) {
// const Vector3& dir = (-Z + X * rng.uniform(-1, 1) + Y * rng.uniform(-0.3f, 0.5f)).direction();
// destinationArray.push(center + dir * distance);
// }
// target->setSpeed(2.0f); // m/s
// target->setDestinations(destinationArray, center);
//
// done = true;
// }
// ++tries;
// } while (!done && tries < 100);
//}

/** Spawn a flying entity target */
//shared_ptr<FlyingEntity> Session::spawnTarget(const Point3& position, float scale, bool spinLeft, const Color3& color, String modelName) {
// const int scaleIndex = clamp(iRound(log(scale) / log(1.0f + TARGET_MODEL_ARRAY_SCALING) + TARGET_MODEL_ARRAY_OFFSET), 0, m_modelScaleCount - 1);
// const shared_ptr<FlyingEntity>& target = FlyingEntity::create(format("target%03d", ++m_lastUniqueID), m_scene, m_targetModels[modelName][scaleIndex], CFrame());
// target->setFrame(position);
// target->setColor(color);
//
// // Don't set a track. We'll take care of the positioning after creation
// /*
// String animation = format("combine(orbit(0, %d), CFrame::fromXYZYPRDegrees(%f, %f, %f))", spinLeft ? 1 : -1, position.x, position.y, position.z);
// const shared_ptr<Entity::Track>& track = Entity::Track::create(target.get(), scene().get(), Any::parse(animation));
// target->setTrack(track);
// */
//
// insertTarget(target);
// return target;
//}

shared_ptr<TargetEntity> Session::spawnDestTarget(
shared_ptr<TargetConfig> config,
const Point3& position,
Expand Down
31 changes: 9 additions & 22 deletions source/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ struct PlayerAction {

class Session : public ReferenceCountedObject {
protected:
FPSciApp* m_app = nullptr; ///< Pointer to the app
FPSciApp* m_app = nullptr; ///< Pointer to the app
Scene* m_scene = nullptr; ///< Pointer to the scene

shared_ptr<SessionConfig> m_config; ///< The session this experiment will run
shared_ptr<FPSciLogger> m_logger; ///< Output results logger
shared_ptr<FPSciLogger> m_logger; ///< Output results logger
shared_ptr<PlayerEntity> m_player; ///< Player entity
shared_ptr<Camera> m_camera; ///< Camera entity

Expand All @@ -130,10 +130,10 @@ class Session : public ReferenceCountedObject {
int m_lastUniqueID = 0; ///< Counter for creating unique names for various entities
Array<shared_ptr<TargetEntity>> m_targetArray; ///< Array of drawn targets

int m_currTrialIdx; ///< Current trial
int m_currQuestionIdx = -1; ///< Current question index
Array<int> m_remainingTrials; ///< Completed flags
Array<Array<shared_ptr<TargetConfig>>> m_targetConfigs; ///< Target configurations by trial
int m_currTrialIdx; ///< Current trial
int m_currQuestionIdx = -1; ///< Current question index
Array<int> m_remainingTrials; ///< Completed flags
Array<Array<shared_ptr<TargetConfig>>> m_targetConfigs; ///< Target configurations by trial

// Time-based parameters
RealTime m_taskExecutionTime; ///< Task completion time for the most recent trial
Expand All @@ -160,23 +160,11 @@ class Session : public ReferenceCountedObject {
}

~Session(){
clearTargets(); // Clear the targets when the session is done
// Clear the targets when the session is done
clearTargets();
}

/** Creates a random target with motion based on parameters
@param motionDuration time in seconds to produce a motion path for
@param motionDecisionPeriod time in seconds when new motion direction is chosen
@param speed world-space velocity (m/s) of target
@param radius world-space distance to target
@param scale size of target TODO: is this radius or diameter in meters?*/
//void spawnParameterizedRandomTarget(float motionDuration, float motionDecisionPeriod, float speed, float radius, float scale);
/** Creates a random target in front of the player */
//void spawnRandomTarget();
/** Creates a spinning target */

//shared_ptr<FlyingEntity> spawnTarget(const Point3& position, float scale, bool spinLeft = true, const Color3& color = Color3::red(), String modelName = "model/target/target.obj");

/** Insert a target into the target array/scene */
/** Insert a target into the target array/scene */
inline void insertTarget(shared_ptr<TargetEntity> target);

shared_ptr<TargetEntity> spawnDestTarget(
Expand Down Expand Up @@ -245,7 +233,6 @@ class Session : public ReferenceCountedObject {
int remainingAmmo() const;

bool blockComplete() const;
bool complete() const;
void nextCondition();

void endLogging();
Expand Down