Skip to content

Commit 1652853

Browse files
committed
Camera position now changable
1 parent 9cf3b83 commit 1652853

9 files changed

+502
-448
lines changed

SphWaterfall/SphWaterfall/src/cui/CUI.cpp

+42-7
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ void CUI::cleanAndExecuteCommand(bool is_config_execution, bool& exit_program) {
127127
}
128128
else if (command == "render")
129129
{
130-
current_command.setCommand(CUICommand::RENDER);
131-
command_handler.handleCUICommand(current_command);
130+
if (cleanRender()) {
131+
current_command.setCommand(CUICommand::RENDER);
132+
command_handler.handleCUICommand(current_command);
133+
}
132134
printInputMessage();
133135
}
134136
else if (command == "loadconfig")
@@ -216,8 +218,8 @@ void CUI::showHelp() {
216218
<< " simulate -t" << endl
217219
<< " start a sph simulation, time can be set with '-t' parameter." << endl << endl
218220

219-
<< " render" << endl
220-
<< " start the rendering process." << endl << endl
221+
<< " render -v" << endl
222+
<< " start the rendering process, the camera can be set with '-v' parameter." << endl << endl
221223

222224
<< " addsource -v" << endl
223225
<< " add a water source at a given point." << endl << endl
@@ -298,7 +300,7 @@ bool CUI::cleanMoveShutter() {
298300
else {
299301
current_command.removeParameter(parameter);
300302
hasOnlyValidParameters = false;
301-
std::cout << "Missing path parameter '-t'" << std::endl;
303+
std::cout << "Missing time parameter '-t'" << std::endl;
302304
}
303305
}
304306

@@ -333,7 +335,7 @@ bool CUI::cleanAddSource() {
333335
else {
334336
current_command.removeParameter(parameter);
335337
hasOnlyValidParameters = false;
336-
std::cout << "Missing path parameter '-v'" << std::endl;
338+
std::cout << "Missing vector parameter '-v'" << std::endl;
337339
}
338340
}
339341

@@ -355,7 +357,7 @@ bool CUI::cleanAddSink() {
355357
{
356358
current_command.removeParameter(parameter);
357359
hasOnlyValidParameters = false;
358-
std::cout << "Missing path parameter '-h'" << std::endl;
360+
std::cout << "Missing height parameter '-h'" << std::endl;
359361
}
360362
}
361363

@@ -380,4 +382,37 @@ bool CUI::cleanSimulate() {
380382

381383
return hasOnlyValidParameters;
382384
}
385+
bool CUI::cleanRender()
386+
{
387+
bool hasOnlyValidParameters = true;
388+
389+
for (CUICommandParameter& parameter : current_command.getParameterList()) {
390+
if (parameter.getParameterName() == "-v") {
391+
std::string source_position = parameter.getValue();
392+
393+
if (source_position.find_first_not_of("+-,.0123456789 ") != std::string::npos)
394+
{
395+
std::cout << "'" << source_position << "' is not a valid input" << std::endl;
396+
hasOnlyValidParameters = false;
397+
}
398+
399+
int spaces = 0;
400+
for (char character : source_position) {
401+
if (character == ' ') {
402+
spaces++;
403+
}
404+
}
405+
406+
if (spaces != 2) {
407+
std::cout << "'" << source_position << "' is not a valid input" << std::endl;
408+
hasOnlyValidParameters = false;
409+
}
410+
}
411+
else {
412+
current_command.removeParameter(parameter);
413+
}
414+
}
415+
416+
return hasOnlyValidParameters;
417+
}
383418
/* -_-_-_Commands End_-_-_- */

SphWaterfall/SphWaterfall/src/cui/CUI.h

+1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ class CUI {
3535
bool cleanAddSource();
3636
bool cleanAddSink();
3737
bool cleanSimulate();
38+
bool cleanRender();
3839
};

SphWaterfall/SphWaterfall/src/cui/CommandHandler.cpp

+18-8
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ void CommandHandler::sendCommand(CUICommand& cui_command) {
137137
void CommandHandler::executeCommand(CUICommand& cui_command) {
138138
std::string file_path, time_for_move, source_position, sink_height;
139139
int simulation_timesteps;
140+
Vector3 camera_position = Vector3(0, 5, -5);
140141

141142
switch (cui_command.getCommand()) {
142143
case CUICommand::LOAD_MESH:
@@ -203,7 +204,11 @@ void CommandHandler::executeCommand(CUICommand& cui_command) {
203204
}
204205
break;
205206
case CUICommand::RENDER:
206-
render(loaded_mesh, loaded_shutter, 0);
207+
if (cui_command.hasParameter("-v")) {
208+
camera_position = parseToVector3(cui_command.getParameter(0).getValue());
209+
}
210+
211+
render(loaded_mesh, loaded_shutter, 0, camera_position);
207212
MPI_Barrier(MPI_COMM_WORLD);
208213

209214
// console feedback
@@ -326,27 +331,27 @@ void CommandHandler::simulate(int simulation_timesteps) {
326331
if (mpi_rank == 1) {
327332
std::vector<SphParticle> particles;
328333

329-
for (int i = 0; i < 20; i++) {
330-
for (int j = 0; j < 20; j++) {
331-
for (int k = 0; k < 20; k++) {
332-
particles.push_back(SphParticle(Vector3(3.0 + i, 3.0 + j, 3.0 + k)));
334+
/*for (int i = 0; i < 1; i++) {
335+
for (int j = 1; j < 2; j++) {
336+
for (int k = 0; k < 1; k++) {
337+
particles.push_back(SphParticle(Vector3(i, j, k)));
333338
}
334339
}
335-
}
340+
}*/
336341

337342
sph_manager.add_particles(particles);
338343
}
339344
sph_manager.simulate(simulation_timesteps);
340345
}
341346

342-
void CommandHandler::render(Terrain loaded_mesh, Terrain loaded_shutter, int shutter_time) {
347+
void CommandHandler::render(Terrain loaded_mesh, Terrain loaded_shutter, int shutter_time, Vector3 cameraPosition) {
343348
if (mpi_rank == 0) {
344349
cout << "Rendering in progress..." << endl;
345350
}
346351
VisualizationManager::importTerrain(loaded_mesh, false);
347352
VisualizationManager::importTerrain(loaded_shutter, true);
348353

349-
VisualizationManager::init(Vector3(10, 5, -20), 200, 200, 10*5);
354+
VisualizationManager::init(cameraPosition, 800, 600, 10*5);
350355
//VisualizationManager::renderFrames("sph.ptcl");
351356
VisualizationManager::renderFramesDistributed("sph.ptcl", mpi_rank);
352357

@@ -360,6 +365,11 @@ void CommandHandler::render(Terrain loaded_mesh, Terrain loaded_shutter, int shu
360365
void CommandHandler::addSource(std::string source_position_string) {
361366
Vector3 source_position = parseToVector3(source_position_string);
362367
//sph_manager.setSource(source_position);
368+
if (mpi_rank == 1) {
369+
std::vector<SphParticle> particles;
370+
particles.push_back(SphParticle(source_position));
371+
sph_manager.add_particles(particles);
372+
}
363373
std::cout << "New source: " << source_position << std::endl;
364374
}
365375

SphWaterfall/SphWaterfall/src/cui/CommandHandler.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class CommandHandler {
4040
void createExport(int simulation_timesteps);
4141
void moveShutter(std::string);
4242
void simulate(int simulation_timesteps);
43-
void render(Terrain, Terrain, int);
43+
void render(Terrain, Terrain, int, Vector3);
4444
void addSource(std::string);
4545
void addSink(std::string);
4646
};

SphWaterfall/SphWaterfall/src/visualization/VisualizationManager.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ void VisualizationManager::init(Vector3 cameraLocation, unsigned int frameWidth,
66
camera = Camera(cameraLocation, cameraDir.normalize(), frameWidth, frameHeight);
77
if (terrain.getVertexCount() > 0 && gate.getVertexCount() > 0) {
88
camera.renderGeometryFrames(terrain, gate);
9+
std::cout << "Terrain rendered" << std::endl;
10+
}
11+
else {
12+
std::cout << "No terrain found" << std::endl;
913
}
1014
initilaized = true;
1115
}
@@ -102,6 +106,7 @@ void VisualizationManager::renderFramesDistributed(string inputFileName, int ran
102106
Frame f = camera.renderFrame(frame, i);
103107

104108
writeFrameToBitmap(f, (("output/frame_" + std::to_string(i)) + ".bmp").c_str(), f.getWidth(), f.getHeight());
109+
std::cout << "Frame " << i+1 << "/" << frameCount << " finished on Processor " << rank << "." << std::endl;
105110
counter++;
106111
}
107112
}

SphWaterfall/SphWaterfall/src/visualization/util.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const int infoHeaderSize = 40;
1919

2020

2121
static Vector3 findRightSkalar(Vector3 vec, Vector3 right) {
22-
Vector3 left = Vector3(right.x * -1, right.y * -1, right.z * -1);
22+
Vector3 left = right * -1;
2323

2424
if (vec.x >= 0) {
2525
if ((vec.z > 0 && right.x < 0) || (vec.z < 0 && right.x > 0) || (vec.z == 0 && right.z > 0)) return left;

0 commit comments

Comments
 (0)