示例#1
0
  void test_normal(const Normal3f& normal)
  {
    Normal3f test = normal3f_from_spherical(spherical_from_normal3f(normal));
    check_normal(normal, test);

    EOctant octant = normal3f_classify_octant(normal);
    Normal3f folded = normal3f_fold_octant(normal, octant);
    ESextant sextant = normal3f_classify_sextant(folded);
    folded = normal3f_fold_sextant(folded, sextant);

    double scale = static_cast<float>(c_quantise_normal) / (folded.x + folded.y + folded.z);

    double zbits = folded.z * scale;
    double ybits = folded.y * scale;

    std::size_t zbits_q = static_cast<std::size_t>(zbits);
    std::size_t ybits_q = static_cast<std::size_t>(ybits);

    ASSERT_MESSAGE(zbits_q <= (c_quantise_normal / 8) * 3, "bleh");
    ASSERT_MESSAGE(ybits_q <= (c_quantise_normal / 2), "bleh");
    ASSERT_MESSAGE(zbits_q + ((c_quantise_normal / 2) - ybits_q) <= (c_quantise_normal / 2), "bleh");

    std::size_t y_t = (zbits_q < (c_quantise_normal / 4)) ? ybits_q : (c_quantise_normal / 2) - ybits_q;
    std::size_t z_t = (zbits_q < (c_quantise_normal / 4)) ? zbits_q : (c_quantise_normal / 2) - zbits_q;
    std::size_t index = (c_quantise_normal / 4) * y_t + z_t;
    ASSERT_MESSAGE(index <= (c_quantise_normal / 4)*(c_quantise_normal / 2), "bleh");

    Normal3f tmp(c_quantise_normal - zbits_q - ybits_q, ybits_q, zbits_q);
    tmp = normal3f_normalised(tmp);

    Normal3f unfolded = normal3f_unfold_octant(normal3f_unfold_sextant(tmp, sextant), octant);

    check_normal(normal, unfolded);

    double dot = normal3f_dot(normal, unfolded);
    float length = VectorLength(normal3f_to_array(unfolded));
    float inv_length = 1 / length;

    Normal3f quantised = normal3f_quantised(normal);
    check_normal(normal, quantised);
  }
示例#2
0
HRESULT mesh_heart::find_point(pancy_point *vertex,UINT *index,int &num_vertex,int &num_index)
{
	num_vertex = 0;
	num_index  = 0;
	double st_x = -1.2,ed_x = 1.2;
	line_percircle += 1;
	//填充顶点
	for(int i = 0; i < heart_divide; ++i)
	{
		double st_y,ed_y;
		double x_rec = st_x + ((ed_x - st_x)/static_cast<double>(heart_divide)) * double(i);
		if(check_range(x_rec,st_y,ed_y))
		{
			for(int j = 0; j < line_percircle; j++)
			{
				double y_rec = st_y + ((ed_y-st_y)/static_cast<double>(line_percircle-1)) * (double)j;		
				if(j == line_percircle -1)
				{
					y_rec = ed_y;
				}
				double z_rec1;
				double z_rec2 = get_z(x_rec,y_rec,2.0,1.0);
				double balance_check = 1.0;
				for(int k = 0; k < 10; ++k)
				{
					balance_check =1.0 - k*0.1;
					z_rec1 = get_z(x_rec,y_rec,-2.0,balance_check);
					if(z_rec1 - z_rec2 < -0.00000001 || z_rec1 - z_rec2 > 0.00000001)
					{
						break;
					}
				}
				int st_now = num_vertex+j;
				int ed_now = num_vertex+2*line_percircle-1-j;
				vertex[st_now].position.x = static_cast<float>(y_rec);
				vertex[st_now].position.y = static_cast<float>(z_rec1);
				vertex[st_now].position.z = static_cast<float>(x_rec);
				vertex[st_now].normal = count_normal(x_rec,y_rec,z_rec1);
				if(!check_normal(vertex[st_now].normal,vertex[st_now].position))
				{
					vertex[st_now].normal.x = -vertex[st_now].normal.x;
					vertex[st_now].normal.y = -vertex[st_now].normal.y;
					vertex[st_now].normal.z = -vertex[st_now].normal.z;
				}
				vertex[st_now].tex.x = 0.0f;
				vertex[st_now].tex.y = 0.0f;
				vertex[ed_now].position.x = static_cast<float>(y_rec);
				vertex[ed_now].position.y = static_cast<float>(z_rec2);
				vertex[ed_now].position.z = static_cast<float>(x_rec);
				vertex[ed_now].normal = count_normal(x_rec,y_rec,z_rec2);
				if(!check_normal(vertex[ed_now].normal,vertex[ed_now].position))
				{
					vertex[ed_now].normal.x = -vertex[ed_now].normal.x;
					vertex[ed_now].normal.y = -vertex[ed_now].normal.y;
					vertex[ed_now].normal.z = -vertex[ed_now].normal.z;
				}
				vertex[ed_now].tex.x = 0.0f;
				vertex[ed_now].tex.y = 0.0f;
			}
			num_vertex += 2*line_percircle;
		}
		else
		{
			heart_divide -= 1;
		}
	}
	//填充索引
	for(int i=0; i < heart_divide-1; ++i)  
	{  
		for(int j=0; j < line_percircle*2; ++j)  
		{  
			if(j == line_percircle*2-1)
			{
				index[num_index++] = i * line_percircle*2 + j;  
				index[num_index++] = (i + 1) * line_percircle*2;  
				index[num_index++] = (i + 1) * line_percircle*2 + j;  
				index[num_index++] = i * line_percircle*2 + j;  
				index[num_index++] = i * line_percircle*2;  
				index[num_index++] = (i + 1) * line_percircle*2; 
			}
			else
			{
				index[num_index++] = i * line_percircle*2 + j;  
				index[num_index++] = (i + 1) * line_percircle*2 + j + 1;  
				index[num_index++] = (i + 1) * line_percircle*2 + j;  
				index[num_index++] = i * line_percircle*2 + j;  
				index[num_index++] = i * line_percircle*2 + j + 1;  
				index[num_index++] = (i + 1) * line_percircle*2 + j + 1; 
			} 
		}
	}
	vertex[num_vertex].normal = XMFLOAT3(0.0f,0.0f,-1.0f);
	vertex[num_vertex++].position = XMFLOAT3(0.0f,0.54f,1.13f);
	//加上前后盖信息
	for(int j=0; j < line_percircle*2; ++j)
	{
		if(j == line_percircle*2-1)
		{
			index[num_index++] = num_vertex - 1;
			index[num_index++] = num_vertex - line_percircle*2 + j-1;
			index[num_index++] = num_vertex - line_percircle*2-1;
		}
		else
		{
			index[num_index++] = num_vertex - 1;
			index[num_index++] = num_vertex - line_percircle*2 + j-1;
			index[num_index++] = num_vertex - line_percircle*2 + j;
		}
	}
	vertex[num_vertex].normal = XMFLOAT3(0.0f,0.0f,1.0f);
	vertex[num_vertex++].position = XMFLOAT3(0.0f,0.54f,-1.13f);
	for(int j=0; j < line_percircle*2; ++j)
	{
		if(j == line_percircle*2-1)
		{
			index[num_index++] = num_vertex-1;
			index[num_index++] = 0;
			index[num_index++] = j;
		}
		else
		{
			index[num_index++] = num_vertex-1;
			index[num_index++] = j + 1;
			index[num_index++] = j;
		}
	}
	return S_OK;
}