Exemplo n.º 1
0
void calglKeyboardEventWindow3D(unsigned char key, int x, int y){
	if(key=='t'){
		x -= window3D->sub_width/2;
		y -= window3D->sub_height/2;

		if(translationOn){
			yPos[activeSubWindow]+=-(y - key_old_y)*keyboardSensitivity;
			xPos[activeSubWindow]+=(x - key_old_x)*keyboardSensitivity;

			key_old_x = x;
			key_old_y = y;
		} else {
			activeSubWindow = glutGetWindow()-2;
			key_old_x = x;
			key_old_y = y;
			translationOn = CAL_TRUE;
		}
	}

	if(key=='h'){
		calglGetGlobalSettings()->onlyModel = !calglGetGlobalSettings()->onlyModel; 
	}

	if(key=='p'){
		if(window3D->models[0]->calUpdater){
			window3D->models[0]->calUpdater->active = !window3D->models[0]->calUpdater->active;
		}
	}

	calglRedisplayAllWindow3D();
}
Exemplo n.º 2
0
void calglTimeFunc3D(int value){
	glutTimerFunc(calglGetGlobalSettings()->refreshTime, calglTimeFunc3D, value);

	if (!calglGetGlobalSettings()->fixedDisplay){
		calglRedisplayAllWindow3D();
	}
}
Exemplo n.º 3
0
struct CALGLWindow3D* calglCreateWindow3D(int argc, char** argv, struct CALGLGlobalSettings* globalSettings, struct CALGLDrawModel3D** models, int size){
	struct CALGLWindow3D* window = (struct CALGLWindow3D*) malloc(sizeof(struct CALGLWindow3D));
	GLint i = 0;

	window->globalSettings = globalSettings;

	window->noModels = size;
	window->models = models;
	window->subWindowID = (GLuint*)malloc(sizeof(GLuint)*window->noModels);
	window->positionsX = (GLint*)malloc(sizeof(GLint)*window->noModels);
	window->positionsY = (GLint*)malloc(sizeof(GLint)*window->noModels);

	// Setting parameter for translate
	xPos = (GLfloat*)malloc(sizeof(GLfloat)*size);
	yPos = (GLfloat*)malloc(sizeof(GLfloat)*size);
	zPos = (GLfloat*)malloc(sizeof(GLfloat)*size);
	xRot = (GLfloat*)malloc(sizeof(GLfloat)*size);
	yRot = (GLfloat*)malloc(sizeof(GLfloat)*size);
	zRot = (GLfloat*)malloc(sizeof(GLfloat)*size);

	for (i = 0; i < window->noModels; i++){
		xPos[i] = 0.0f;	yPos[i] = 0.0f;	zPos[i] = 0.0f;
		xRot[i] = 0.0f; yRot[i] = 0.0f; zRot[i] = 0.0f;
	}

	glutInitWindowSize(window->globalSettings->width, window->globalSettings->height);
	glutInitWindowPosition(window->globalSettings->positionX, window->globalSettings->positionY);
	window->id = glutCreateWindow(window->globalSettings->applicationName);
	glutReshapeFunc(calglReshapeWindow3D);
	glutDisplayFunc(calglDisplayWindow3D);
	glutIdleFunc(calglIdleFuncWindow3D);
	glutTimerFunc(calglGetGlobalSettings()->refreshTime, calglTimeFunc3D, calglGetGlobalSettings()->refreshTime);

	calglCalculatePositionAndDimensionWindow3D(window);

	for (i = 0; i < window->noModels; i++){
		window->subWindowID[i] = glutCreateSubWindow(window->id, window->positionsX[i], window->positionsY[i], window->sub_width, window->sub_height);
		glutReshapeFunc(calglSubReshapeWindow3D);
		glutDisplayFunc(calglSubDisplayWindow3D);

		glutMouseFunc(calglMouseWindow3D);
		glutMotionFunc(calglMotionMouseWindow3D);
		glutKeyboardFunc(calglKeyboardEventWindow3D);
		glutKeyboardUpFunc(calglKeyboardUpEventWindow3D);
		glutSpecialFunc(calglSpecialKeyboardEventWindow3D);
	}

	window->font_style = GLUT_BITMAP_8_BY_13;

	if(orientation==CALGL_LAYOUT_ORIENTATION_UNKNOW)
		orientation = CALGL_LAYOUT_ORIENTATION_HORIZONTAL;

	window3D = window;
	return window;
}
Exemplo n.º 4
0
void calglKeyboardEventWindow3D(unsigned char key, int x, int y){
	int i = 0;

	if (key == 't'){
		x -= window3D->sub_width / 2;
		y -= window3D->sub_height / 2;

		if (translationOn){
			yPos[activeSubWindow] += -(y - key_old_y)*keyboardSensitivity;
			xPos[activeSubWindow] += (x - key_old_x)*keyboardSensitivity;

			key_old_x = x;
			key_old_y = y;
		}
		else {
			activeSubWindow = glutGetWindow() - 2;
			key_old_x = x;
			key_old_y = y;
			translationOn = CAL_TRUE;
		}
	}

	if (key == 'h'){
		calglGetGlobalSettings()->onlyModel = !calglGetGlobalSettings()->onlyModel;
	}

	if (key == 'x' || key == 's'){
		if (window3D->models[0]->calglRun){
			window3D->models[0]->calglRun->active = !window3D->models[0]->calglRun->active;
		}
	}

	if(key=='r') {
		for(i = 0; i < window3D->noModels; i++) {
			xPos[i] = 0.0f;	yPos[i] = 0.0f;	zPos[i] = 0.0f;
			xRot[i] = 90.0f; yRot[i] = 0.0f; zRot[i] = 0.0f;
		}
	}

	calglRedisplayAllWindow3D();
}
Exemplo n.º 5
0
struct CALGLModelViewParameter* calglAutoCreateModelViewParameterSurface2D(struct CALGLDrawModel2D* calDrawModel){
	struct CALGLModelViewParameter* modelView = (struct CALGLModelViewParameter*) malloc(sizeof(struct CALGLModelViewParameter));
	GLfloat max, min;
	GLfloat yTranslate = 0.0f;
	GLfloat heightDiff = 0.0f;

	if(calDrawModel->byteModel){
		calglComputeExtremesToAll2Db(calDrawModel, calDrawModel->byteModel);
		min = (GLfloat) calDrawModel->byteModel->min;
		max = (GLfloat) calDrawModel->byteModel->nodes[1]->max;
		heightDiff = max - min;
	}
	if(calDrawModel->intModel){
		calglComputeExtremesToAll2Di(calDrawModel, calDrawModel->intModel);
		min = (GLfloat) calDrawModel->intModel->min;
		max = (GLfloat) calDrawModel->intModel->nodes[1]->max;
		heightDiff = max - min;
	}
	if(calDrawModel->realModel){
		calglComputeExtremesToAll2Dr(calDrawModel, calDrawModel->realModel);
		min = (GLfloat) calDrawModel->realModel->min;
		max = (GLfloat) calDrawModel->realModel->nodes[1]->max;
		heightDiff = max - min;
	}


	if(min >= 0){
		yTranslate = -min-(heightDiff/2);
	} else if(max <= 0){
		yTranslate = max+(heightDiff/2);
	} else {
		if((-min) > max){
			yTranslate = ((-min)-max)/2.0f;
		} else if((-min) < max){
			yTranslate = -(max-(-min))/2.0f;
		}
	}

	//modelView = calglCreateModelViewParameter(
	//	(-calDrawModel->calModel->columns/2.0f) * calglGetGlobalSettings()->cellSize, yTranslate, (-calDrawModel->calModel->rows/2.0f)* calglGetGlobalSettings()->cellSize,
	//	0,0,0,
	//	1/(calDrawModel->calModel->columns/10.0f), 1/(heightDiff/10.0f), 1/(calDrawModel->calModel->rows/10.0f));

	modelView = calglCreateModelViewParameter(
		(-calDrawModel->calModel->columns/2.0f) * calglGetGlobalSettings()->cellSize, yTranslate, (-calDrawModel->calModel->rows/2.0f)* calglGetGlobalSettings()->cellSize,
		0, 0, 0,
		1/(calDrawModel->calModel->columns/1.0f), 1/(heightDiff/1.0f), 1/(calDrawModel->calModel->rows/1.0f));


	return modelView;
}
Exemplo n.º 6
0
int main(int argc, char** argv){
	calglSetApplicationNameGlobalSettings("3D life");
	calglSetRowsAndColumnsGlobalSettings(25, 25);
	calglSetStepGlobalSettings(4000);
	calglSetWindowDimensionGlobalSettings(400, 400);
	calglSetWindowPositionGlobalSettings(40, 40);

	struct CALDrawModel3D* drawModel;

	//cadef and rundef
	life3D = calCADef3D(calglGetGlobalSettings()->rows, calglGetGlobalSettings()->columns, LAYERS, CAL_MOORE_NEIGHBORHOOD_3D, CAL_SPACE_TOROIDAL, CAL_NO_OPT);
	life3Dsimulation = calRunDef3D(life3D, 1, CAL_RUN_LOOP, CAL_UPDATE_IMPLICIT);
	//add substates
	Q.life = calAddSubstate3Db(life3D);
	//add transition function's elementary processes
	calAddElementaryProcess3D(life3D, life3DTransitionFunction);
	
	//simulation run setup
	calRunAddInitFunc3D(life3Dsimulation, life3DSimulationInit);
	calRunInitSimulation3D(life3Dsimulation);	//It is required in the case the simulation main loop is explicitated; similarly for calRunFinalizeSimulation3D
	calRunAddStopConditionFunc3D(life3Dsimulation, life3DSimulationStopCondition);

	//drawModel definition
	drawModel = calglDefDrawModel3D(CALGL_DRAW_MODE_FLAT, "Life", life3D, life3Dsimulation);
	calglAddToDrawModel3Db(drawModel, NULL, &Q.life, CALGL_TYPE_INFO_VERTEX_DATA, CALGL_TYPE_INFO_USE_DEFAULT, CALGL_DATA_TYPE_DYNAMIC);
	calglColor3D(drawModel, 0.5f, 0.5f, 0.5f, 1.0f);
	calglAddToDrawModel3Db(drawModel, Q.life, &Q.life, CALGL_TYPE_INFO_COLOR_DATA, CALGL_TYPE_INFO_USE_CONST_VALUE, CALGL_DATA_TYPE_DYNAMIC);
	calglAddToDrawModel3Db(drawModel, Q.life, &Q.life, CALGL_TYPE_INFO_NORMAL_DATA, CALGL_TYPE_INFO_USE_DEFAULT, CALGL_DATA_TYPE_DYNAMIC); 
	calglStartProcessWindow3D(argc, argv);

	//finalizations
	calRunFinalize3D(life3Dsimulation);
	calFinalize3D(life3D);

	calglDestroyGlobalSettings();
	calglCleanDrawModelList3D();
	return 0;
}
Exemplo n.º 7
0
void calglMainLoop3D(int argc, char** argv) {
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);

	glClearColor(0.5f, 0.5f, 1.0f, 1.0f);
	glShadeModel(GL_SMOOTH);
	glEnable(GL_DEPTH_TEST);

	calglCreateWindow3D(argc, argv, calglGetGlobalSettings(), models3D, noModels3D);

	calglPrintfInfoCommand3D();

	calglRedisplayAllWindow3D();

	glutMainLoop();

	calglDestroyWindow3D(window3D);
}
Exemplo n.º 8
0
void calglDisplayBar3D(struct CALGLInfoBar* infoBar){
	static GLfloat minimumDistanceX = 0;
	static GLfloat minimumDistanceY = 0;
	static GLint sub_width;
	static GLint sub_height;
	static GLfloat smallDimension = 5.0f;
	static GLfloat normalDimension = 10.0f;
	GLint i = 0;
	GLfloat internalDistance = 0.0f;

	if (calglGetGlobalSettings()->onlyModel){
		return;
	}

	if (infoBar->dimension == CALGL_INFO_BAR_DIMENSION_RELATIVE){
#pragma region InfoBarRelativeDrawing
		sub_width = window3D->sub_width;
		sub_height = window3D->sub_height;

		minimumDistanceX = (0.1f)*sub_width;
		minimumDistanceY = (0.1f)*sub_height;

		glPushAttrib(GL_LIGHTING_BIT); {
			glDisable(GL_LIGHTING);

			glPushMatrix(); {
				glDepthMask(GL_FALSE);
				glDisable(GL_DEPTH_TEST);

				glMatrixMode(GL_PROJECTION);
				glLoadIdentity();

				gluOrtho2D(0, sub_width, 0, sub_height); //left,right,bottom,top
				glMatrixMode(GL_MODELVIEW);
				glLoadIdentity();

				if (infoBar->height >= infoBar->width){ // h >= w
					infoBar->xPosition = sub_width - minimumDistanceX - infoBar->width;
					infoBar->yPosition = sub_height - minimumDistanceY;

					glBegin(GL_QUADS); {
						switch (infoBar->infoUse){
						case CALGL_TYPE_INFO_USE_GRAY_SCALE:
							glColor3f(1.0f, 1.0f, 1.0f);
							break;
						case CALGL_TYPE_INFO_USE_RED_SCALE:
							glColor3f(1.0f, 1.0f, 0.0f);
							break;
						case CALGL_TYPE_INFO_USE_GREEN_SCALE:
							glColor3f(0.0f, 1.0f, 0.0f);
							break;
						case CALGL_TYPE_INFO_USE_BLUE_SCALE:
							glColor3f(0.0f, 0.0f, 1.0f);
							break;
						default:
							glColor3f(1.0f, 1.0f, 1.0f);
							break;
						}
						glVertex2f(infoBar->xPosition + infoBar->width, infoBar->yPosition);
						glVertex2f(infoBar->xPosition, infoBar->yPosition);

						switch (infoBar->infoUse){
						case CALGL_TYPE_INFO_USE_RED_SCALE:
							glColor3f(1.0f, 0.0f, 0.0f);
							break;
						default:
							glColor3f(0.0f, 0.0f, 0.0f);
							break;
						}
						glVertex2f(infoBar->xPosition, infoBar->yPosition - infoBar->height);
						glVertex2f(infoBar->xPosition + infoBar->width, infoBar->yPosition - infoBar->height);
					}glEnd();

					glColor3f(1.0f, 1.0f, 1.0f);
					calglPrintString3D(infoBar->xPosition + infoBar->width + normalDimension * 3, infoBar->yPosition, calglGetString3D(*infoBar->max));
					calglPrintString3D(infoBar->xPosition + infoBar->width + normalDimension * 3, infoBar->yPosition - infoBar->height, calglGetString3D(*infoBar->min));

					internalDistance = infoBar->height / 10.0f;

					for (i = 0; i < 11; i++){
						glBegin(GL_LINES); {
							if (i % 5 == 0){
								glVertex2f(infoBar->xPosition + infoBar->width, infoBar->yPosition - i*internalDistance);
								glVertex2f(infoBar->xPosition + infoBar->width + normalDimension * 2, infoBar->yPosition - i*internalDistance);
							}
							else {
								glVertex2f(infoBar->xPosition + infoBar->width, infoBar->yPosition - i*internalDistance);
								glVertex2f(infoBar->xPosition + infoBar->width + smallDimension * 2, infoBar->yPosition - i*internalDistance);
							}
						} glEnd();
					}
				}
				else { // w > h
					infoBar->xPosition = minimumDistanceX;
					infoBar->yPosition = minimumDistanceY + infoBar->height;

					glBegin(GL_QUADS); {
						switch (infoBar->infoUse){
						case CALGL_TYPE_INFO_USE_RED_SCALE:
							glColor3f(1.0f, 0.0f, 0.0f);
							break;
						default:
							glColor3f(0.0f, 0.0f, 0.0f);
							break;
						}
						glVertex2f(infoBar->xPosition, infoBar->yPosition);
						glVertex2f(infoBar->xPosition, infoBar->yPosition - infoBar->height);

						switch (infoBar->infoUse){
						case CALGL_TYPE_INFO_USE_GRAY_SCALE:
							glColor3f(1.0f, 1.0f, 1.0f);
							break;
						case CALGL_TYPE_INFO_USE_RED_SCALE:
							glColor3f(1.0f, 1.0f, 0.0f);
							break;
						case CALGL_TYPE_INFO_USE_GREEN_SCALE:
							glColor3f(0.0f, 1.0f, 0.0f);
							break;
						case CALGL_TYPE_INFO_USE_BLUE_SCALE:
							glColor3f(0.0f, 0.0f, 1.0f);
							break;
						default:
							glColor3f(1.0f, 1.0f, 1.0f);
							break;
						}
						glVertex2f(infoBar->xPosition + infoBar->width, infoBar->yPosition - infoBar->height);
						glVertex2f(infoBar->xPosition + infoBar->width, infoBar->yPosition);
					}glEnd();

					glColor3f(1.0f, 1.0f, 1.0f);
					calglPrintString3D(infoBar->xPosition + infoBar->width, infoBar->yPosition - infoBar->height - normalDimension * 3, calglGetString3D(*infoBar->max));
					calglPrintString3D(infoBar->xPosition, infoBar->yPosition - infoBar->height - normalDimension * 3, calglGetString3D(*infoBar->min));

					internalDistance = infoBar->width / 10.0f;

					for (i = 0; i < 11; i++){
						glBegin(GL_LINES); {
							if (i % 5 == 0){
								glVertex2f(infoBar->xPosition + i*internalDistance, infoBar->yPosition - infoBar->height);
								glVertex2f(infoBar->xPosition + i*internalDistance, infoBar->yPosition - infoBar->height - normalDimension * 2);
							}
							else {
								glVertex2f(infoBar->xPosition + i*internalDistance, infoBar->yPosition - infoBar->height);
								glVertex2f(infoBar->xPosition + i*internalDistance, infoBar->yPosition - infoBar->height - smallDimension * 2);
							}
						} glEnd();
					}
				}

				// Print name
				glColor3f(1.0f, 1.0f, 1.0f);
				calglPrintConstString3D(infoBar->xPosition, infoBar->yPosition + 21, infoBar->substateName);

				glDepthMask(GL_TRUE);
			}glPopMatrix();
		}glPopAttrib();
#pragma endregion
	}
	else if (infoBar->dimension == CALGL_INFO_BAR_DIMENSION_ABSOLUTE){
#pragma region InfoBarAbsoluteDrawing
		sub_width = window3D->sub_width;
		sub_height = window3D->sub_height;

		minimumDistanceX = (0.1f)*sub_width;
		minimumDistanceY = (0.1f)*sub_height;

		glPushAttrib(GL_LIGHTING_BIT); {
			glDisable(GL_LIGHTING);

			glPushMatrix(); {
				glDepthMask(GL_FALSE);
				glDisable(GL_DEPTH_TEST);

				glMatrixMode(GL_PROJECTION);
				glLoadIdentity();

				gluOrtho2D(0, sub_width, 0, sub_height); //left,right,bottom,top
				glMatrixMode(GL_MODELVIEW);
				glLoadIdentity();

				if (infoBar->height >= infoBar->width){ // h >= w
					glBegin(GL_QUADS); {
						switch (infoBar->infoUse){
						case CALGL_TYPE_INFO_USE_GRAY_SCALE:
							glColor3f(1.0f, 1.0f, 1.0f);
							break;
						case CALGL_TYPE_INFO_USE_RED_SCALE:
							glColor3f(1.0f, 1.0f, 0.0f);
							break;
						case CALGL_TYPE_INFO_USE_GREEN_SCALE:
							glColor3f(0.0f, 1.0f, 0.0f);
							break;
						case CALGL_TYPE_INFO_USE_BLUE_SCALE:
							glColor3f(0.0f, 0.0f, 1.0f);
							break;
						default:
							glColor3f(1.0f, 1.0f, 1.0f);
							break;
						}
						glVertex2f(infoBar->xPosition + infoBar->width, infoBar->yPosition);
						glVertex2f(infoBar->xPosition, infoBar->yPosition);

						switch (infoBar->infoUse){
						case CALGL_TYPE_INFO_USE_RED_SCALE:
							glColor3f(1.0f, 0.0f, 0.0f);
							break;
						default:
							glColor3f(0.0f, 0.0f, 0.0f);
							break;
						}
						glVertex2f(infoBar->xPosition, infoBar->yPosition - infoBar->height);
						glVertex2f(infoBar->xPosition + infoBar->width, infoBar->yPosition - infoBar->height);
					}glEnd();

					glColor3f(1.0f, 1.0f, 1.0f);
					calglPrintString3D(infoBar->xPosition + infoBar->width + normalDimension * 3, infoBar->yPosition, calglGetString3D(*infoBar->max));
					calglPrintString3D(infoBar->xPosition + infoBar->width + normalDimension * 3, infoBar->yPosition - infoBar->height, calglGetString3D(*infoBar->min));

					internalDistance = infoBar->height / 10.0f;

					for (i = 0; i < 11; i++){
						glBegin(GL_LINES); {
							if (i % 5 == 0){
								glVertex2f(infoBar->xPosition + infoBar->width, infoBar->yPosition - i*internalDistance);
								glVertex2f(infoBar->xPosition + infoBar->width + normalDimension * 2, infoBar->yPosition - i*internalDistance);
							}
							else {
								glVertex2f(infoBar->xPosition + infoBar->width, infoBar->yPosition - i*internalDistance);
								glVertex2f(infoBar->xPosition + infoBar->width + smallDimension * 2, infoBar->yPosition - i*internalDistance);
							}
						} glEnd();
					}
				}
				else { // w > h
					glBegin(GL_QUADS); {
						switch (infoBar->infoUse){
						case CALGL_TYPE_INFO_USE_RED_SCALE:
							glColor3f(1.0f, 0.0f, 0.0f);
							break;
						default:
							glColor3f(0.0f, 0.0f, 0.0f);
							break;
						}
						glVertex2f(infoBar->xPosition, infoBar->yPosition);
						glVertex2f(infoBar->xPosition, infoBar->yPosition - infoBar->height);

						switch (infoBar->infoUse){
						case CALGL_TYPE_INFO_USE_GRAY_SCALE:
							glColor3f(1.0f, 1.0f, 1.0f);
							break;
						case CALGL_TYPE_INFO_USE_RED_SCALE:
							glColor3f(1.0f, 1.0f, 0.0f);
							break;
						case CALGL_TYPE_INFO_USE_GREEN_SCALE:
							glColor3f(0.0f, 1.0f, 0.0f);
							break;
						case CALGL_TYPE_INFO_USE_BLUE_SCALE:
							glColor3f(0.0f, 0.0f, 1.0f);
							break;
						default:
							glColor3f(1.0f, 1.0f, 1.0f);
							break;
						}
						glVertex2f(infoBar->xPosition + infoBar->width, infoBar->yPosition - infoBar->height);
						glVertex2f(infoBar->xPosition + infoBar->width, infoBar->yPosition);
					}glEnd();

					glColor3f(1.0f, 1.0f, 1.0f);
					calglPrintString3D(infoBar->xPosition + infoBar->width, infoBar->yPosition - infoBar->height - normalDimension * 3, calglGetString3D(*infoBar->max));
					calglPrintString3D(infoBar->xPosition, infoBar->yPosition - infoBar->height - normalDimension * 3, calglGetString3D(*infoBar->min));

					internalDistance = infoBar->width / 10.0f;

					for (i = 0; i < 11; i++){
						glBegin(GL_LINES); {
							if (i % 5 == 0){
								glVertex2f(infoBar->xPosition + i*internalDistance, infoBar->yPosition - infoBar->height);
								glVertex2f(infoBar->xPosition + i*internalDistance, infoBar->yPosition - infoBar->height - normalDimension * 2);
							}
							else {
								glVertex2f(infoBar->xPosition + i*internalDistance, infoBar->yPosition - infoBar->height);
								glVertex2f(infoBar->xPosition + i*internalDistance, infoBar->yPosition - infoBar->height - smallDimension * 2);
							}
						} glEnd();
					}
				}

				// Print name
				glColor3f(1.0f, 1.0f, 1.0f);
				calglPrintConstString3D(infoBar->xPosition, infoBar->yPosition + 21, infoBar->substateName);

				glDepthMask(GL_TRUE);
			}glPopMatrix();
		}glPopAttrib();
#pragma endregion
	}

	calglSubReshapeWindow3D(sub_width, sub_height);
}
Exemplo n.º 9
0
void calglIdleFuncWindow3D(void){
	if (calglGetGlobalSettings()->fixedDisplay && window3D->models[0]->calglRun->step%calglGetGlobalSettings()->fixedStep == 0){
		calglRedisplayAllWindow3D();
	}
}