コード例 #1
0
int init_render(int x_res, int y_res)
{
	GzDisplay* display;
	GzNewDisplay(&display, 0, x_res, y_res);
	GzNewRender(&renderer, GZ_Z_BUFFER_RENDER, display);

	//init camera
	default_camera.position[X] =0.0;      
	default_camera.position[Y] = 10.0;
	default_camera.position[Z] = 10.0;

	default_camera.lookat[X] = 0.0;
	default_camera.lookat[Y] = 0.0;
	default_camera.lookat[Z] = 0.0;

	default_camera.worldup[X] = 0.0;
	default_camera.worldup[Y] = 1.0;
	default_camera.worldup[Z] = 0.0;

	default_camera.FOV = 53.7;              // degrees 

	GzPutCamera(renderer, &default_camera);


	//setup light
	GzToken     nameListLights[10];
	GzPointer   valueListLights[10];
	GzLight ambient_light = {{0.0f, 0.0f, 0.0f}, {0.9f, 0.9f, 0.9f}};
	GzLight direction_light = { {0.0f, -0.707f, -0.707f} , {0.9f, 0.9f, 0.9f}};
	nameListLights[0] = GZ_AMBIENT_LIGHT;
	valueListLights[0] = (GzPointer)&ambient_light;
	nameListLights[1] = GZ_DIRECTIONAL_LIGHT;
	valueListLights[1] = (GzPointer)&direction_light;
	GzPutAttribute(renderer, 2, nameListLights, valueListLights);

	//read in model
	teapot_model.ReadMesh("POT4.ASC");
	teapot_scale[0] = 0.3f;
	teapot_scale[1] = 0.3f;
	teapot_scale[2] = 0.3f;
	teapot_position[0] = 0.0f;
	teapot_position[1] = -3.0f;
	teapot_position[2] = -1.0f;
	teapot_rotation[0] = 0.0f;
	teapot_rotation[1] = 0.0f;
	teapot_rotation[2] = 0.0f;

	water_plane_model.ReadMesh("water_plane.asc");

	//setup texture display
	GzNewDisplay(&refraction_display, GZ_Z_BUFFER_RENDER, x_res, y_res);

	return 0;
}
コード例 #2
0
static int render_teapot_refraction(GzRender* in_renderer)
{
	//setup shader and teapot material
	in_renderer->v_shader = GouraudVertexShader;
	in_renderer->p_shader = GouraudAlphaPixelShader;

	//use the same material for ambient, diffuse and specular
	GzColor material_color = {0.7f, 0.3f, 0.1f};
	for(int i=0; i<3; i++)
	{
		in_renderer->Ka[i] = material_color[i];
		in_renderer->Kd[i] = material_color[i];
		in_renderer->Ks[i] = material_color[i];
	}
	in_renderer->spec = 32;

	//setup transform
	GzMatrix m;
	GzScaleMat(teapot_scale, m);
	GzPushMatrix(in_renderer, m);
	GzCoord pos = {teapot_position[0], teapot_position[1]/1.33f, teapot_position[2]};
	GzTrxMat(pos, m);
	GzPushMatrix(in_renderer, m);
	GzTrxMat(teapot_rotation, m);
	GzPushMatrix(in_renderer, m);

	GzPutCamera(renderer, &default_camera);

	GzBeginRender(in_renderer);

	GzToken		nameListTriangle[4];		/* vertex attribute names */
	GzPointer	valueListTriangle[4]; 			/* vertex attribute pointers */
	nameListTriangle[0] = GZ_POSITION; 
	nameListTriangle[1] = GZ_NORMAL; 
	nameListTriangle[2] = GZ_TEXTURE_INDEX;  
	nameListTriangle[3] = GZ_RGB_COLOR;

	const Model::TriangleVector& triangles = teapot_model.GetData();
	for(Model::TriangleVector::const_iterator it = triangles.begin(); it != triangles.end(); it++) 
	{ 	
		valueListTriangle[0] = (GzPointer)(*it)->vertices; 
		valueListTriangle[1] = (GzPointer)(*it)->normals; 
		valueListTriangle[2] = (GzPointer)(*it)->uvs; 
		GzPutTriangle(in_renderer, 3, nameListTriangle, valueListTriangle); 
	}

	return GZ_SUCCESS;
}
コード例 #3
0
static int render_water_plane(GzRender* in_renderer)
{
	//setup shader and teapot material
	in_renderer->v_shader = PhongVertexShader;
	in_renderer->p_shader = PhongPixelShader;

	//use the same material for ambient, diffuse and specular
	GzColor material_color = {0.04f, 0.4f, 0.6f};
	for(int i=0; i<3; i++)
	{
		in_renderer->Ka[i] = material_color[i];
		in_renderer->Kd[i] = material_color[i];
		in_renderer->Ks[i] = material_color[i];
	}
	in_renderer->spec = 32;

	GzPutCamera(renderer, &default_camera);

	//setup transform
	GzCoord scale = {3.0f, 1.0f, 1.5f};
	GzMatrix m;
	GzScaleMat(scale,m);
	GzPushMatrix(in_renderer, m);

	GzBeginRender(in_renderer);

	GzToken		nameListTriangle[4];		/* vertex attribute names */
	GzPointer	valueListTriangle[4]; 			/* vertex attribute pointers */
	nameListTriangle[0] = GZ_POSITION; 
	nameListTriangle[1] = GZ_NORMAL; 
	nameListTriangle[2] = GZ_TEXTURE_INDEX;  
	nameListTriangle[3] = GZ_RGB_COLOR;

	const Model::TriangleVector& triangles = water_plane_model.GetData();
	for(Model::TriangleVector::const_iterator it = triangles.begin(); it != triangles.end(); it++) 
	{ 	
		valueListTriangle[0] = (GzPointer)(*it)->vertices; 
		valueListTriangle[1] = (GzPointer)(*it)->normals; 
		valueListTriangle[2] = (GzPointer)(*it)->uvs; 
		GzPutTriangle(in_renderer, 3, nameListTriangle, valueListTriangle); 
	}

	return GZ_SUCCESS;
}
コード例 #4
0
int Application3::Initialize()
{
	/* to be filled in by the app if it sets camera params */

	GzCamera	camera;
	int		i, j;
	int		xRes, yRes, dispClass;	/* display parameters */
	int		status;

	status = 0;

	/*
	 * Allocate memory for user input
	 */
	m_pUserInput = new GzInput;

	/*
	 * initialize the display and the renderer
	 */

	m_nWidth = 256;		// frame buffer and display width
	m_nHeight = 256;    // frame buffer and display height

	/* Translation matrix */
	GzMatrix	scale =
	{
		3.25, 0.0, 0.0, 0.0,
		0.0, 3.25, 0.0, -3.25,
		0.0, 0.0, 3.25, 3.5,
		0.0, 0.0, 0.0, 1.0
	};

	GzMatrix	rotateX =
	{
		1.0, 0.0, 0.0, 0.0,
		0.0, .7071, .7071, 0.0,
		0.0, -.7071, .7071, 0.0,
		0.0, 0.0, 0.0, 1.0
	};

	GzMatrix	rotateY =
	{
		.866, 0.0, -0.5, 0.0,
		0.0, 1.0, 0.0, 0.0,
		0.5, 0.0, .866, 0.0,
		0.0, 0.0, 0.0, 1.0
	};

	status |= GzNewFrameBuffer(&m_pFrameBuffer, m_nWidth, m_nHeight);

	status |= GzNewDisplay(&m_pDisplay, GZ_RGBAZ_DISPLAY, m_nWidth, m_nHeight);

	status |= GzGetDisplayParams(m_pDisplay, &xRes, &yRes, &dispClass);

	status |= GzInitDisplay(m_pDisplay);

	status |= GzNewRender(&m_pRender, GZ_Z_BUFFER_RENDER, m_pDisplay);

#if 1 	/* set up app-defined camera if desired, else use camera defaults */
	camera.position[X] = 13.2;
	camera.position[Y] = -8.7;
	camera.position[Z] = -14.8;

	camera.lookat[X] = 0.8;
	camera.lookat[Y] = 0.7;
	camera.lookat[Z] = 4.5;

	camera.worldup[X] = -0.2;
	camera.worldup[Y] = 1.0;
	camera.worldup[Z] = 0.0;

	camera.FOV = 53.7;              /* degrees */

	status |= GzPutCamera(m_pRender, &camera);
#endif 

	/* Start Renderer */
	status |= GzBeginRender(m_pRender);

	status |= GzPushMatrix(m_pRender, scale);
	status |= GzPushMatrix(m_pRender, rotateY);
	status |= GzPushMatrix(m_pRender, rotateX);

	if (status)
		return(GZ_FAILURE);
	else
		return(GZ_SUCCESS);
}
コード例 #5
0
int Application5::Initialize()
{
	GzCamera	camera;  
	int		    xRes, yRes, dispClass;	/* display parameters */ 

	GzToken		nameListShader[9]; 	    /* shader attribute names */
	GzPointer   valueListShader[9];		/* shader attribute pointers */
	GzToken     nameListLights[10];		/* light info */
	GzPointer   valueListLights[10];
	int			shaderType, interpStyle;
	float		specpower;
	int		status; 
 
	status = 0; 

	/* 
	 * Allocate memory for user input
	 */
	m_pUserInput = new GzInput;

	/* 
	 * initialize the display and the renderer 
	 */ 
 	m_nWidth = 256;		// frame buffer and display width
	m_nHeight = 256;    // frame buffer and display height
	
	//initialize the final display
	status |= GzNewFrameBuffer(&m_pFrameBuffer, m_nWidth, m_nHeight);

	status |= GzNewDisplay(&m_finalDisplay, GZ_RGBAZ_DISPLAY, m_nWidth, m_nHeight);

	status |= GzGetDisplayParams(m_finalDisplay, &xRes, &yRes, &dispClass); 
	 
	status |= GzInitDisplay(m_finalDisplay); 

/* Translation matrix */
GzMatrix	scale = 
{ 
	3.25,	0.0,	0.0,	0.0, 
	0.0,	3.25,	0.0,	-3.25, 
	0.0,	0.0,	3.25,	3.5, 
	0.0,	0.0,	0.0,	1.0 
}; 
 
GzMatrix	rotateX = 
{ 
	1.0,	0.0,	0.0,	0.0, 
	0.0,	.7071,	.7071,	0.0, 
	0.0,	-.7071,	.7071,	0.0, 
	0.0,	0.0,	0.0,	1.0 
}; 
 
GzMatrix	rotateY = 
{ 
	.866,	0.0,	-0.5,	0.0, 
	0.0,	1.0,	0.0,	0.0, 
	0.5,	0.0,	.866,	0.0, 
	0.0,	0.0,	0.0,	1.0 
}; 

	m_pRender = new GzRender* [AAKERNEL_SIZE * sizeof(GzRender*)];
	m_pDisplay = new GzDisplay* [AAKERNEL_SIZE * sizeof(GzDisplay*)];
	
	//initialize the seperated display and renderer for different offsets
	for (int i = 0; i < AAKERNEL_SIZE; i++)
	{
		status |= GzNewDisplay(&m_pDisplay[i], GZ_RGBAZ_DISPLAY, m_nWidth, m_nHeight);

		status |= GzGetDisplayParams(m_pDisplay[i], &xRes, &yRes, &dispClass); 
	 
		status |= GzInitDisplay(m_pDisplay[i]); 
 
		status |= GzNewRender(&m_pRender[i], GZ_Z_BUFFER_RENDER, m_pDisplay[i]);
#if 1 	/* set up app-defined camera if desired, else use camera defaults */
		camera.position[X] = -3;
		camera.position[Y] = -25;
		camera.position[Z] = -4;

		camera.lookat[X] = 7.8;
		camera.lookat[Y] = 0.7;
		camera.lookat[Z] = 6.5;

		camera.worldup[X] = -0.2;
		camera.worldup[Y] = 1.0;
		camera.worldup[Z] = 0.0;

		camera.FOV = 63.7;              /* degrees *              /* degrees */

		status |= GzPutCamera(m_pRender[i], &camera); 
#endif 

		/* Start Renderer */
		status |= GzBeginRender(m_pRender[i]);

		/* Light */
		GzLight	light1 = { {-0.7071, 0.7071, 0}, {0.5, 0.5, 0.9} };
		GzLight	light2 = { {0, -0.7071, -0.7071}, {0.9, 0.2, 0.3} };
		GzLight	light3 = { {0.7071, 0.0, -0.7071}, {0.2, 0.7, 0.3} };
		GzLight	ambientlight = { {0, 0, 0}, {0.3, 0.3, 0.3} };

		/* Material property */
		GzColor specularCoefficient = { 0.3, 0.3, 0.3 };
		GzColor ambientCoefficient = { 0.1, 0.1, 0.1 };
		GzColor diffuseCoefficient = {0.7, 0.7, 0.7};

/* 
  renderer is ready for frame --- define lights and shader at start of frame 
*/

        /*
         * Tokens associated with light parameters
         */
        nameListLights[0] = GZ_DIRECTIONAL_LIGHT;
        valueListLights[0] = (GzPointer)&light1;
        nameListLights[1] = GZ_DIRECTIONAL_LIGHT;
        valueListLights[1] = (GzPointer)&light2;
        nameListLights[2] = GZ_DIRECTIONAL_LIGHT;
        valueListLights[2] = (GzPointer)&light3;
        status |= GzPutAttribute(m_pRender[i], 3, nameListLights, valueListLights);

        nameListLights[0] = GZ_AMBIENT_LIGHT;
        valueListLights[0] = (GzPointer)&ambientlight;
        status |= GzPutAttribute(m_pRender[i], 1, nameListLights, valueListLights);

        /*
         * Tokens associated with shading 
         */
        nameListShader[0]  = GZ_DIFFUSE_COEFFICIENT;
        valueListShader[0] = (GzPointer)diffuseCoefficient;

		/* 
		* Select either GZ_COLOR or GZ_NORMALS as interpolation mode  
		*/
        nameListShader[1]  = GZ_INTERPOLATE;
        interpStyle = GZ_NORMALS;         /* Phong shading */
		//interpStyle = GZ_COLOR; //gourand shading
        valueListShader[1] = (GzPointer)&interpStyle;

        nameListShader[2]  = GZ_AMBIENT_COEFFICIENT;
        valueListShader[2] = (GzPointer)ambientCoefficient;
        nameListShader[3]  = GZ_SPECULAR_COEFFICIENT;
        valueListShader[3] = (GzPointer)specularCoefficient;
        nameListShader[4]  = GZ_DISTRIBUTION_COEFFICIENT;
        specpower = 32;
        valueListShader[4] = (GzPointer)&specpower;

        nameListShader[5]  = GZ_TEXTURE_MAP;
#if 0   /* set up null texture function or valid pointer */
        valueListShader[5] = (GzPointer)0;
#else
        valueListShader[5] = (GzPointer)(tex_fun);	/* use tex_fun */
		//valueListShader[5] = (GzPointer)(ptex_fun);	// use ptex_fun
#endif
        nameListShader[6]  = GZ_AASHIFTX;
        valueListShader[6] = (GzPointer)&(AAFilter[i][X]);
		nameListShader[7]  = GZ_AASHIFTY;
        valueListShader[7] = (GzPointer)&(AAFilter[i][Y]);

		status |= GzPutAttribute(m_pRender[i], 8, nameListShader, valueListShader);


		status |= GzPushMatrix(m_pRender[i], scale);  
		status |= GzPushMatrix(m_pRender[i], rotateY); 
		status |= GzPushMatrix(m_pRender[i], rotateX); 
	}

	if (status) exit(GZ_FAILURE); 

	if (status) 
		return(GZ_FAILURE); 
	else 
		return(GZ_SUCCESS); 
}
コード例 #6
0
int Application4::Initialize()
{
    /* to be filled in by the app if it sets camera params */

    GzCamera	camera;
    int		    xRes, yRes, dispClass;	/* display parameters */

    GzToken		nameListShader[9]; 	/* shader attribute names */
    GzPointer   valueListShader[9];		/* shader attribute pointers */
    GzToken     nameListLights[10];		/* light info */
    GzPointer   valueListLights[10];
    int			shaderType, interpStyle;
    float		specpower;
    int		    status;

    status = 0;

    /*
     * Allocate memory for user input
     */
    m_pUserInput = new GzInput;

    /*
     * initialize the display and the renderer
     */

    m_nWidth = 512;		// frame buffer and display width
    m_nHeight = 512;    // frame buffer and display height

    status |= GzNewFrameBuffer(&m_pFrameBuffer, m_nWidth, m_nHeight);

    status |= GzNewDisplay(&m_pDisplay, GZ_RGBAZ_DISPLAY, m_nWidth, m_nHeight);

    status |= GzGetDisplayParams(m_pDisplay, &xRes, &yRes, &dispClass);

    status |= GzInitDisplay(m_pDisplay);

    status |= GzNewRender(&m_pRender, GZ_Z_BUFFER_RENDER, m_pDisplay);

    /* Translation matrix */
    GzMatrix	scale =
    {
        3.25,	0.0,	0.0,	0.0,
        0.0,	3.25,	0.0,	-3.25,
        0.0,	0.0,	3.25,	3.5,
        0.0,	0.0,	0.0,	1.0
    };

    GzMatrix	rotateX =
    {
        1.0,	0.0,	0.0,	0.0,
        0.0,	.7071,	.7071,	0.0,
        0.0,	-.7071,	.7071,	0.0,
        0.0,	0.0,	0.0,	1.0
    };

    GzMatrix	rotateY =
    {
        .866,	0.0,	-0.5,	0.0,
        0.0,	1.0,	0.0,	0.0,
        0.5,	0.0,	.866,	0.0,
        0.0,	0.0,	0.0,	1.0
    };

#if 1 	/* set up app-defined camera if desired, else use camera defaults */
    camera.position[X] = 13.2;
    camera.position[Y] = -8.7;
    camera.position[Z] = -14.8;

    camera.lookat[X] = 0.8;
    camera.lookat[Y] = 0.7;
    camera.lookat[Z] = 4.5;

    camera.worldup[X] = -0.2;
    camera.worldup[Y] = 1.0;
    camera.worldup[Z] = 0.0;

    camera.FOV = 53.7;              /* degrees */

    status |= GzPutCamera(m_pRender, &camera);
#endif

    /* Start Renderer */
    status |= GzBeginRender(m_pRender);

    /* Light */
    GzLight	light1 = { {-0.7071, 0.7071, 0}, {0.5, 0.5, 0.9} };
    GzLight	light2 = { {0, -0.7071, -0.7071}, {0.9, 0.2, 0.3} };
    GzLight	light3 = { {0.7071, 0.0, -0.7071}, {0.2, 0.7, 0.3} };
    GzLight	ambientlight = { {0, 0, 0}, {0.3, 0.3, 0.3} };

    /* Material property */
    GzColor specularCoefficient = { 0.3, 0.3, 0.3 };
    GzColor ambientCoefficient = { 0.1, 0.1, 0.1 };
    GzColor diffuseCoefficient = {0.7, 0.7, 0.7};

    /*
      renderer is ready for frame --- define lights and shader at start of frame
    */

    /*
     * Tokens associated with light parameters
     */
    nameListLights[0] = GZ_DIRECTIONAL_LIGHT;
    valueListLights[0] = (GzPointer)&light1;
    nameListLights[1] = GZ_DIRECTIONAL_LIGHT;
    valueListLights[1] = (GzPointer)&light2;
    nameListLights[2] = GZ_DIRECTIONAL_LIGHT;
    valueListLights[2] = (GzPointer)&light3;
    status |= GzPutAttribute(m_pRender, 3, nameListLights, valueListLights);

    nameListLights[0] = GZ_AMBIENT_LIGHT;
    valueListLights[0] = (GzPointer)&ambientlight;
    status |= GzPutAttribute(m_pRender, 1, nameListLights, valueListLights);

    /*
     * Tokens associated with shading
     */
    nameListShader[0]  = GZ_DIFFUSE_COEFFICIENT;
    valueListShader[0] = (GzPointer)diffuseCoefficient;

    /*
    * Select either GZ_COLOR or GZ_NORMALS as interpolation mode
    */
    nameListShader[1]  = GZ_INTERPOLATE;
#if 0
    interpStyle = GZ_COLOR;         /* Gouraud shading */
#else
    interpStyle = GZ_NORMALS;       /* Phong shading */
#endif

    valueListShader[1] = (GzPointer)&interpStyle;
    nameListShader[2]  = GZ_AMBIENT_COEFFICIENT;
    valueListShader[2] = (GzPointer)ambientCoefficient;
    nameListShader[3]  = GZ_SPECULAR_COEFFICIENT;
    valueListShader[3] = (GzPointer)specularCoefficient;
    nameListShader[4]  = GZ_DISTRIBUTION_COEFFICIENT;
    specpower = 32;
    valueListShader[4] = (GzPointer)&specpower;

    status |= GzPutAttribute(m_pRender, 5, nameListShader, valueListShader);

    status |= GzPushMatrix(m_pRender, scale);
    status |= GzPushMatrix(m_pRender, rotateY);
    status |= GzPushMatrix(m_pRender, rotateX);

    if (status) exit(GZ_FAILURE);

    if (status)
        return(GZ_FAILURE);
    else
        return(GZ_SUCCESS);
}
コード例 #7
0
int Application4::Initialize()
{
	GzCamera	camera;  
	int		    xRes = 0, yRes = 0, dispClass;	/* display parameters */ 

	GzToken		nameListShader[9]; 	    /* shader attribute names */
	GzPointer   valueListShader[9];		/* shader attribute pointers */
	GzToken     nameListLights[10];		/* light info */
	GzPointer   valueListLights[10];
	GzToken     nameListShifts[10];		/* Shift info */
	GzPointer   valueListShifts[10];

	int			shaderType, interpStyle;
	float		specpower;
	int			status; 
	int			index = 0;
 
	status = 0; 

	/* 
	 * Allocate memory for user input
	 */
	m_pUserInput = new GzInput;

	/* 
	 * initialize the display and the renderer 
	 */ 
 	m_nWidth = 256;		// frame buffer and display width
	m_nHeight = 256;    // frame buffer and display height
	
	/* Translation matrix */
	GzMatrix	scale = 
	{ 
		3.25,	0.0,	0.0,	0.0, 
		0.0,	3.25,	0.0,	-3.25, 
		0.0,	0.0,	3.25,	3.5, 
		0.0,	0.0,	0.0,	1.0 
	}; 
	 
	GzMatrix	rotateX = 
	{ 
		1.0,	0.0,	0.0,	0.0, 
		0.0,	.7071,	.7071,	0.0, 
		0.0,	-.7071,	.7071,	0.0, 
		0.0,	0.0,	0.0,	1.0 
	}; 
	 
	GzMatrix	rotateY = 
	{ 
		.866,	0.0,	-0.5,	0.0, 
		0.0,	1.0,	0.0,	0.0, 
		0.5,	0.0,	.866,	0.0, 
		0.0,	0.0,	0.0,	1.0 
	}; 

		/* Light */
	GzLight	light1 = { {-0.7071, 0.7071, 0}, {0.5, 0.5, 0.9} };
	GzLight	light2 = { {0, -0.7071, -0.7071}, {0.9, 0.2, 0.3} };
	GzLight	light3 = { {0.7071, 0.0, -0.7071}, {0.2, 0.7, 0.3} };
	GzLight	ambientlight = { {0, 0, 0}, {0.3, 0.3, 0.3} };

	/* Material property */
	GzColor specularCoefficient = { 0.3, 0.3, 0.3 };
	GzColor ambientCoefficient = { 0.1, 0.1, 0.1 };
	GzColor diffuseCoefficient = {0.7, 0.7, 0.7};

#if 0 	/* set up app-defined camera if desired, else use camera defaults */
    camera.position[X] = -3;
    camera.position[Y] = -25;
    camera.position[Z] = -4;

    camera.lookat[X] = 7.8;
    camera.lookat[Y] = 0.7;
    camera.lookat[Z] = 6.5;

    camera.worldup[X] = -0.2;
    camera.worldup[Y] = 1.0;
    camera.worldup[Z] = 0.0;

    camera.FOV = 63.7;              /* degrees *              /* degrees */

	status |= GzPutCamera(m_pRender, &camera); 
#endif 

	status |= GzNewFrameBuffer(&m_pFrameBuffer, m_nWidth, m_nHeight);

// ****************************************************************************************
//								START	HW6 CHANGE
// ****************************************************************************************
	// Create multiple displays and framebuffers(display framebuffers)
	for(index = 0; index < AAKERNEL_SIZE; index++){
		status |= GzNewDisplay(&m_pDisplay[index], GZ_RGBAZ_DISPLAY, m_nWidth, m_nHeight);
		status |= GzGetDisplayParams(m_pDisplay[index], &xRes, &yRes, &dispClass);  
		status |= GzInitDisplay(m_pDisplay[index]); 
		status |= GzNewRender(&m_pRender[index], GZ_Z_BUFFER_RENDER, m_pDisplay[index]); 

		/* Start Renderer */
		status |= GzBeginRender(m_pRender[index]);

		/*
		 * Tokens associated with light parameters
		 */
		nameListLights[0] = GZ_DIRECTIONAL_LIGHT;
		valueListLights[0] = (GzPointer)&light1;
		nameListLights[1] = GZ_DIRECTIONAL_LIGHT;
		valueListLights[1] = (GzPointer)&light2;
		nameListLights[2] = GZ_DIRECTIONAL_LIGHT;
		valueListLights[2] = (GzPointer)&light3;

		// store the Directional Light values in the render structures
		status |= GzPutAttribute(m_pRender[index], 3, nameListLights, valueListLights);

		nameListLights[0] = GZ_AMBIENT_LIGHT;
		valueListLights[0] = (GzPointer)&ambientlight;
		
		// store the Ambient Light values in the render structures
		status |= GzPutAttribute(m_pRender[index], 1, nameListLights, valueListLights);

		/*
		 * Tokens associated with shading 
		 */
		nameListShader[0]  = GZ_DIFFUSE_COEFFICIENT;
		valueListShader[0] = (GzPointer)diffuseCoefficient;

		/* 
		* Select either GZ_COLOR or GZ_NORMALS as interpolation mode  
		*/
			nameListShader[1]  = GZ_INTERPOLATE;
	#if 0
			interpStyle = GZ_COLOR;         /* Gourand shading */
	#else
			interpStyle = GZ_NORMALS;         /* Phong shading */
	#endif

		valueListShader[1] = (GzPointer)&interpStyle;

		nameListShader[2]  = GZ_AMBIENT_COEFFICIENT;
		valueListShader[2] = (GzPointer)ambientCoefficient;
		nameListShader[3]  = GZ_SPECULAR_COEFFICIENT;
		valueListShader[3] = (GzPointer)specularCoefficient;
		nameListShader[4]  = GZ_DISTRIBUTION_COEFFICIENT;
		specpower = 32;
		valueListShader[4] = (GzPointer)&specpower;

		nameListShader[5]  = GZ_TEXTURE_MAP;
	#if 1   /* set up null texture function or valid pointer */
		valueListShader[5] = (GzPointer)0;
	#else
		valueListShader[5] = (GzPointer)(tex_fun);	/* or use ptex_fun */
	#endif

		// store the Ambient shading values in the render structures
		status |= GzPutAttribute(m_pRender[index], 6, nameListShader, valueListShader);
		

		// Pass the Sample offset X for the renderer defined for handling that jittered sample
		nameListShifts[0]  = GZ_AASHIFTX;
		valueListShifts[0] = (GzPointer)&AAFilter[index][X];
		status |= GzPutAttribute(m_pRender[index], 1, nameListShifts, valueListShifts);
		
		// Pass the Sample offset Y for the renderer defined for handling that jittered sample
		nameListShifts[0]  = GZ_AASHIFTY;
		valueListShifts[0] = (GzPointer)&AAFilter[index][Y];
		status |= GzPutAttribute(m_pRender[index], 1, nameListShifts, valueListShifts);
		
		// Push the transformation matrices into all the renderer stacks
		status |= GzPushMatrix(m_pRender[index], scale);  
		status |= GzPushMatrix(m_pRender[index], rotateY); 
		status |= GzPushMatrix(m_pRender[index], rotateX); 
	}
// ****************************************************************************************
//								END		HW6 CHANGE
// ****************************************************************************************
	if (status) exit(GZ_FAILURE); 

	if (status) 
		return(GZ_FAILURE); 
	else 
		return(GZ_SUCCESS); 
}
コード例 #8
0
static void generated_grid(const char* OutPutFile, GzRender* renderer)
{
	static float up_bias = 30.0f, forward_bias = 20.0f;

	float u, v;
	float meshTri1V1[4];
	float meshTri1V2[4];
	float meshTri1V3[4];
	float meshTri2V1[4];
	float meshTri2V2[4];
	float meshTri2V3[4];
	xRes = 1.0f/RECT_MAX_X;
	yRes = 1.0f/RECT_MAX_Z; 

    CTransMatrix MProjection;
    CTransMatrix XiwTrans, XpiTrans;

	//set Xsp, Ximage elements
	GzCoord view_vector;
	VectorSubtract(renderer->camera.lookat, renderer->camera.position, view_vector);
	Normalize(view_vector);
	if(view_vector[1] < 0.0f)			//look at y=0
	{
		GzCoord camera_pos;
		Scale(renderer->camera.position, 1.0f, camera_pos);
		renderer->camera.position[1] = camera_pos[1] + up_bias;
		renderer->camera.lookat[0] = camera_pos[0] - camera_pos[1]/view_vector[1]*view_vector[0];
		renderer->camera.lookat[1] = 0.0f;
		renderer->camera.lookat[2] = camera_pos[2] - camera_pos[1]/view_vector[1]*view_vector[2];
		GzPutCamera(renderer, &renderer->camera);
	}
	else										//look away from y=0
	{
		GzCoord camera_pos;
		Scale(renderer->camera.position, 1.0f, camera_pos);
		GzCoord camera_forward = {view_vector[0], 0.0f, view_vector[2]};
		Normalize(camera_forward);
		renderer->camera.position[1] = camera_pos[1] + up_bias;
		renderer->camera.lookat[0] = camera_pos[0] + forward_bias * camera_forward[0];
		renderer->camera.lookat[1] = 0.0f;
		renderer->camera.lookat[2] = camera_pos[2]  + forward_bias * camera_forward[2];
		GzPutCamera(renderer, &renderer->camera);
	}
	for (int i=0;i<4;i++)
	{
		for (int j=0;j<4;j++)
		{
			XiwTrans.SetElementValue(i,j,(double)renderer->camera.Xiw[i][j]);
			XpiTrans.SetElementValue(i,j,(double)renderer->camera.Xpi[i][j]);
		}
	}

	MProjection = XpiTrans;
	MProjection *=XiwTrans;
	MatrixInverse(MProjection.matrixData, MProjection.matrixData);

//transform and output the vertices

	FILE *outfile ;
	outfile = fopen ( OutPutFile , "wb" );

//Transform four corners of the grid

	float  leftbottomper[4] = {-1.0f, -1.0f, -1.0f, 1.0f}, 
			rightbottomper[4] = {1.0f, -1.0f, -1.0f, 1.0f}, 
			lefttopper[4] = {-1.0f, 1.0f, -1.0f, 1.0f}, 
			righttopper[4] = {1.0f, 1.0f, -1.0f, 1.0f};
     
    float  leftbottom1[4], rightbottom1[4], lefttop1[4], righttop1[4];
	float  leftbottom2[4], rightbottom2[4], lefttop2[4], righttop2[4];
     //transform leftbottom to world space
          //set z to -1
	       leftbottomper[2] = -1;
           MProjection.GetTransformedHVertex(leftbottomper,leftbottom1);
		   leftbottomper[2] = 1;
		   MProjection.GetTransformedHVertex(leftbottomper,leftbottom2);
           LinePlaneIntersection(leftbottom1, leftbottom2, m_LeftBottom);   
		   
    //transform rightbottom to world space
	       rightbottomper[2] = -1;
		   MProjection.GetTransformedHVertex(rightbottomper,rightbottom1);
		  rightbottomper[2] = 1;
		   MProjection.GetTransformedHVertex(rightbottomper,rightbottom2);
		   LinePlaneIntersection(rightbottom1, rightbottom2, m_RightBottom);

	//transform lefttop to world space
	       lefttopper[2] = -1;
		   MProjection.GetTransformedHVertex(lefttopper,lefttop1);
		   lefttopper[2] = 1;
		   MProjection.GetTransformedHVertex(lefttopper,lefttop2);
		   LinePlaneIntersection(lefttop1, lefttop2, m_LeftTop);

	//transform righttop to world space
		   righttopper[2] = -1;
		   MProjection.GetTransformedHVertex(righttopper,righttop1);
		  righttopper[2] = 1;
		   MProjection.GetTransformedHVertex(righttopper,righttop2);
		   LinePlaneIntersection(righttop1, righttop2, m_RightTop);

//interpolate homegeneous coordinates
   float current_Vertex[4];

for (int i=0; i<RECT_MAX_X;i++ )
	{
		for (int j=0;j<RECT_MAX_Z;j++)
		{
			  fprintf( outfile, "Triangle\r\n");         
			  InterpolateHomoCoord(i,j,meshTri1V1);
			  u = i*xRes; v= j*yRes;
			  fprintf( outfile, "%f %f %f " ,  meshTri1V1[X],  meshTri1V1[Y], meshTri1V1[Z] );
			  fprintf( outfile, "0.00 1.00 0.00 ");//normal
			  fprintf( outfile, "%f %f\r\n", u,v);

			  InterpolateHomoCoord(i+1,j,meshTri1V2);
			  u = (i+1)*xRes; v= j*yRes;
			  fprintf( outfile, "%f %f %f " ,  meshTri1V2[X],  meshTri1V2[Y], meshTri1V2[Z] );
			  fprintf( outfile, "0.00 1.00 0.00 ");//normal
			  fprintf( outfile, "%f %f\r\n", u,v);

			  InterpolateHomoCoord(i+1,j+1,meshTri1V3);
			  u = (i+1)*xRes; v= (j+1)*yRes;
			  fprintf( outfile, "%f %f %f " ,  meshTri1V3[X],  meshTri1V3[Y], meshTri1V3[Z] );
			  fprintf( outfile, "0.00 1.00 0.00 ");//normal
			  fprintf( outfile, "%f %f\r\n", u,v);
            

			  //Second triangle vertices
			  fprintf( outfile, "Triangle\r\n");  
			  u = i*xRes; v= j*yRes;
			  fprintf( outfile, "%f %f %f " ,  meshTri1V1[X],  meshTri1V1[Y], meshTri1V1[Z] );
			  fprintf( outfile, "0.00 1.00 0.00 ");//normal
			  fprintf( outfile, "%f %f\r\n", u,v);

			  u = (i+1)*xRes; v= (j+1)*yRes;
			  fprintf( outfile, "%f %f %f " ,  meshTri1V3[X],  meshTri1V3[Y], meshTri1V3[Z] );
			  fprintf( outfile, "0.00 1.00 0.00 ");//normal
			  fprintf( outfile, "%f %f\r\n", u,v);

			  InterpolateHomoCoord(i,j+1,meshTri2V3);
			  u = i*xRes; v= (j+1)*yRes;
			  fprintf( outfile, "%f %f %f " ,  meshTri2V3[X],  meshTri2V3[Y], meshTri2V3[Z] );
			  fprintf( outfile, "0.00 1.00 0.00 ");//normal
			  fprintf( outfile, "%f %f\r\n", u,v);
		}
	}
}