示例#1
0
void ExtObject::Draw()
{
	// Enable the Z stencil
	cr::renderstate_value old_zbuffer_state = renderer->GetRenderState(cr::rs_zbuffer_enabled);
	renderer->SetRenderState(cr::rs_zbuffer_enabled, (zbuffer ? cr::rsv_enabled : cr::rsv_disabled));

	cr::point3d objpos(info.x, info.y, z + (depth / 2.0));

	vector<cr::point3d> verts;
	for( int i = 0; i < 8; i++)
	{
		verts.push_back( makepoint3d(cube_vertices_xyz[i]) );
	}
	transform_vertices(verts, false);





	// Draw each face separately
	for (int i = 0; i < 6; i++) {

		renderer->SetTexture(textures[i]);

		float u = textures[i]->xf;
		float v = textures[i]->yf;

		//pRuntime->EndBatch();
		renderer->BeginBatchQuads(24, 36);

		renderer->AddIndex(0);
		renderer->AddIndex(1);
		renderer->AddIndex(2);
		renderer->AddIndex(2);
		renderer->AddIndex(3);
		renderer->AddIndex(0);


		for(int b = i*4; b < i*4 + 4; b++){

			renderer->AddVertex(verts[cube_indexes[b]], 
				cr::point(cube_vertices[b]._uv.u * u, cube_vertices[b]._uv.v * v),
				cr::opaque_white);
		}
	}

	renderer->SetRenderState(cr::rs_zbuffer_enabled, old_zbuffer_state);
}
示例#2
0
void ExtObject::transform_vertices( vector<cr::point3d>& verts, bool screen)
{
	cr::point3d objpos(info.x, info.y, z);

	cr_float sin_a, sin_b, sin_c;
	cr_float cos_a, cos_b, cos_c;

	cr_float temp;
	cr_float zz;

	cr::sincosf(-yaw, &sin_a, &cos_a);
	cr::sincosf(-pitch, &sin_b, &cos_b);
	cr::sincosf(cr::to_radians(info.angle), &sin_c, &cos_c);

	vector<cr::point3d>::iterator v = verts.begin();
	for( ; v != verts.end(); v++)
	{
		cr::point vertexpos(v->x * info.w * scale, v->y * info.h * scale);
		zz = v->z * depth * scale;

		temp = (vertexpos.x * cos_a) - (zz * sin_a);
		zz = (zz * cos_a) + (vertexpos.x * sin_a);
		vertexpos.x = temp;

		temp = (zz * cos_b) - (vertexpos.y * sin_b);
		vertexpos.y = (vertexpos.y * cos_b) + (zz * sin_b);
		zz = temp;

		vertexpos.rotate(cr::to_radians(info.angle));
		cr::point3d vertexpos3d(-vertexpos.x, -vertexpos.y, zz);

		cr::point3d vertex = objpos + vertexpos3d;

		if(screen)
		{
			vertex.x -= pLayout->scrollX;
			vertex.y -= pLayout->scrollY;
		}
		
		*v = vertex;


	}
}