四庸科技 2021-11-22 20:37 采纳率: 0%
浏览 49
已结题

多视点(Multiple Viewpoint Rendering)渲染算法实现

问题遇到的现象和发生背景

复现论文:Multiple Viewpoint Rendering
进行三角形切片处理遇到指针指向的内容连续输出两次,第二次输出地址,不是指向的内容。

问题相关代码,请勿粘贴截图

Triangle_slices* slice_triangle(Triangle_slices* triangle_slices, Scene_triangles t) //verts[3] 为场景一个三角形 verts[0]=Va verts[1]=Vb verts[2]=Vs
{
Vertex* sorted_v[3] = {NULL}; //指针数组: 数组元素为指针的数组
//cout << sorted_v[0] << " " << sorted_v[1] << " " << sorted_v[2] << endl;
*sorted_v = sort_by_y(sorted_v, t); //根据y值排好序 返回指针数组的首地址: sort_by_y函数返回一个地址

//cout << sorted_v[0] << " " << sorted_v[1] << " " << sorted_v[2] << endl;
//cout << sorted_v[0]->y << " " << sorted_v[1]->y << " " << sorted_v[2]->y << endl;
//cout << sorted_v[0]->y << " " << sorted_v[0]->y << " " << sorted_v[0]->y << endl; 
//cout << sorted_v[0]->y << endl;
//sorted_v[0]->y = 0;
//sorted_v[1]->y = 1;
//sorted_v[2]->y = 2;
cout << sorted_v[0]->y << " " << sorted_v[1]->y << " " << sorted_v[2]->y << endl;
cout << sorted_v[0]->y << " " << sorted_v[1]->y << " " << sorted_v[2]->y << endl;

float dist10 = sorted_v[1]->y - sorted_v[0]->y;
float dist21 = sorted_v[2]->y - sorted_v[1]->y;
float dist20 = sorted_v[2]->y - sorted_v[0]->y;


//cout << dist10 << " " << dist21 << " " << dist20 << endl;
//cout << dist10 << " " << dist21 << " " << dist20 << endl;
//cout << sorted_v[0]->y << " " << sorted_v[1]->y << " " << sorted_v[2]->y << endl; 

float ystart = (float)ceil(sorted_v[0]->y);       //round up to the nearest scanline  floor()函数
//cout << ystart << endl;
float y = ystart;

//cout << ystart - sorted_v[0]->y << endl;

//cout << sorted_v[0]->y << " " << sorted_v[1]->y << " " << sorted_v[2]->y << endl;
float a, b, delta_a, delta_b;
if (dist10 == 0)
{
    //cout << "ok" << endl;
    a = 1;
    delta_a = 0;
}
else
{

    a = 1 - ((ystart - sorted_v[0]->y) / dist10);    
    //cout << "ok" << a << endl;
    delta_a = 1.0 / dist10;
    //cout << delta_a << endl;
}

if (dist20 == 0)
{
    b = 1;
    delta_b = 0;
}
else
{
    b = 1 - ((ystart - sorted_v[0]->y) / dist20);
    delta_b = 1.0 / dist20;
} 

//cout << a << endl;
//cout << sorted_v[1]->y << endl;
//first part of triangle: v[0] shares edges with v[1] (param a) and v[2] (param b)
while (y < sorted_v[1]->y) {
    //cout << y << " ok " << triangle_slices->f <<endl;
    triangle_slices = add_slice(triangle_slices, y, sorted_v[0], a, sorted_v[1], b, sorted_v[2]); //0 1 2
    y += 1;
    a -= delta_a;
    b -= delta_b;
    triangle_slices->f++;
}

//second part of triangle: v[2] shares edges with v[1] (param a) and v[0] (param b)
a = ((y - sorted_v[1]->y) / dist21);
delta_a = 1.0 / dist21;
b = 1.0 - b;
while (y < sorted_v[2]->y) {
    //cout << y << " " << triangle_slices->f << endl;
    triangle_slices = add_slice(triangle_slices, y, sorted_v[2], a, sorted_v[1], b, sorted_v[0]);  // 2 1 0
    y += 1;
    a += delta_a;
    b += delta_b;
    triangle_slices->f++;
}

return triangle_slices;

}

运行结果及报错内容

93.7809 107.108 149.753
-1.07374e+08 1.4013e-45 2.67131e+35

我的解答思路和尝试过的方法

因为是用指针动态开辟内存,指针再第一次调用过后,指向的地址得到释放,发生错误指向问题。

我想要达到的结果

指针指向内容固定

可以复现这篇论文的,麻烦私信,可以有偿咨询。

  • 写回答

1条回答 默认 最新

  • 急速光粒 2021-11-23 06:52
    关注

    指针指向发生变化了吧,代码不全。

    评论

报告相同问题?

问题事件

  • 系统已结题 11月30日
  • 创建了问题 11月22日

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站