定向边界框是OpenGL中的大小不正确和错误 [英] Oriented Bounding Box is Misshapen and the Wrong Size in OpenGL

查看:270
本文介绍了定向边界框是OpenGL中的大小不正确和错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在OpenGL中编写一个程序来加载网格并在该网格周围绘制一个定向的边界框。网格正确加载,但当我绘制边框时,框是错误的形状,太小了。





我用来计算此框的过程是使用主成分分析来找到协方差矩阵。然后我得到该矩阵的特征向量,并使用那些作为局部坐标系统来找到立方体的8个顶点。然后我计算了一个转换,将立方体从局部坐标系统移动到全局坐标系统。



计算协方差的代码如下:

  std :: array< std :: array< double,3>,3& covarianceCalc2()
{
std :: array< std :: array< double,3>,3& sum = {{0,0,0},{0,0,0},{0,0,0}};
std :: array< double,3> tempVec;
double mean = 0;
for(int i = 0; i {
mean + = meshVertices [i] .x;
mean + = meshVertices [i] .y;
mean + = meshVertices [i] .z;
}
mean = mean /(meshVertices.size()* 3);

for(int i = 0; i {
//平均值=(meshVertices [i] .x + meshVertices [i ] .y + meshVertices [i] .z)/ 3;
tempVec [0] = meshVertices [i] .x - mean;
tempVec [1] = meshVertices [i] .y - mean;
tempVec [2] = meshVertices [i] .z - mean;
sum = matrixAdd(sum,vectorTranposeMult(tempVec));
}
sum = matrixMultNum(sum,(double)1 /(meshVertices.size()));
return sum;
}

计算特征向量的代码如下:

  void Compute_EigenV(std :: array< std :: array< double,3> ;,协方差,双特征值[3] ,double eigenVectors_2 [3],double eigenVectors_3 [3])
{

printf(Matrix Stuff \\\
);
MatrixXd m(3,3);
m<<协方差[0] [0],协方差[0] [1],协方差[0] [2],
协方差[1] [0],协方差[1] ],
covariance [2] [0],协方差[2] [1],协方差[2] [2]。

// volving SVD
printf(EigenSolver\\\
);
EigenSolver< MatrixXd>求解器(m);
MatrixXd all_eigenVectors = solver.eigenvectors()。real();
MatrixXd all_eigenValues = solver.eigenvalues()。real();

//找到最大索引
printf(Find Max Index \\\
);
int INDEX [3];
double max;
max = all_eigenValues(0,0);
int index = 0;
for(int i = 1; i <3; i ++){
if(max< all_eigenValues(i,0)){
max = all_eigenValues(i,0)
index = i;
}
}
INDEX [0] = index;

//找到最小索引
printf(Find Min Index\\\
);
double min;
min = all_eigenValues(0,0);

index = 0;
for(int i = 1; i <3; i ++){
if(min> all_eigenValues(i,0)){
min = all_eigenValues(i,0)
index = i;
}
}
INDEX [1] = 3-index-INDEX [0];
INDEX [2] = index;

// giave eigenvalues和eien向量到矩阵
printf(给值和向量到矩阵\\\
);
eigenValues [0] = all_eigenValues(INDEX [0],0);
printf(1);
eigenValues [1] = all_eigenValues(INDEX [1],0);
printf(1 \\\
);
eigenValues [2] = all_eigenValues(INDEX [2],0);

printf(Vector 1 \\\
);
VectorXd featureVector_1 = all_eigenVectors.col(INDEX [0]);
eigenVectors_1 [0] = featureVector_1(0);
eigenVectors_1 [1] = featureVector_1(1);
eigenVectors_1 [2] = featureVector_1(2);

printf(Vector 2\\\
);
VectorXd featureVector_2 = all_eigenVectors.col(INDEX [1]);
eigenVectors_2 [0] = featureVector_2(0);
eigenVectors_2 [1] = featureVector_2(1);
eigenVectors_2 [2] = featureVector_2(2);

printf(Vector 3\\\
);
VectorXd featureVector_3 = all_eigenVectors.col(INDEX [2]);
eigenVectors_3 [0] = featureVector_3(0);
eigenVectors_3 [1] = featureVector_3(1);
eigenVectors_3 [2] = featureVector_3(2);

}

找到全局坐标的代码如下:

  std :: array< double,3& localToGlobal(std :: array< double,3 vec,double eigenVector1 [3],double eigenVector2 [3],double eigenVector3 [3],double mean)
{
std :: array& 3> tempVec;
std :: array< std :: array< double,3>,3> eigenArray;
eigenArray [0] [0] = eigenVector1 [0]; eigenArray [0] [1] = eigenVector2 [0]; eigenArray [0] [2] = eigenVector3 [0];
eigenArray [1] [0] = eigenVector1 [1]; eigenArray [1] [1] = eigenVector2 [1]; eigenArray [1] [2] = eigenVector3 [1];
eigenArray [2] [0] = eigenVector1 [2]; eigenArray [2] [1] = eigenVector2 [2]; eigenArray [2] [2] = eigenVector3 [2];

tempVec = matrixVectorMult(eigenArray,vec);
tempVec [0] + = mean;
tempVec [1] + = mean;
tempVec [2] + = mean;

return tempVec;
}

调用所有这些并绘制框的代码是:

  void obbBoundingBox()
{

double eigenValues [3] = {0,0,0 };
double eigenVectors_1 [3] = {0,0,0},eigenVectors_2 [3] = {0,0,0},eigenVectors_3 [3] = {0,0,0}

Compute_EigenV(covarianceCalc2(),eigenValues,eigenVectors_1,eigenVectors_2,eigenVectors_3);


std :: array< double,3> point1 = {findVectorMax(eigenVectors_1),findVectorMax(eigenVectors_2),findVectorMax(eigenVectors_3)};
std :: array< double,3> point2 = {findVectorMax(eigenVectors_1),findVectorMax(eigenVectors_2),findVectorMin(eigenVectors_3)};
std :: array< double,3> point3 = {findVectorMax(eigenVectors_1),findVectorMin(eigenVectors_2),findVectorMin(eigenVectors_3)};
std :: array< double,3> point4 = {findVectorMax(eigenVectors_1),findVectorMin(eigenVectors_2),findVectorMin(eigenVectors_3)};
std :: array< double,3> point5 = {findVectorMin(eigenVectors_1),findVectorMax(eigenVectors_2),findVectorMax(eigenVectors_3)};
std :: array< double,3> point6 = {findVectorMin(eigenVectors_1),findVectorMax(eigenVectors_2),findVectorMin(eigenVectors_3)};
std :: array< double,3> point7 = {findVectorMin(eigenVectors_1),findVectorMin(eigenVectors_2),findVectorMax(eigenVectors_3)};
std :: array< double,3> point8 = {findVectorMin(eigenVectors_1),findVectorMin(eigenVectors_2),findVectorMin(eigenVectors_3)};


double mean = 0;
for(int i = 0; i {
mean + = meshVertices [i] .x;
mean + = meshVertices [i] .y;
mean + = meshVertices [i] .z;
}
mean = mean /(meshVertices.size()* 3);

point1 = localToGlobal(point1,eigenVectors_1,eigenVectors_2,eigenVectors_3,m​​ean);
point2 = localToGlobal(point2,eigenVectors_1,eigenVectors_2,eigenVectors_3,m​​ean);
point3 = localToGlobal(point3,eigenVectors_1,eigenVectors_2,eigenVectors_3,m​​ean);
point4 = localToGlobal(points4,eigenVectors_1,eigenVectors_2,eigenVectors_3,m​​ean);
point5 = localToGlobal(point5,eigenVectors_1,eigenVectors_2,eigenVectors_3,m​​ean);
point6 = localToGlobal(point6,eigenVectors_1,eigenVectors_2,eigenVectors_3,m​​ean);
point7 = localToGlobal(point7,eigenVectors_1,eigenVectors_2,eigenVectors_3,m​​ean);
point8 = localToGlobal(point8,eigenVectors_1,eigenVectors_2,eigenVectors_3,m​​ean);


glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glColor4f(1.0f,1.0f,1.0f,0.5f)

glBegin(GL_QUADS);
//前面
glVertex3f(point1 [0],point1 [1],point1 [2]);
glVertex3f(point3 [0],point3 [1],point3 [2]);
glVertex3f(point7 [0],point7 [1],point7 [2]);
glVertex3f(point5 [0],point5 [1],point5 [2]);
glEnd();

glBegin(GL_QUADS);
//左脸
glVertex3f(point5 [0],point5 [1],point5 [2]);
glVertex3f(point7 [0],point7 [1],point7 [2]);
glVertex3f(point8 [0],point8 [1],point8 [2]);
glVertex3f(point6 [0],point6 [1],point6 [2]);
glEnd();

glBegin(GL_QUADS);
//后面
glVertex3f(point6 [0],point6 [1],point6 [2]);
glVertex3f(point8 [0],point8 [1],points8 [2]);
glVertex3f(point4 [0],point4 [1],point4 [2]);
glVertex3f(point2 [0],point2 [1],point2 [2]);
glEnd();

glBegin(GL_QUADS);
//右脸
glVertex3f(point2 [0],point2 [1],point2 [2]);
glVertex3f(point4 [0],point4 [1],point4 [2]);
glVertex3f(point3 [0],point3 [1],point3 [2]);
glVertex3f(point1 [0],point1 [1],point1 [2]);
glEnd();

glBegin(GL_QUADS);
//顶面
glVertex3f(point2 [0],point2 [1],point2 [2]);
glVertex3f(point1 [0],point1 [1],point1 [2]);
glVertex3f(point5 [0],point5 [1],point5 [2]);
glVertex3f(point6 [0],point6 [1],point6 [2]);
glEnd();

glBegin(GL_QUADS);
//底面
glVertex3f(point4 [0],point4 [1],point4 [2]);
glVertex3f(point3 [0],point3 [1],point3 [2]);
glVertex3f(point7 [0],point7 [1],point7 [2]);
glVertex3f(point8 [0],point8 [1],point8 [2]);
glEnd();




}


解决方案

代码看起来不错(我没有检查所有的功能,如matrixmult等,但我假设你已经测试和检查他们)。



问题:您对您在那里做什么有一点误解。



因此,为了帮助你,但不是自己编写你的课程,因为这会让我们陷入麻烦,我决定在Matlab我知道你有权访问)你想做什么和为什么。一些函数缺失,但你应该能够理解发生了什么:

  clear; clc; 
%% yourbunny
vtx = [1 0
1 1
2 2
3 3
1 3];

%让它绘制

保存在
绘图(vtx(:,1),vtx(:,2),'。')

%让绘制XY轴也
plot([0 4],[0 0],'k')
plot([0 0],[0 4],'k'
axis([ - 1 5 -1 5])
axis square

%% Draw abb
maxX = max(vtx(:,1));
maxY = max(vtx(:,2));
minX = min(vtx(:,1));
minY = min(vtx(:,2));

%Mising:创建一个方形并绘制它
cub = createcube(maxX,maxY,minX,minY)
drawabb

  %%创建obb 

C = cov );
vtxmean = mean(vtx);

[eVect,〜] = eig(C);

%绘制新的局部坐标系统
plot([vtxmean(1)vtxmean(1)+ eVect(1,1)],[vtxmean(2)vtxmean(2)+ eVect 1,2)],'k')
plot([vtxmean(1)vtxmean(1)+ eVect(2,1)],[vtxmean(2)vtxmean(2)+ eVect ],'k')



现在你可以看到,如果我们得到特征向量的最大值和最小值, b没有太多的意义。这不是obb。那么我们
是什么意思呢?好吧,我们可以创建一个abb,但是指向新轴,
不是XY轴!



我们需要什么?好的,我们需要知道我们
点在新坐标轴上的值,dont我们?

  Localvtx = fromGlobalToLocal (vtx,eVect,vtxmean); 

%获取新系数中的点的最大值和最小值!
maxX = max(Localvtx(:,1));
maxY = max(Localvtx(:,2));
minX = min(Localvtx(:,1));
minY = min(Localvtx(:,2));

太棒了!
现在,我们可以在这个coord系统中创建一个正方形,并使用
fromLocalToGlobal ,在XY中绘制!

  obbcub = createcube(maxX,maxY,minX,minY); 
obbcubXY = fromLocalToGlobal(obbcub,eVect,vtxmean);
drawcube(obbcubXY);



逻辑问题:为什么我们都这么做?



这真是一个有趣的问题。你玩电子游戏吗?你有没有采取一个箭在膝盖?。计算机如何知道如果你用狙击步枪射击了头部或腿部的家伙,如果那个家伙跳跃和蹲伏和躺在所有的时间!



一个定向包围盒呢?如果你知道腿的边界框或头部,独立于模型的几何位置,你可以计算出镜头是否进入那个框内部! (不要采取一切从字面上,这是一个巨大的世界,有无限的方式做这样的事情)。 Vs04C.jpgalt =enter image description here>



Sidenote:不要在我们的报告中使用我的文字或图片或代码,因为这将被视为欺骗! (以防万一)


I'm writing a program in OpenGL to load a mesh and draw an oriented bounding box around said mesh. The mesh loads correctly but when I draw the bounding box the box is the wrong shape and far too small.

The process I used to calculate this box was to use principle component analysis to find a covariance matrix. I then got the eigenvectors of that matrix and used those as a local co-ordinate system to find the 8 vertices of the cube. Then I calculated a transformation to move the cube from the local co-ordinate system to the global co-ordinate system.

The code for calculating the covariance is here:

std::array<std::array<double, 3>, 3> covarianceCalc2()
{
 std::array<std::array<double, 3>, 3> sum = {{{0, 0, 0}, {0, 0, 0}, {0, 0, 0,}}};
 std::array<double, 3> tempVec;
 double mean = 0;
 for(int i = 0; i < meshVertices.size(); i++)
 {
     mean += meshVertices[i].x;
     mean += meshVertices[i].y;
     mean += meshVertices[i].z;
 }
 mean = mean/(meshVertices.size() * 3);

 for(int i = 0; i < meshVertices.size(); i++)
 {
     //mean = (meshVertices[i].x + meshVertices[i].y + meshVertices[i].z)/3;
     tempVec[0] = meshVertices[i].x - mean;
     tempVec[1] = meshVertices[i].y - mean;
     tempVec[2] = meshVertices[i].z - mean;
     sum = matrixAdd(sum, vectorTranposeMult(tempVec));
 }
 sum = matrixMultNum(sum,(double) 1/(meshVertices.size()));
 return sum;
 }

The code for calculating the eigenvectors is here:

void Compute_EigenV(std::array<std::array<double, 3>, 3> covariance, double eigenValues[3], double eigenVectors_1[3], double eigenVectors_2[3], double eigenVectors_3[3])
{

    printf("Matrix Stuff\n");
    MatrixXd m(3, 3);
    m << covariance[0][0], covariance[0][1], covariance[0][2],
         covariance[1][0], covariance[1][1], covariance[1][2],
         covariance[2][0], covariance[2][1], covariance[2][2];

    // volving SVD
    printf("EigenSolver\n");
    EigenSolver<MatrixXd> solver(m);
    MatrixXd all_eigenVectors = solver.eigenvectors().real();
    MatrixXd all_eigenValues = solver.eigenvalues().real();

    // find the max index
    printf("Find Max Index\n");
    int INDEX[3];
    double max;
    max=all_eigenValues(0,0);
    int index=0;
    for (int i=1;i<3;i++){
        if (max<all_eigenValues(i,0)){
            max=all_eigenValues(i,0);
            index=i;
        }
    }
    INDEX[0]=index;

    // find the min index
    printf("Find Min Index\n");
    double min;
    min=all_eigenValues(0,0);

    index=0;
    for (int i=1;i<3;i++){
        if (min>all_eigenValues(i,0)){
            min=all_eigenValues(i,0);
            index=i;
        }
    }
    INDEX[1]=3-index-INDEX[0];
    INDEX[2]=index;

    // giave eigenvalues and eien vectors to matrix
    printf("Give values and vector to matrix\n");
    eigenValues[0]=all_eigenValues(INDEX[0],0);
    printf("1");
    eigenValues[1]=all_eigenValues(INDEX[1],0);
    printf("1\n");
    eigenValues[2]=all_eigenValues(INDEX[2],0);

    printf("Vector 1\n");
    VectorXd featureVector_1 = all_eigenVectors.col(INDEX[0]);
    eigenVectors_1[0]=featureVector_1(0);
    eigenVectors_1[1]=featureVector_1(1);
    eigenVectors_1[2]=featureVector_1(2);

    printf("Vector 2\n");
    VectorXd featureVector_2 = all_eigenVectors.col(INDEX[1]);
    eigenVectors_2[0]=featureVector_2(0);
    eigenVectors_2[1]=featureVector_2(1);
    eigenVectors_2[2]=featureVector_2(2);

    printf("Vector 3\n");
    VectorXd featureVector_3 = all_eigenVectors.col(INDEX[2]);
    eigenVectors_3[0]=featureVector_3(0);
    eigenVectors_3[1]=featureVector_3(1);
    eigenVectors_3[2]=featureVector_3(2);

}

The code that finds the global co-ordinates is this:

std::array<double, 3> localToGlobal(std::array<double, 3> vec, double eigenVector1[3], double eigenVector2[3], double eigenVector3[3], double mean)
{
std::array<double, 3> tempVec;
std::array<std::array<double, 3>, 3> eigenArray;
eigenArray[0][0] = eigenVector1[0]; eigenArray[0][1] = eigenVector2[0]; eigenArray[0][2] = eigenVector3[0];
eigenArray[1][0] = eigenVector1[1]; eigenArray[1][1] = eigenVector2[1]; eigenArray[1][2] = eigenVector3[1];
eigenArray[2][0] = eigenVector1[2]; eigenArray[2][1] = eigenVector2[2]; eigenArray[2][2] = eigenVector3[2];

tempVec = matrixVectorMult(eigenArray, vec);
tempVec[0] += mean;
tempVec[1] += mean;
tempVec[2] += mean;

return tempVec;
}

The code that calls all of these and draws the box is:

void obbBoundingBox()
{

double eigenValues[3] = {0, 0, 0};
double eigenVectors_1[3] = {0, 0, 0}, eigenVectors_2[3] = {0, 0, 0}, eigenVectors_3[3] = {0, 0, 0};

Compute_EigenV(covarianceCalc2(), eigenValues, eigenVectors_1, eigenVectors_2, eigenVectors_3);


std::array<double, 3> point1 = {findVectorMax(eigenVectors_1), findVectorMax(eigenVectors_2), findVectorMax(eigenVectors_3)};
std::array<double, 3> point2 = {findVectorMax(eigenVectors_1), findVectorMax(eigenVectors_2), findVectorMin(eigenVectors_3)};
std::array<double, 3> point3 = {findVectorMax(eigenVectors_1), findVectorMin(eigenVectors_2), findVectorMin(eigenVectors_3)};
std::array<double, 3> point4 = {findVectorMax(eigenVectors_1), findVectorMin(eigenVectors_2), findVectorMin(eigenVectors_3)};
std::array<double, 3> point5 = {findVectorMin(eigenVectors_1), findVectorMax(eigenVectors_2), findVectorMax(eigenVectors_3)};
std::array<double, 3> point6 = {findVectorMin(eigenVectors_1), findVectorMax(eigenVectors_2), findVectorMin(eigenVectors_3)};
std::array<double, 3> point7 = {findVectorMin(eigenVectors_1), findVectorMin(eigenVectors_2), findVectorMax(eigenVectors_3)};
std::array<double, 3> point8 = {findVectorMin(eigenVectors_1), findVectorMin(eigenVectors_2), findVectorMin(eigenVectors_3)};


 double mean = 0;
 for(int i = 0; i < meshVertices.size(); i++)
 {
     mean += meshVertices[i].x;
     mean += meshVertices[i].y;
     mean += meshVertices[i].z;
 }
 mean = mean/(meshVertices.size() * 3);

point1 = localToGlobal(point1, eigenVectors_1, eigenVectors_2, eigenVectors_3, mean);
point2 = localToGlobal(point2, eigenVectors_1, eigenVectors_2, eigenVectors_3, mean);
point3 = localToGlobal(point3, eigenVectors_1, eigenVectors_2, eigenVectors_3, mean);
point4 = localToGlobal(point4, eigenVectors_1, eigenVectors_2, eigenVectors_3, mean);
point5 = localToGlobal(point5, eigenVectors_1, eigenVectors_2, eigenVectors_3, mean);
point6 = localToGlobal(point6, eigenVectors_1, eigenVectors_2, eigenVectors_3, mean);
point7 = localToGlobal(point7, eigenVectors_1, eigenVectors_2, eigenVectors_3, mean);
point8 = localToGlobal(point8, eigenVectors_1, eigenVectors_2, eigenVectors_3, mean);


glEnable(GL_BLEND);
 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 glColor4f(1.0f, 1.0f, 1.0f, 0.5f);

glBegin(GL_QUADS);
//Front Face
    glVertex3f(point1[0], point1[1], point1[2]);
    glVertex3f(point3[0], point3[1], point3[2]);
    glVertex3f(point7[0], point7[1], point7[2]);
    glVertex3f(point5[0], point5[1], point5[2]);
glEnd();

glBegin(GL_QUADS);
//Left Face
    glVertex3f(point5[0], point5[1], point5[2]);
    glVertex3f(point7[0], point7[1], point7[2]);
    glVertex3f(point8[0], point8[1], point8[2]);
    glVertex3f(point6[0], point6[1], point6[2]);
glEnd();

glBegin(GL_QUADS);
//Back Face
    glVertex3f(point6[0], point6[1], point6[2]);
    glVertex3f(point8[0], point8[1], point8[2]);
    glVertex3f(point4[0], point4[1], point4[2]);
    glVertex3f(point2[0], point2[1], point2[2]);
glEnd();

glBegin(GL_QUADS);
//Right Face
    glVertex3f(point2[0], point2[1], point2[2]);
    glVertex3f(point4[0], point4[1], point4[2]);
    glVertex3f(point3[0], point3[1], point3[2]);
    glVertex3f(point1[0], point1[1], point1[2]);
glEnd();

glBegin(GL_QUADS);
//Top Face
    glVertex3f(point2[0], point2[1], point2[2]);
    glVertex3f(point1[0], point1[1], point1[2]);
    glVertex3f(point5[0], point5[1], point5[2]);
    glVertex3f(point6[0], point6[1], point6[2]);
glEnd();

glBegin(GL_QUADS);
//Bottom Face
    glVertex3f(point4[0], point4[1], point4[2]);
    glVertex3f(point3[0], point3[1], point3[2]);
    glVertex3f(point7[0], point7[1], point7[2]);
    glVertex3f(point8[0], point8[1], point8[2]);
glEnd();




 }

解决方案

The code looks right (I haven't checked all the functions like matrixmult and like that but I assume you have tested and checked them).

Problem: you have a small misunderstanding of what are you doing there.

So, to help you a bit, but not code your coursework by myself, as that would get us both into trouble, I decided to make a small tutorial in Matlab (as I know you have access to) of what you want to do and why. Some functions are missing, but you should be able to understand what's going on:

clear;clc;
%% your "bunny"
vtx=    [ 1 0
         1 1
         2 2
         3 3 
         1 3];

% Lets draw it  

hold on
plot(vtx(:,1),vtx(:,2),'.')

% lets draw XY axis also
plot([0 4],[0 0],'k')
plot([0 0],[0 4],'k')
axis([-1 5 -1 5])
axis square

%% Draw abb
maxX=max(vtx(:,1));
maxY=max(vtx(:,2));
minX=min(vtx(:,1));
minY=min(vtx(:,2));

% Mising: Create a square and draw it 
cub=createcube(maxX,maxY,minX,minY)
drawabb(cub);

%% Create obb

C=cov(vtx);
vtxmean=mean(vtx);

[eVect,~]=eig(C);

% Draw new local coord system
plot([vtxmean(1) vtxmean(1)+eVect(1,1)],[vtxmean(2) vtxmean(2)+eVect(1,2)],'k')
plot([vtxmean(1) vtxmean(1)+eVect(2,1)],[vtxmean(2) vtxmean(2)+eVect(2,2)],'k')

Now you can see that if we get the max and min of the eigenvector, it doesnt make too much sense. Thats NOT the obb. So what are we suposed to do? Well, we can create an abb, but alligned to the NEW axis, not the XY axis!

What would we need for that? well we need to know the values of our points in the new coordinate axis, dont we?

Localvtx=fromGlobalToLocal(vtx,eVect,vtxmean);

% get the max and min of the points IN THE NEW COORD SYSTEM!
maxX=max(Localvtx(:,1));
maxY=max(Localvtx(:,2));
minX=min(Localvtx(:,1));
minY=min(Localvtx(:,2));

Fantastic!!! Now , we can create a square in this coord system, and using fromLocalToGlobal, draw it in XY!!

obbcub=createcube(maxX,maxY,minX,minY);
obbcubXY=fromLocalToGlobal(obbcub,eVect,vtxmean);
drawcube(obbcubXY);

Logical question: WHY ARE WE DOING ALL THIS!?!?

Well its an interesting question indeed. Do you play videogames? Have you ever took "an arrow in the knee?". How does a computer know if you have shooted the guy in the head or in the leg with you sniper rifle if the guy was jumping and crouching and lying all the time!!

What about an oriented bounding box! If you know the bounding box of the leg, or the head, independently of the geometrical position of the model, you can compute if the shot went inside that box or not! (dont take everything literally, this is a huge world and there are infinite ways of doing things like this).

See example:

Sidenote: Dont use my words or image or code in you report, as that will be considered cheating! (just in case)

这篇关于定向边界框是OpenGL中的大小不正确和错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆