Пример #1
0
void PlaneMoon::init() {
//    Material * skyDomeMat = new Template("Texture", QList<string>() << "uv");

    QList<string> attributes = QList<string>() << "normal" << "uv";
    initMaterials("Atmo/Space", attributes);

    Texture * skyDomeMap = new TextureFile("Earth/StarsMap_2500x1250.jpg", "glow");
    fromAtmosphere->addTexture(skyDomeMap);
    fromSpace->addTexture(skyDomeMap);

//    Mesh * skyDomeMesh = Geometry::sphere(attributes, 1000, 100, 50);
    Mesh * skyDomeMesh = Geometry::sphere(attributes, 50, 100, 50);
//    Mesh * skyDomeMesh = moonPlane(attributes);
    node = new Node("space", QVector3D(0,0,0), 1, skyDomeMesh, fromAtmosphere);
//    node->setRotation(QVector3D(-90, 0, 0));


//  QList<string> attributes = QList<string>() << "normal" << "uv";
//  initMaterials("Atmo/Space", attributes);
//
//  Texture * glow = new TextureQImage(ProcTextures::makeGlow(QSize(512, 512), 40.0f, 0.1f), "glow");
//  fromAtmosphere->addTexture(glow);
//  fromSpace->addTexture(glow);
//
//  node = new Node("space", planet->position, planet->getSize(), moonPlane(attributes), fromAtmosphere);
//  setAtmoUniforms(fromAtmosphere->getShaderProgram());
//  setAtmoUniforms(fromSpace->getShaderProgram());
}
Пример #2
0
void Object::loadObject( const std::string& filename )
{
	Assimp::Importer Importer;

	/* Import file
	   Options:

	   aiProcess_Triangulate -> translate models which are made from non-triangle polys
							 into triangle based meshes
	   aiProcess_GenSmoothNormals -> automatically generate normals, in case the model
							 doesn't already contain them
	*/

	const aiScene* pScene = Importer.ReadFile( filename.c_str(),
							aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs );

	if( pScene )
	{
		initFromScene( pScene, filename );
		initMaterials( pScene, filename );
	}
	else
	{
		std::cerr << "Could not load model\n";
	}

}
Пример #3
0
void Sun::init(){
  QList<string> attributes = QList<string>() << "normal" << "uv";

  initMaterials("Atmo/Sun", attributes);

  Texture * mars = new TextureFile("Planets/Mars.jpg","planet");
  fromAtmosphere->addTexture(mars);
  fromSpace->addTexture(mars);
  node = new Node("sun", planet->position, planet->getSize(), Geometry::sphere(attributes, planet->innerRadius, 800, 400), fromAtmosphere);
  node->setRotation(QVector3D(-90,0,180));
}
Пример #4
0
bool Mesh::initFromScene(const aiScene* pScene, const std::string &filename)
{
	m_Entries.resize(pScene->mNumMeshes);
	m_Textures.resize(pScene->mNumMaterials);

	for(unsigned int i = 0; i < m_Entries.size(); i++)
	{
		const aiMesh* paiMesh = pScene->mMeshes[i];
		initMesh(i, paiMesh);
	}

	return initMaterials(pScene, filename);
}
Пример #5
0
// ----------------------------------------------------------------------------
Terrain::Terrain(ISceneNode* parent, ISceneManager* mgr, s32 id,
                 float x, float z, u32 nx, u32 nz)
    :ISceneNode(parent, mgr, id), m_nx(nx), m_nz(nz)
{

    m_valid        = true;
    m_visible      = true;
    m_bounding_box = aabbox3d<f32>(0, 0, 0, x, 0, z);

    setAutomaticCulling(EAC_OFF);

    m_tile_num_x = 10;
    m_tile_num_z = 10;

    m_mesh.vertex_count = nx * nz;
    m_mesh.vertices = new S3DVertex2TCoords[m_mesh.vertex_count];

    m_mesh.quad_count = (nx - 1) * (nz - 1);
    m_mesh.indices = new u16[m_mesh.quad_count * 6];

    for (u32 j = 0; j < nz; j++)
    for (u32 i = 0; i < nx; i++)
    {
        m_mesh.vertices[j * nx + i].Pos = vector3df(x / nx * i, 0, z / nz *j);
        m_mesh.vertices[j * nx + i].Color = SColor(255, 255, 255, 255);
        m_mesh.vertices[j * nx + i].TCoords  =
            vector2df(i / (float)nx * m_tile_num_x, j / (float)nz * m_tile_num_z);
        m_mesh.vertices[j * nx + i].TCoords2 = vector2df(i / (float)nx, j / (float)nz);
    }

    createIndexList(m_mesh.indices, nx, nz);

    m_x = x;
    m_z = z;

    recalculateNormals();

    m_highlight_mesh.vertices = 0;
    m_highlight_mesh.indices = 0;

    initMaterials();

    m_highlight_visible = false;

} // Terrain
Пример #6
0
void ThreeDimLife::initView() {
    glClearColor(0,0,0,0);
    glShadeModel(GL_SMOOTH);
    
    glPolygonMode(GL_FRONT, GL_FILL);
    
    glEnable(GL_POLYGON_OFFSET_FILL);
    
    glEnable(GL_DEPTH_TEST);

    zoomAmount=75;
    rotateX = 45.0;
    rotateY = 45.0;
    rotateZ = 0.0;

    initLights();
    initMaterials();
}
Пример #7
0
bool Mesh::load(const std::string &filename){
    Assimp::Importer importer;
    const aiScene *pScene = importer.ReadFile(filename, aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs);
    if(pScene){
        entries.resize(pScene->mNumMeshes);
        textures.resize(pScene->mNumMaterials);
        for(size_t i = 0; i < entries.size(); i++){
            const aiMesh *pMesh = pScene->mMeshes[i];
            initMesh(i,pMesh);
        }
        initMaterials(pScene,filename);
    }
    else{
        printf("Error parsing '%s': '%s'\n",filename.c_str(),importer.GetErrorString());
        return false;
    }
    return true;
}
Пример #8
0
void ThreeDimLife::reset() {
    array.clear();
    array.resize(height);
    for (int i=0; i<height; ++i) {
        array[i].resize(width);
        for (int j=0;j<width; ++j) {
            array[i][j].resize(depth, false);
        }
    }
    int num = prob*width*height*depth;
    for (int i=0;i<num; ++i) {
        size_t ri = randUInt(0, height);
        size_t rj = randUInt(0, width);
        size_t rk = randUInt(0, depth);
        array[ri][rj][rk] = true;
    }
    initMaterials();
    initLights();
}
Пример #9
0
/*
    Initialise des parametres OpenGL
*/
void initGL()
{
	/*
	** Initialisation
	*/

	initMaterials();
	initLighting();

	glFrontFace( GL_CCW );
	glEnable( GL_NORMALIZE );

    gCam.theta= 0.0;
    gCam.phi = 89.0;
    gCam.r = 500.0;
    gCam.fovy = 45.0;
	gCam.ratio = 1.0;
	gCam.znear = 1.0;
	gCam.zfar = 3000.0;
}
Пример #10
0
//============================================================================
void TestModel::init()
{	
	Renderer &rd = Engine::instance().getRenderer();
	
	// Création de la caméra 
	// XXX mieux vaut ignorer le truc avec les entités
	{
		cameraEntity = Entity::create();
		auto camera = cameraEntity->addComponent<Camera>();
		cameraEntity->getTransform().move(glm::vec3(0, 0, -1));
		cameraEntity->addComponent<FreeCameraController>();
	}

	// Création du buffer des paramètres à passer au shader
	// TODO mieux vaut ignorer ça pour le moment, ça devrait pas être fait dans le main
	frameData = rd.createConstantBuffer(
		sizeof(PerFrameShaderParameters), 
		ResourceUsage::Dynamic, 
		nullptr);

	initModel();
	initMaterials();
}
Пример #11
0
bool Model::init(const char* fileName, const aiScene* scene){
  //save our number of vertices so we know how many to draw later
  numVertices = vertices.size();

  //set up where geometry lives for GL to draw
  glGenBuffers(1, &vbo_geometry);
  glBindBuffer(GL_ARRAY_BUFFER, vbo_geometry);
  glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vertex), &vertices[0], GL_STATIC_DRAW);
  // --Geometry Done

  //setup textures
  initMaterials(fileName, scene); //mesh if our file name, scene is our aiScene


  //set up our shaders
    GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER);
    GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER);

    //Shader Sources
    // --Shader loader completed, returns string with the shader file
    // Note the added uniform!
    std::string tempString1 = shaderLoader("assets/shaders/vertex-shader");
    const char *vs = tempString1.c_str();

    std::string tempString2 = shaderLoader("assets/shaders/fragment-shader");
    const char *fs = tempString2.c_str();

    //compile the shaders
    GLint shader_status;

    // Vertex shader first
    glShaderSource(vertex_shader, 1, &vs, NULL);
    glCompileShader(vertex_shader);
    //check the compile status
    glGetShaderiv(vertex_shader, GL_COMPILE_STATUS, &shader_status);
    if(!shader_status)
    {
        std::cerr << "[F] FAILED TO COMPILE VERTEX SHADER!" << std::endl;
        return false;
    }

    // Now the Fragment shader
    glShaderSource(fragment_shader, 1, &fs, NULL);
    glCompileShader(fragment_shader);
    //check the compile status
    glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &shader_status);

    if(!shader_status)
    {
        std::cerr << "[F] FAILED TO COMPILE FRAGMENT SHADER!" << std::endl;
        return false;
    }

    //Now we link the 2 shader objects into a program
    //This program is what is run on the GPU
    program = glCreateProgram();
    glAttachShader(program, vertex_shader);
    glAttachShader(program, fragment_shader);
    glLinkProgram(program);
    //check if everything linked ok
    glGetProgramiv(program, GL_LINK_STATUS, &shader_status);
    if(!shader_status){
        std::cerr << "[F] THE SHADER PROGRAM FAILED TO LINK" << std::endl;
        return false;
    }

    //Now we set the locations of the attributes and uniforms
    //this allows us to access them easily while rendering
    loc_position = glGetAttribLocation(program,
                    const_cast<const char*>("v_position"));
    if(loc_position == -1){
        std::cerr << "[F] POSITION NOT FOUND" << std::endl;
        return false;
    }

    loc_color = glGetAttribLocation(program,
                    const_cast<const char*>("v_color"));
    if(loc_color == -1){
        std::cerr << "[F] V_COLOR NOT FOUND" << std::endl;
        return false;
    }

    loc_normal = glGetAttribLocation(program, 
                     const_cast<const char*>("v_normal"));
    if (loc_normal == -1){
        std::cerr << "[F] v_normal not found \n";
     }

    //add textures
    loc_texture = glGetAttribLocation(program,
                    const_cast<const char*>("texcoord"));
    if(loc_texture == -1){
        std::cerr << "[F] texcoord NOT FOUND" << std::endl;
        return false;
    }

    loc_mvpmat = glGetUniformLocation(program,
                    const_cast<const char*>("mvpMatrix"));
    if(loc_mvpmat == -1){
        std::cerr << "[F] MVPMATRIX NOT FOUND" << std::endl;
        return false;
    }



  return true;
}
Пример #12
0
 void iStatistics::init()
 {
     initMaterials();
     _seconds = iTimer::getInstance().getSeconds();
 }
Пример #13
0
void initGame(void)
{
	lcdMainOnTop();
	int oldv=getMemFree();
	NOGBA("mem free : %dko (%do)",getMemFree()/1024,getMemFree());
	NOGBA("initializing...");
	videoSetMode(MODE_5_3D | DISPLAY_BG3_ACTIVE);
	videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE);
	
	glInit();
	
	vramSetPrimaryBanks(VRAM_A_TEXTURE,VRAM_B_TEXTURE,VRAM_C_LCD,VRAM_D_MAIN_BG_0x06000000);
	vramSetBankH(VRAM_H_SUB_BG);
	vramSetBankI(VRAM_I_SUB_BG_0x06208000);
	
	glEnable(GL_TEXTURE_2D);
	// glEnable(GL_ANTIALIAS);
	glDisable(GL_ANTIALIAS);
	glEnable(GL_BLEND);
	glEnable(GL_OUTLINE);
	
	glSetOutlineColor(0,RGB15(0,0,0)); //TEMP?
	glSetOutlineColor(1,RGB15(0,0,0)); //TEMP?
	glSetOutlineColor(7,RGB15(31,0,0)); //TEMP?
	glSetToonTableRange(0, 15, RGB15(8,8,8)); //TEMP?
	glSetToonTableRange(16, 31, RGB15(24,24,24)); //TEMP?
	
	glClearColor(31,31,0,31);
	glClearPolyID(63);
	glClearDepth(0x7FFF);

	glViewport(0,0,255,191);
	
	// initVramBanks(1);
	initVramBanks(2);
	initTextures();
	initSound();
	
	initCamera(NULL);
	
	initPlayer(NULL);
	
	initLights();
	initParticles();
	
	initMaterials();
	
	loadMaterialSlices("slices.ini");
	loadMaterials("materials.ini");
	loadControlConfiguration("config.ini");
	
	initElevators();
	initWallDoors();
	initTurrets();
	initBigButtons();
	initTimedButtons();
	initEnergyBalls();
	initPlatforms();
	initCubes();
	initEmancipation();
	initDoors();
	initSludge();
	initPause();

	initText();

	NOGBA("lalala");

	getPlayer()->currentRoom=&gameRoom;
	
	currentBuffer=false;
	
	getVramStatus();
	fadeIn();
	
	mainBG=bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
	bgSetPriority(mainBG, 0);
	REG_BG0CNT=BG_PRIORITY(3);
	
	#ifdef DEBUG_GAME
		consoleInit(&bottomScreen, 3, BgType_Text4bpp, BgSize_T_256x256, 16, 0, false, true);
		consoleSelect(&bottomScreen);
	#endif
	
	// glSetToonTableRange(0, 14, RGB15(16,16,16));
	// glSetToonTableRange(15, 31, RGB15(26,26,26));
	
	initPortals();
	
	//PHYSICS
	initPI9();

	strcpy(&mapFilePath[strlen(mapFilePath)-3], "map");
	newReadMap(mapFilePath, NULL, 255);
	
	transferRectangles(&gameRoom);
	makeGrid();
	generateRoomGrid(&gameRoom);
	gameRoom.displayList=generateRoomDisplayList(&gameRoom, vect(0,0,0), vect(0,0,0), false);
	
	getVramStatus();
	
	startPI();

	NOGBA("START mem free : %dko (%do)",getMemFree()/1024,getMemFree());
	NOGBA("vs mem free : %dko (%do)",oldv/1024,oldv);

	levelInfoCounter=60;
}
/* openGL init */
void myInit() {

	t = clock();

	/* Enable a single OpenGL light. */
	initLighting();
	initMaterials();
	glEnable(GL_LIGHT0);
	glEnable(GL_LIGHTING);

	initGroundTexture();
	initSkyTexture();
	initRailTexture();
	initSpline();
	calculateNormalsAndBinormals();

	/* create the display list */
	theSpline = glGenLists(1);
	glNewList(theSpline, GL_COMPILE);

	/* create cross sections */
	glBegin(GL_LINES);

	for (int i = 0; i < normals.numControlPoints; i++) {
		glVertex3f(rollercoasterSpline.points[i].x, rollercoasterSpline.points[i].y, rollercoasterSpline.points[i].z);
		glVertex3f(rollercoasterSpline.points[i].x + normals.points[i].x / 2,
			rollercoasterSpline.points[i].y + normals.points[i].y / 2,
			rollercoasterSpline.points[i].z + normals.points[i].z / 2);
	}

	glEnd();

	/* create support beams */
	glBegin(GL_LINES);

	for (int i = 0; i < normals.numControlPoints; i++) {
		if (i % 20 == 0) {
			glVertex3f(rollercoasterSpline.points[i].x, rollercoasterSpline.points[i].y, rollercoasterSpline.points[i].z);
			glVertex3f(rollercoasterSpline.points[i].x, rollercoasterSpline.points[i].y, 0);

			glVertex3f(rollercoasterSpline.points[i].x + normals.points[i].x / 2,
				rollercoasterSpline.points[i].y + normals.points[i].y / 2,
				rollercoasterSpline.points[i].z + normals.points[i].z / 2);
			glVertex3f(rollercoasterSpline.points[i].x + normals.points[i].x / 2,
				rollercoasterSpline.points[i].y + normals.points[i].y / 2,
				0);
		}
	}

	glEnd();

	// modulate texture with lighting
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	glBindTexture(GL_TEXTURE_2D, railTexture);
	// turn on texture mapping
	glEnable(GL_TEXTURE_2D);


	/* compute the spline */
	glBegin(GL_QUADS);

	double alpha = 0.05;
	for (int i = 0; i < rollercoasterSpline.numControlPoints; i++) {
		double pointX = rollercoasterSpline.points[i].x;
		double pointY = rollercoasterSpline.points[i].y;
		double pointZ = rollercoasterSpline.points[i].z;
		double normX = normals.points[i].x;
		double normY = normals.points[i].y;
		double normZ = normals.points[i].z;
		double binX = binormals.points[i].x;
		double binY = binormals.points[i].y;
		double binZ = binormals.points[i].z;

		double pointX2 = rollercoasterSpline.points[i + 1].x;
		double pointY2 = rollercoasterSpline.points[i + 1].y;
		double pointZ2 = rollercoasterSpline.points[i + 1].z;
		double normX2 = normals.points[i + 1].x;
		double normY2 = normals.points[i + 1].y;
		double normZ2 = normals.points[i + 1].z;
		double binX2 = binormals.points[i + 1].x;
		double binY2 = binormals.points[i + 1].y;
		double binZ2 = binormals.points[i + 1].z;

		double v0X = pointX - alpha*(normX - binX);
		double v0Y = pointY - alpha*(normY - binY);
		double v0Z = pointZ - alpha*(normZ - binZ);

		double v1X = pointX + alpha*(normX + binX);
		double v1Y = pointY + alpha*(normY + binY);
		double v1Z = pointZ + alpha*(normZ + binZ);

		double v2X = pointX + alpha*(normX - binX);
		double v2Y = pointY + alpha*(normY - binY);
		double v2Z = pointZ + alpha*(normZ - binZ);

		double v3X = pointX - alpha*(normX + binX);
		double v3Y = pointY - alpha*(normY + binY);
		double v3Z = pointZ - alpha*(normZ + binZ);

		double v4X = pointX2 - alpha*(normX2 - binX2);
		double v4Y = pointY2 - alpha*(normY2 - binY2);
		double v4Z = pointZ2 - alpha*(normZ2 - binZ2);

		double v5X = pointX2 + alpha*(normX2 + binX2);
		double v5Y = pointY2 + alpha*(normY2 + binY2);
		double v5Z = pointZ2 + alpha*(normZ2 + binZ2);

		double v6X = pointX2 + alpha*(normX2 - binX2);
		double v6Y = pointY2 + alpha*(normY2 - binY2);
		double v6Z = pointZ2 + alpha*(normZ2 - binZ2);

		double v7X = pointX2 - alpha*(normX2 + binX2);
		double v7Y = pointY2 - alpha*(normY2 + binY2);
		double v7Z = pointZ2 - alpha*(normZ2 + binZ2);

		// // // RAIL TWO // // //

		double v0X2 = pointX - alpha*(-8 * normX - binX);
		double v0Y2 = pointY - alpha*(-8 * normY - binY);
		double v0Z2 = pointZ - alpha*(-8 * normZ - binZ);

		double v1X2 = pointX + alpha*(10 * normX + binX);
		double v1Y2 = pointY + alpha*(10 * normY + binY);
		double v1Z2 = pointZ + alpha*(10 * normZ + binZ);

		double v2X2 = pointX + alpha*(10 * normX - binX);
		double v2Y2 = pointY + alpha*(10 * normY - binY);
		double v2Z2 = pointZ + alpha*(10 * normZ - binZ);

		double v3X2 = pointX - alpha*(-8 * normX + binX);
		double v3Y2 = pointY - alpha*(-8 * normY + binY);
		double v3Z2 = pointZ - alpha*(-8 * normZ + binZ);

		double v4X2 = pointX2 - alpha*(-8 * normX2 - binX2);
		double v4Y2 = pointY2 - alpha*(-8 * normY2 - binY2);
		double v4Z2 = pointZ2 - alpha*(-8 * normZ2 - binZ2);

		double v5X2 = pointX2 + alpha*(10 * normX2 + binX2);
		double v5Y2 = pointY2 + alpha*(10 * normY2 + binY2);
		double v5Z2 = pointZ2 + alpha*(10 * normZ2 + binZ2);

		double v6X2 = pointX2 + alpha*(10 * normX2 - binX2);
		double v6Y2 = pointY2 + alpha*(10 * normY2 - binY2);
		double v6Z2 = pointZ2 + alpha*(10 * normZ2 - binZ2);

		double v7X2 = pointX2 - alpha*(-8 * normX2 + binX2);
		double v7Y2 = pointY2 - alpha*(-8 * normY2 + binY2);
		double v7Z2 = pointZ2 - alpha*(-8 * normZ2 + binZ2);

		// // // // // // // // //


		glNormal3f(-normals.points[i].x, -normals.points[i].y, -normals.points[i].z);
		// right side face
		glTexCoord2f(1.0, 0.0);
		glVertex3f(v0X, v0Y, v0Z);
		glTexCoord2f(0.0, 0.0);
		glVertex3f(v1X, v1Y, v1Z);
		glTexCoord2f(0.0, 1.0);
		glVertex3f(v5X, v5Y, v5Z);
		glTexCoord2f(1.0, 1.0);
		glVertex3f(v4X, v4Y, v4Z);

		glNormal3f(-binormals.points[i].x, -binormals.points[i].y, -binormals.points[i].z);
		// top face
		glTexCoord2f(1.0, 0.0);
		glVertex3f(v1X, v1Y, v1Z);
		glTexCoord2f(0.0, 0.0);
		glVertex3f(v2X, v2Y, v2Z);
		glTexCoord2f(0.0, 1.0);
		glVertex3f(v6X, v6Y, v6Z);
		glTexCoord2f(1.0, 1.0);
		glVertex3f(v5X, v5Y, v5Z);

		glNormal3f(normals.points[i].x, normals.points[i].y, normals.points[i].z);
		// left side face
		glTexCoord2f(1.0, 0.0);
		glVertex3f(v2X, v2Y, v2Z);
		glTexCoord2f(0.0, 0.0);
		glVertex3f(v3X, v3Y, v3Z);
		glTexCoord2f(0.0, 1.0);
		glVertex3f(v7X, v7Y, v7Z);
		glTexCoord2f(1.0, 1.0);
		glVertex3f(v6X, v6Y, v6Z);

		glNormal3f(binormals.points[i].x, binormals.points[i].y, binormals.points[i].z);
		// bottom face
		glTexCoord2f(1.0, 0.0);
		glVertex3f(v0X, v0Y, v0Z);
		glTexCoord2f(0.0, 0.0);
		glVertex3f(v3X, v3Y, v3Z);
		glTexCoord2f(0.0, 1.0);
		glVertex3f(v7X, v7Y, v7Z);
		glTexCoord2f(1.0, 1.0);
		glVertex3f(v4X, v4Y, v4Z);



		// // // RAIL TWO // // //
		// // // // // // // // //

		glNormal3f(-normals.points[i].x, -normals.points[i].y, -normals.points[i].z);
		// right side face
		glTexCoord2f(1.0, 0.0);
		glVertex3f(v0X2, v0Y2, v0Z2);
		glTexCoord2f(0.0, 0.0);
		glVertex3f(v1X2, v1Y2, v1Z2);
		glTexCoord2f(0.0, 1.0);
		glVertex3f(v5X2, v5Y2, v5Z2);
		glTexCoord2f(1.0, 1.0);
		glVertex3f(v4X2, v4Y2, v4Z2);

		glNormal3f(-binormals.points[i].x, -binormals.points[i].y, -binormals.points[i].z);
		// top face
		glTexCoord2f(1.0, 0.0);
		glVertex3f(v1X2, v1Y2, v1Z2);
		glTexCoord2f(0.0, 0.0);
		glVertex3f(v2X2, v2Y2, v2Z2);
		glTexCoord2f(0.0, 1.0);
		glVertex3f(v6X2, v6Y2, v6Z2);
		glTexCoord2f(1.0, 1.0);
		glVertex3f(v5X2, v5Y2, v5Z2);

		glNormal3f(normals.points[i].x, normals.points[i].y, normals.points[i].z);
		// left side face
		glTexCoord2f(1.0, 0.0);
		glVertex3f(v2X2, v2Y2, v2Z2);
		glTexCoord2f(0.0, 0.0);
		glVertex3f(v3X2, v3Y2, v3Z2);
		glTexCoord2f(0.0, 1.0);
		glVertex3f(v7X2, v7Y2, v7Z2);
		glTexCoord2f(1.0, 1.0);
		glVertex3f(v6X2, v6Y2, v6Z2);

		glNormal3f(binormals.points[i].x, binormals.points[i].y, binormals.points[i].z);
		// bottom face
		glTexCoord2f(1.0, 0.0);
		glVertex3f(v0X2, v0Y2, v0Z2);
		glTexCoord2f(0.0, 0.0);
		glVertex3f(v3X2, v3Y2, v3Z2);
		glTexCoord2f(0.0, 1.0);
		glVertex3f(v7X2, v7Y2, v7Z2);
		glTexCoord2f(1.0, 1.0);
		glVertex3f(v4X2, v4Y2, v4Z2);

	}
	glDisable(GL_TEXTURE_2D);
	glEnd();
	glEndList();


	/* setup gl view here */
	glClearColor(0.0, 0.0, 0.0, 0.0);
}
Пример #15
0
int main ( int argc, char* argv[] )
{
    if ( argc != 2 )
    {
	cout << "usage : " << argv[0] << " SLCFileName" << endl;
	cout << argv[0] << " will generate a slc file & idx files" << endl;
	return 0;
    }
    initLC();
    initMaterials();

//    list<SLCNode*> nodes;
    SLCSceneNode scene ( "test_scene");
    scene.addChild ( gmat );
    scene.addChild ( gmat1 );
    scene.addChild ( gmatLine0 );
    scene.addChild ( gmatLine );
    scene.addChild ( gmatLine2 );
    scene.addChild ( gmatLine3 );

    {
	SLCLayerNode* layer = new SLCLayerNode ( "background", gmat );
	nodes.push_back ( layer );
	SLCLODNode* lod = new SLCLODNode();
	nodes.push_back ( lod );
	SLCLODPageNode* lodpage = new SLCLODPageNode();
	nodes.push_back ( lodpage );
	lodpage->delayloading = false;
	lodpage->kdtree = "background0.idx";
	lodpage->imposter = true;
	scene.addChild ( layer );
	layer->addChild ( lod );
	lod->addChild ( lodpage );

	SLCTransformNode* t = new SLCTransformNode ();
//	mat_rotatematrix ( t->mat, M_PI / 2, 2 );
	mat_translatematrix ( t->mat, -100, -100, 0 );
	nodes.push_back ( t );
	lodpage->addChild ( t );

	float w = 8900;
	float h = 10800;
	SLCRectNode* rc1 = new SLCRectNode ( gmat1 );
	nodes.push_back ( rc1 );
	rc1->pnts[0] = vec2f ( 0, 0 );
	rc1->pnts[1] = vec2f ( w, 0 );
	rc1->pnts[2] = vec2f ( w, h );
	rc1->pnts[3] = vec2f ( 0, h );
	rc1->z = -2;
//	lodpage->addChild ( rc1 );
	t->addChild ( rc1 );
    }

    {
	SLCLayerNode* layer = new SLCLayerNode ( "global routing", gmat );
	nodes.push_back ( layer );
	SLCLODNode* lod = new SLCLODNode();
	nodes.push_back ( lod );
	SLCLODPageNode* lodpage = new SLCLODPageNode();
	nodes.push_back ( lodpage );
	lodpage->delayloading = false;
	lodpage->kdtree = "globalrouting0.idx";
	lodpage->imposter = true;
	scene.addChild ( layer );
	layer->addChild ( lod );
	lod->addChild ( lodpage );
	float w, h;
	lodpage->addChild ( globalrouting_lod0(gmat, w, h) );
    }

    {
	float w, h;
	SLCLayerNode* layer = new SLCLayerNode ( "local routing", gmat );
	nodes.push_back ( layer );
	SLCLODNode* lod = new SLCLODNode();
	nodes.push_back ( lod );
	SLCLODPageNode* lodpage = new SLCLODPageNode();
	nodes.push_back ( lodpage );
	lodpage->delayloading = false;
	lodpage->kdtree = "localrouting0.idx";
	lodpage->imposter = true;
	scene.addChild ( layer );
	layer->addChild ( lod );
	lodpage->addChild ( localrouting_lod0(gmat, w, h) );

	SLCLODPageNode* lodpage1 = new SLCLODPageNode();
	nodes.push_back ( lodpage1 );
	lod->addChild ( lodpage1 );
	lod->addChild ( lodpage );
	lod->scales.push_back (0.00019);
    }
    {
	float w, h;
	SLCLayerNode* layer = new SLCLayerNode ( "logic", gmat );
	nodes.push_back ( layer );
	scene.addChild ( layer );

	SLCLODNode* lod = new SLCLODNode();
	nodes.push_back ( lod );
	layer->addChild ( lod );

	SLCLODPageNode* lodpage0 = new SLCLODPageNode();
	nodes.push_back ( lodpage0 );
	lodpage0->delayloading = false;
	lodpage0->kdtree = "logic0.idx";
	lodpage0->imposter = true;
	lodpage0->addChild ( logic_lod0( gmat, w, h) );

	SLCLODPageNode* lodpage1 = new SLCLODPageNode();
	nodes.push_back ( lodpage1 );
	lodpage1->delayloading = false;
	lodpage1->kdtree = "logic1.idx";
	lodpage1->imposter = true;
	lodpage1->addChild ( logic_lod1( gmat, w, h) );

	SLCLODPageNode* lodpage2 = new SLCLODPageNode();
	nodes.push_back ( lodpage2 );
	lodpage2->delayloading = false;
	lodpage2->kdtree = "logic2.idx";
	lodpage2->imposter = true;
	lodpage2->addChild ( logic_lod2( gmat, w, h) );

	lod->addChild ( lodpage0 );
	lod->addChild ( lodpage1 );
	lod->addChild ( lodpage2 );
	lod->scales.push_back (0.00019);
	lod->scales.push_back (0.00022);
    }

    {
	float w, h;
	SLCLayerNode* layer = new SLCLayerNode ( "port", gmat );
	nodes.push_back ( layer );
	SLCLODNode* lod = new SLCLODNode();
	nodes.push_back ( lod );
	SLCLODPageNode* lodpage = new SLCLODPageNode();
	nodes.push_back ( lodpage );
	lodpage->delayloading = false;
	lodpage->kdtree = "port0.idx";
	lodpage->imposter = true;
	scene.addChild ( layer );
	layer->addChild ( lod );
	lodpage->addChild ( port_lod0( gmat, w, h) );
	SLCLODPageNode* lodpage1 = new SLCLODPageNode();
	nodes.push_back ( lodpage1 );
	lod->addChild ( lodpage1 );
	lod->addChild ( lodpage );

	lod->scales.push_back (0.00026);
    }
//     ofstream o;
//     o.open ("test.xml" );
//     o << scene.toXML();
//     o.close();

    // ********************************************************************************
    SLCNode2LC node2lc ( &scene );
    node2lc.convert ( argv[1] );

    for ( list<SLCNode*>::iterator pp=nodes.begin(); pp!=nodes.end(); ++pp )
        delete *pp;
    
    LC nlc;
    clock_t t = clock();
    nlc.load ( argv[1] );
    cout << "parse finished, elapse " << clock() - t << "(ms), kdtreesize = " << nlc.kdtrees.size() << endl;

    t = clock();
    LCReport rpt ( nlc );
    rpt.printCounter ();
    cout << "traverse finished, elapse " << clock() - t << "(ms)" << endl;

    t = clock();
    nlc.free();
    cout << "free LC finished, elapse " << clock() - t << "(ms)" << endl;
    
    return 0;
}
Пример #16
0
// ----------------------------------------------------------------------------
Terrain::Terrain(ISceneNode* parent, ISceneManager* mgr, s32 id, FILE* fp)
                                              :ISceneNode(parent, mgr, id)
{
    m_visible = true;
    m_valid   = true;
    setAutomaticCulling(EAC_OFF);

    fread(&m_x, sizeof(f32), 1, fp);
    fread(&m_z, sizeof(f32), 1, fp);

    if (m_x < 1 || m_z < 1 || m_x > 500 || m_z > 500)
    {
        m_valid = false;
        return;
    }

    fread(&m_nx, sizeof(u32), 1, fp);
    fread(&m_nz, sizeof(u32), 1, fp);

    if (m_nx > 400 || m_nz > 400)
    {
        m_valid = false;
        return;
    }

    m_bounding_box = aabbox3d<f32>(0, 0, 0, m_x, 0, m_z);

    m_tile_num_x = 10;
    m_tile_num_z = 10;

    m_mesh.vertex_count = m_nx * m_nz;
    m_mesh.vertices = new S3DVertex2TCoords[m_mesh.vertex_count];

    m_mesh.quad_count = (m_nx - 1) * (m_nz - 1);
    m_mesh.indices = new u16[m_mesh.quad_count * 6];

    for (u32 j = 0; j < m_nz; j++)
    for (u32 i = 0; i < m_nx; i++)
    {
        m_mesh.vertices[j * m_nx + i].Pos =
            vector3df(m_x / m_nx * i, 0, m_z / m_nz *j);
        fread(&m_mesh.vertices[j * m_nx + i].Pos.Y, sizeof(f32), 1, fp);
        m_mesh.vertices[j * m_nx + i].Color = SColor(255, 255, 255, 255);

        m_mesh.vertices[j * m_nx + i].TCoords =
            vector2df(i / (float)m_nx * m_tile_num_x, j / (float)m_nz * m_tile_num_z);

        m_mesh.vertices[j * m_nx + i].TCoords2 =
            vector2df(i / (float)m_nx, j / (float)m_nz);
    }

    createIndexList(m_mesh.indices, m_nx, m_nz);

    recalculateNormals();

    m_highlight_mesh.vertices = 0;
    m_highlight_mesh.indices = 0;

    initMaterials();

    u32 x, y;
    fread(&x, sizeof(u32), 1, fp);
    fread(&y, sizeof(u32), 1, fp);

    if (x != SPIMG_X || y != SPIMG_Y)
    {
        std::cerr << "Warning: splatting image size incorrect!\n";
    }

    fread(m_material.getTexture(1)->lock(ETLM_WRITE_ONLY), sizeof(u8),
                                             4 * SPIMG_X*SPIMG_Y, fp);
    m_material.getTexture(1)->unlock();
    m_material.getTexture(1)->regenerateMipMapLevels();

    m_highlight_visible = false;

    ITexture* tex;
    Editor::readTexSt(fp, &tex); m_material.setTexture(2,tex);
    Editor::readTexSt(fp, &tex); m_material.setTexture(3, tex);
    Editor::readTexSt(fp, &tex); m_material.setTexture(4, tex);
    Editor::readTexSt(fp, &tex); m_material.setTexture(5, tex);
} // Terrain - fp