游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2641|回复: 0

一个3d点与立方体素12条边的位置关系的函数看不太懂

[复制链接]

11

主题

80

帖子

146

积分

注册会员

Rank: 2

积分
146
发表于 2011-7-15 09:41:00 | 显示全部楼层 |阅读模式
///
//        test()
//
//         Which of the twelve edge plane(s) is point P outside of?
//
static
int test(vector3 p)
{
        int outcode;

        outcode = 0;
        if ( p.x + p.y > 1.0) outcode |= 0x001;
        if ( p.x - p.y > 1.0) outcode |= 0x002;
        if (-p.x + p.y > 1.0) outcode |= 0x004;
        if (-p.x - p.y > 1.0) outcode |= 0x008;
        if ( p.x + p.z > 1.0) outcode |= 0x010;
        if ( p.x - p.z > 1.0) outcode |= 0x020;
        if (-p.x + p.z > 1.0) outcode |= 0x040;
        if (-p.x - p.z > 1.0) outcode |= 0x080;
        if ( p.y + p.z > 1.0) outcode |= 0x100;
        if ( p.y - p.z > 1.0) outcode |= 0x200;
        if (-p.y + p.z > 1.0) outcode |= 0x400;
        if (-p.y - p.z > 1.0) outcode |= 0x800;
        return(outcode);
}
//在这个函数中的12个条件表达式应该就是用来测试点和立方体素12条边的位置,关系。不过我还是没懂背后的数学原理是
怎样的 比如p.x+p.y>1.0 是怎么来的? 请高手指点
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-5-14 23:19

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表