Exemplo n.º 1
0
void AvatarScalpel::init() {

	m_isSweptQuadValid = false;
	m_vSweptQuad.resize(4);
	m_edgeref0 = vec3f(-2.0, 0, 0);
	m_edgeref1 = vec3f(2.0, 0, 0);
	vec3f lo = vec3f(m_edgeref0.x, 0.0f, -0.001f);
	vec3f hi = vec3f(m_edgeref1.x, 1.0f, 0.001);

	//Geometry
	Geometry g;
	g.init(3, 4, 2, ftTriangles);
	g.addCube(lo, hi);
	g.addPerVertexColor(vec4f(0, 1, 0, 1), g.countVertices());
	SGMesh::setup(g);

	//Outline
	Geometry gWireframe;
	gWireframe.init(3, 4, 2, ftQuads);
	gWireframe.addCube(lo, hi);
	m_outline.setup(gWireframe);
	m_outline.setWireFrameMode(true);


	resetTransform();
	if(TheShaderManager::Instance().has("phong")) {
        m_spEffect = SmartPtrSGEffect(new SGEffect(TheShaderManager::Instance().get("phong")));
    }
}
Exemplo n.º 2
0
SGVoxels::SGVoxels(const vector<vec3f>& voxels, float side) {
	this->setName("voxels");

	Geometry g;
	g.init(3, 4, 2, ftQuads);

	vec3f sides(side);
	for(U32 i=0; i<voxels.size(); i++) {
		g.addCube(voxels[i], voxels[i] + side);
	}

	this->setup(g);
}
Exemplo n.º 3
0
int main(int argc, char* argv[]) {
	cout << "Cutting tets" << endl;

	g_parser.add_option("input", "[filepath] set input file in vega format",
			Value(AnsiStr("internal")));
	g_parser.add_toggle("ringscalpel", "If the switch presents then the ring scalpel will be used");
	g_parser.add_option("example",
			"[one, two, cube, eggshell] set an internal example",
			Value(AnsiStr("two")));
	g_parser.add_option("gizmo",
			"loads a file to set gizmo location and orientation",
			Value(AnsiStr("gizmo.ini")));

	if (g_parser.parse(argc, argv) < 0)
		exit(0);

	//file path
	g_strFilePath = ExtractFilePath(GetExePath()) + g_parser.value<AnsiStr>("input");
	if (FileExists(g_strFilePath))
		LogInfoArg1("input file: %s.", g_strFilePath.cptr());
	else
		g_strFilePath = "";

	//Initialize app
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
	glutInitWindowSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
	glutCreateWindow("SoftRigidDynamics - Pourya Shirazian");
	glutDisplayFunc(draw);
	glutReshapeFunc(def_resize);
	glutMouseFunc(MousePress);
	glutPassiveMotionFunc(MousePassiveMove);
	glutMotionFunc(MouseMove);
	glutMouseWheelFunc(MouseWheel);
	glutKeyboardFunc(NormalKey);
	glutSpecialFunc(SpecialKey);
	glutCloseFunc(closeApp);
	glutIdleFunc(timestep);

	def_initgl();

	//Build Shaders for drawing the mesh
	AnsiStr strRoot = ExtractOneLevelUp(ExtractFilePath(GetExePath()));
	AnsiStr strShaderRoot = strRoot + "data/shaders/";
	AnsiStr strMeshRoot = strRoot + "data/meshes/";
	AnsiStr strTextureRoot = strRoot + "data/textures/";

	AnsiStr strLeftPial = strMeshRoot + "brain/pial_Full_obj/lh.pial.obj";
	AnsiStr strRightPial = strMeshRoot + "brain/pial_Full_obj/rh.pial.obj";

	//Load Shaders
	TheShaderManager::Instance().addFromFolder(strShaderRoot.cptr());

	//Load Textures
	TheTexManager::Instance().add(strTextureRoot + "wood.png");
	TheTexManager::Instance().add(strTextureRoot + "rendermask.png");
	TheTexManager::Instance().add(strTextureRoot + "maskalpha.png");
	TheTexManager::Instance().add(strTextureRoot + "maskalphafilled.png");
	TheTexManager::Instance().add(strTextureRoot + "spin.png");

	//Ground and Room
	//TheSceneGraph::Instance().addFloor(32, 32, 0.5f);
	TheSceneGraph::Instance().addSceneBox(AABB(vec3f(-10, -10, -16), vec3f(10, 10, 16)));


	//floor
	Geometry g;
	g.addCube(vec3f(-8, -2.0, -8), vec3f(8, -1.8, 8));
	g.addPerVertexColor(vec4f(0.5, 0.5, 0.5, 1));
	SGBulletRigidMesh* floor = new SGBulletRigidMesh();
	floor->setup(g, 0.0);
	floor->setName("floor");
	TheSceneGraph::Instance().addRigidBody(floor);


	//create rigid bodies
	/*
	Geometry g1;
	g1.addCube(vec3f(0.0, 0.0, 0.0), 1.0);
	g1.addPerVertexColor(vec4f(0, 0, 1, 1));

	for(int i=0; i < 8; i ++) {
		for(int j=0; j < 8; j++) {
			g1.colors().clear();

			float r = RandRangeT<float>(0.0, 1.0);
			float g = RandRangeT<float>(0.0, 1.0);
			float b = RandRangeT<float>(0.0, 1.0);

			g1.addPerVertexColor(vec4f(r, g, b, 1.0f));
			SGBulletRigidMesh* acube = new SGBulletRigidMesh();
			acube->transform()->setTranslate(vec3f(i-3, 10.0, j-3));
			acube->setup(g1, 1.0);
			TheSceneGraph::Instance().addRigidBody(acube);
		}
	}
	*/


	//Scalpel
	g_lpScalpel = new AvatarScalpel();
	g_lpRing = new AvatarRing(TheTexManager::Instance().get("spin"));
	TheSceneGraph::Instance().add(g_lpScalpel);
	TheSceneGraph::Instance().add(g_lpRing);

	if(g_parser.value<int>("ringscalpel")) {
		g_lpAvatar = g_lpRing;
		g_lpScalpel->setVisible(false);
	}
	else {
		g_lpAvatar = g_lpScalpel;
		g_lpRing->setVisible(false);
	}

	g_lpAvatar->setTissue(g_lpTissue);
	g_lpAvatar->setOnCutFinishedEventHandler(finishedcut);
	TheGizmoManager::Instance().setFocusedNode(g_lpAvatar);

	//load gizmo manager file
	AnsiStr strGizmoFP = g_parser.value<AnsiStr>("gizmo");
	TheGizmoManager::Instance().readConfig(strGizmoFP);


	resetMesh();

	//render mask
//	SGRenderMask* renderMask = new SGRenderMask(TheTexManager::Instance().get("maskalpha"));
//	renderMask->setName("rendermask");
//	TheSceneGraph::Instance().add(renderMask);

	glutMainLoop();

	return 0;
}