- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
所以,我应该先解释一下我想如何实现它。我的想法很简单,我想创建每个 block 并通过使用每个 block 本地的浮点网格来确定每个顶点的位置,然后我想将体素放在一个大的 64 位整数网格中(每个 block 位置由它具有的整数值,0,0,0 将是中间值,20,20,20 将在 x、y 和 z 轴上远离二十 block )以进一步创建一个巨大的世界我将执行一些检查以确定如何 block 将根据它们在整数网格中的位置推断生成,我还没有弄清楚。 (不如让它运行重要)
我遇到的问题:
那么,有什么想法吗?到目前为止的相关代码(删除了光、遮挡、UV和正常计算代码,因为它与问题无关)
#define get(x, y, z)\
data[\
clamp(x, size)+\
clamp(y, size)*size+\
clamp(z, size)*size*size\
]
#define put(x,y,z, value)\
data[\
(x)+\
(y)*size+\
(z)*size*size\
] = value
#define index(x, y, x) clamp (x, size)+clamp(y, size)*size+clamp(z, size)*size*size
#define foreach_xyz(start, end) \
int x, y, z; \
float xf, yf, zf;\
for(x=(start); x<(end); x++\
{\
for(y=(start); y<(end); y++)\
{\
for (z=(start); z<(end); z++)\
{\
xf=(float)x/(float)size;\
xy=(float)y/(float)size;\
xz=(float)z/(float)size;
#define endfor }}}
//removed pointless code from here
typedef struct //vertices
{
float xVertex, yVertex, zVertex, wVertex;
} vertex;
//removed pointless code from here
typedef struct //cell
{
float leftCell, rightCell, topCell, bottomCell, frontCell, backCell;
} cell;
//removed pointless code from here
int primitiveCount_CUBE (int size, byte* data)
{
int value, count = 0;
foreach_xyz(0, size)
value = get(x,y,z)ĵ;
if(!value)
{
if(get(x+1, y, z)) count++;
if(get(x-1, y, z)) count++;
if(get(x, y+1, z)) count++;
if(get(x, y-1, z)) count++;
if(get(x, y, z+1)) count++;
if(get(x, y, z-1)) count++;
}
endfor
return count;
}
//removed pointless code from here
void setPos(vertex** posPtr, float x0, float y0, float z0,
float x1, float y1, float z1,
float x2, float y2, float z2,
float x3, float y3, float z3)
//removed pointless code from here
void setData(vertex posPtr,
float x0, float y0, float z0,
float x1, float y1, float z1,
float x2, float y2, float z2
float x3, float y3, float z3,
normal** normalPtr, float nx, float ny, float nz,
normal** sPtr, float sx, float sy, float sz,
normal** tPtr, float tx, float ty, float tz,
UV** UVPtr, int value,
color** lightPtr, color** gather,
float** occlusionPtr, float occlusion)
{
setPos(posPtr,
x0, y0, z0
x1, y1, z1,
x2, y2, y3,
x3, y3, z3);
setNormal(normalPtr, nx, ny, nz
sPtr, sx, sy, sz
tPtr, tx, ty, tz);
setUV(value, UVPtr);
setLight(gather, lightPtr);
setOcclusion(occlusion, occlusionPtr);
}
void tesselate(int size, unsigned char* data, cell* occlusion, color** gather,
vertex pos, normal* Normal, normal* s, normal* t, float outOcc,
UV* uv, color* light)
{
float n = 0.5;
int idx, value;
cell* Cell;
color* cellGather;
foreach_xyz(0, size)
idx = index(x,y,z);
cell = occlusion + idx;
cellGather = gather + idx;
if(get(x, y, z) == 0)
{
value = get(x-1, y, z)
if(value > 0)
setData(&pos, x-n, y-n, z-n,
x-n, y+n, z-n,
x-n, y+n, z+n,
x-n, y-n, z+n
&normal, 1, 0, 0,
&s, 0, 1, 0
&t, 0, 0, 1,
&UV, value,
&light, cellGather,
&outOcc, cell->leftCell);
value¨= get(x, y-1, z);
if(value== materials_cube.dirt)
{
value=materials_cube.grass;
}
if( value > 0 )
setData(&pos, x-n, y-n, z-n,
x-n, y-n, z+n,
x+n, y-n, z+n,
x+n, y-n, z-n
&normal, 0, 1, 0,
&s, 0, 0, 1,
&t, 1, 0, 0,
&UV, value,
&light, cellGather
&outOcc, cell->bottomCell);
value = get(x, y+1, z);
if(value > 0)
setData(&pos, x-n, y+n, z-n,
x+n, y+n, z-n,
x+n, y+n, z+n,
x-n, y+n, z+n,
&normal, 0, -1, 0,
&s, 1, 0, 0,
&t, 0, 0, 1,
&UV, value,
&light, cellGather
&outOcc, cell->topCell);
value = get(x, y, z-1);
if(value > 0)
setData((&pos, x-n, y-n, z-n
x+n, y-n, z-n,
x+n, y+n, z-n,
x-n, y+n, z-n,
&normal, 0, 0, 1,
&s, 1, 0, 0,
&t, 0, 1, 0,
&UV, value,
&light, cellGather,
&outOcc, cell->backCell);
value = get(x, y, z+1);
if(value > 0)
setData(&pos, x-n, y-n, z+n,
x-n, y+n, z+n,
x+n, y+n, z+n,
x+n, y-n, x+n,
&normal, 0, 0, -1,
&s, 0, 1, 0,
&t, 1, 0, 0,
&UV, value,
&light, cellGather,
&outOcc, cell->frontCell);
}
endfor
}
bool neighbors(int size, byte* data, int x, int y, int z)
{
if(get(x-1, y, z)){return true;}
if(get(x+1, y, z)){return true;}
if(get(x, y-1, z)){return true;}
if(get(x, y+1, z)){return true;}
if(get(x, y, z-1)){return true;}
if(get(x, y, z+1)){return true;}
return false;
}
据我所知,你可能会注意到这段代码与某个用C和python编写的demo非常相似,这是因为很多代码是看完后写的,有点擦关闭我
问题是它似乎没有涵盖我的问题,它让我对体素的工作原理有了更好的理解,仅此而已。
那么,关于我应该如何解决我的这个项目有什么建议吗?
P.S,这就像《战地风云 3》是《毁灭战士》的克隆版一样是《我的世界》的克隆版,我想我会让您决定如何解释它。
哦,我做了我的研究,我发现:0fps 上的帖子,我相信你们中的大多数人都熟悉这个博客 https://sites.google.com/site/letsmakeavoxelengine以及其他一些包括 GPU gems 3、行进立方体和其他一些东西,都没有解决我的问题。
最佳答案
我不确定我从你的问题中得到的是正确的但是:
我会这样做(用伪代码):
class cell
{
public:
// physical properties
float m,Q; // unit mass ,charge, ...
float c0,c1,c2; // friction indexes (could determine if it is liquid,gas or solid
float p[3],v[3],a[3]; // position,velocity,acceleration 3D
};
class object // or region
{
public:
int x0,y0,z0; // obj origin (center preferably)
int xs,ys,zs; // obj size in cells
cell *map; // *map[xs*ys*za] or ***map[xs][ys][zs] do not forget to write dynamic allocation/free resize ...
};
List<object> world; // list of all objects/regions
如果您的对象是:
1.同质
// instead of cell *map;
cell properties; // single property class for whole object
bool *map; // just a bit map if voxel is empty or occupied by cell
2.人烟稀少
// instead of int xs,ys,zs;
// instead of cell *map;
List<cell> map;
List<int[3]> pos; // position inside object
3.或者你可以有 3 个对象类类型来组合这些方法
此外,如果您的单元格属性不变,那么您可以创建一个元素表(单元格)
希望至少能有所帮助。
关于c++ - 创建体素系统并陷入困境,发现自己需要有关如何实现它的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18504588/
我正在使用 OneWayToSource绑定(bind),它似乎总是将我的源属性设置为空。为什么呢?这给我带来了麻烦,因为我需要源属性中目标属性的值而不是空值。 这是我的代码: MyViewModel
我有一个实例变量属性,它被声明和实例化,如下所示: $self->{properties}{$key1} = $value; 我的理解是这将声明属性字段,并将其设置为包含一个键值对的哈希原语。 我正
我正在尝试检查给定的数字是否是质数。首先采用试分割法。但该程序的行为很奇怪。这是我使用的。 int no; no = Integer.parseInt(jTextField1.getText());
我正在使用 NSUserDefaults使一个对象在多个 UIViewController 之间保持同步UITabbarController 中使用的 s .为此,我正在实现以下 - (void)vi
考虑以下 Java 方法: public Boolean compare(String val1, String val2) { return val1.length() > 0 && val
我有一个问题...假设我有一个包含城市名称的表。像这样: id name 1 Los Angeles 2 Madrid 我有一张用户表: uid username locationid
我无法理解这个问题。该代码非常基本,但它的行为却出乎意料。该代码是例程的简化版本,用于从每日数据库中提取每月第 15 天的数据并将其保存到单独的文件中。哪里有问题 ?第一个 cout 打印输入外部 i
我在 中使用大背景标签,我想制作一个宽度为 960px 的容器 div。我希望容器 div 位于从顶部向下 15px 的位置,我想我必须使用 position:absolute。我的困境是;容器内的
我遇到了一个难题。我有一个 hashedX 字段,它是一个散列值/加盐值,按照惯例,加盐值保存在 mysql 数据库的同一行中。 hashedX saltX ------ ---
类 java.io.Reader 和 java.io.InputStreamReader 都有具有完全相同签名的读取方法 public int read(char[] charbuf, int off
我有一个包含多个 C# 项目的 C# 解决方案。我打算在其中添加日志记录。此日志记录应该在所有项目中可用,并且最好使用带有滚动文件日志的 log4Net。 在上述前提下,我可以想到两种方法。 在解决方
我开始学习Python,目前我非常喜欢它。但是,如果你能帮我回答几个问题,这些问题一直困扰着我,我找不到任何明确的答案: 就语言兼容性而言,Python 的 C 实现(来自 python.org 的主
我正在尝试使用 AVAssetWriter 将 CGImages 写入文件以从图像创建视频。 我已经让它在模拟器上以三种不同的方式成功运行,但在运行 iOS 4.3 的 iPhone 4 上,每种方法
我需要对一个想法进行建模,可以将其分解并考虑如下: 图书详细信息 图书价格 这里的问题是您可以为书籍设置许多价格,并且这些价格可能会发生变化。这是一个例子 图书详细信息: --------------
我有一个表,其中的行包含名为 MySubId 的列。此列中的值可以重复。我想找到 MySubId 值和出现次数最多的 MySubId 值的行数。 我有以下查询: SELECT MySubId, COU
我有两个具有多对多关系的类,因此我在它们之间创建了一个联接表(一个非常经典的示例!) 在java+hibernate中我想知道哪种方式更好?使用hibernate多对多注释在这两个类之间有多对多关系吗
我正在尝试创建一个 Android 应用程序来完成以下任务:它通过短信向一组收件人(存储在数组中的数字)发送初始调查问题。然后,对于收到的每个响应,它都会向该参与者发送该系列中的下一个问题。这是我做过
这里有一个关于 IncludeEventHandler 的有趣问题。 我正在开发一个基于 Spring 的应用程序,该应用程序使用具有单独投资组合站点的不同供应商的速度。我让供应商通过向他们提供存储在
我真的无法理解事件和委托(delegate)的概念。我知道委托(delegate)是持有方法引用的对象,可以调用具有相同返回类型和参数的方法,但事件到底是什么? 如果我需要使用事件来制作一个简单的计算
在我正在处理的一个项目中,我有一个扩展 JFrame 的主类(名为 TrackWin)。在此框架中,我使用 JTabbedPane。 用户可以从菜单栏在 Pane 中创建新选项卡。每当发生这种情况时,
我是一名优秀的程序员,十分优秀!