小编use*_*679的帖子

倾斜的平截头体/离轴投影用于OpenGL中的头部跟踪

我正在尝试在我的应用程序中进行离轴投影,并尝试根据用户的头部位置更改场景的视角.通常情况下,鉴于我必须在屏幕上画一个方框,我会在屏幕上画一个方框:

ofBox(350,250,0,50); //ofBox(x, y, z, size); where x, y and z used here are the screen coordinates
Run Code Online (Sandbox Code Playgroud)

要在这里进行离轴投影,我知道我必须更改透视投影,如下所示:

vertFov = 0.5; near = 0.5; aspRatio = 1.33;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(near * (-vertFov * aspRatio + headX),
          near * (vertFov * aspRatio + headX),
          near * (-vertFov + headY),
          near * (vertFov + headY),
          near, far); //frustum changes as per the position of headX and headY
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(headX * headZ, headY * headZ, 0, headX * headZ, headY * headZ, …
Run Code Online (Sandbox Code Playgroud)

c++ opengl 3d openframeworks

7
推荐指数
1
解决办法
4161
查看次数

MVC控制器和业务逻辑之间的区别(3层)

我一直试图在ASP.NET中找到MVC和3层架构之间的差异.我之前提到过一些先前的问题和一些页面,但可以找到一个明确的答案.
这是一个关于MVC实现的msdn页面:http://msdn.microsoft.com/en-us/library/ff647462.aspx

考虑一下,我这个代码:
单页面的aspx UI和代码

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<html>
   <head>
      <title>start</title>
      <script language="c#" runat="server">
         void Page_Load(object sender, System.EventArgs e)
         {
            String selectCmd = "select * from Recording";

            SqlConnection myConnection = 
               new SqlConnection(
                  "server=(local);database=recordings;Trusted_Connection=yes");
            SqlDataAdapter myCommand = new SqlDataAdapter(selectCmd, 
               myConnection);

            DataSet ds = new DataSet();
            myCommand.Fill(ds, "Recording");

            recordingSelect.DataSource = ds;
            recordingSelect.DataTextField = "title";
            recordingSelect.DataValueField = "id";
            recordingSelect.DataBind();
         }
       </script>
   </head>
   <body>
         <asp:dropdownlist id="recordingSelect" runat="server" />
         <asp:button runat="server" text="Submit" OnClick="SubmitBtn_Click" />
      </form>
   </body>
</html> …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc 3-tier

6
推荐指数
2
解决办法
4904
查看次数

使用glFrustum创建拼接场景

我有一个程序,我可以根据用户的位置在屏幕上进行场景渲染.当用户改变位置时,平截头体变为给出轴外投影.我想利用这种技术在三个不同的显示器上拼接一个更大的场景,具有以下类型:

在此输入图像描述 想象一下在三个显示器上呈现的大型真实世界场景.三个显示器应该显示场景,因为它将根据用户的位置在每个显示器上以改变的透视图显示.我可以使用一个显示器来根据用户的位置渲染场景,但无法想到在三个屏幕上工作的方法.

我创建的类离轴投影基本上执行以下操作:

customCam::project(){
pushMatrices();
glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
        glFrustum(leftNear.x, rightNear.x, bottomNear.y, topNear.y, _near, _far);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(uPos.x, uPos.y, 0, uPos.x, uPos.y, -1, 0, 1, 0); //neglect z scaling for now. In the main program, it's there
    glTranslatef(0, 0, uPos.z);
}
Run Code Online (Sandbox Code Playgroud)

我如何以这样一种场景看待三个截头锥体,使得场景看起来像在现实世界中一样连续?目前,该类的用户绘制如下场景:

cstCam.project();
    //draw something here
popMatriceS(); //which were pushed before glFrustum projection
Run Code Online (Sandbox Code Playgroud)

编辑: 在我的情况下,为用户定义三个截头锥体(考虑到相同参考框架中所有显示的accoutn用户和屏幕角),我做了以下内容:

custCam1.project();
//draw scene here. eg: two walls at the far left and right screen
drawWalls();
popMatrices();
custCam2.project();
drawWalls();
popMatrices();
custCam3.project();
drawWalls();
popMatrices();

void drawWalls(){
//Left most corner …
Run Code Online (Sandbox Code Playgroud)

c++ opengl algorithm 3d graphics

6
推荐指数
1
解决办法
295
查看次数

使用glFrustum进行轴外投影

我正在尝试使用OpenGL对场景进行离轴投影,并且我将文档读取到了Robert Kooima的离轴投影,现在对于实际需要做的事情有了更好的想法,但仍然有一些部分我觉得这里很棘手.我知道OpenGL的离轴投影代码有点如下:

代码1:

glMatrixMode(GL_PROJECTION);  
    glLoadIdentity();            
    glFrustum(fNear*(-fFov * ratio + headX),  
              fNear*(fFov * ratio + headX),  
              fNear*(-fFov + headY),  
              fNear*(fFov + headY),  
              fNear, fFar);  
          
    glMatrixMode(GL_MODELVIEW);  
    glLoadIdentity();  
    gluLookAt(headX*headZ, headY*headZ, 0, headX*headZ, headY*headZ, -1, 0, 1, 0);
    glTranslatef(0.0,0.0,headZ);
Run Code Online (Sandbox Code Playgroud)

如果这是用户位于屏幕中心的正常透视投影,那么我理解的内容相当容易理解.

               Screen  
                   |
                   |  h = H/2
                   |  
x----- n -----------
                   |
                   |  h = H/2
                   |
Run Code Online (Sandbox Code Playgroud)

当用户在x处并且距离屏幕的距离为n时,glFrustum的顶部,底部坐标将被计算为:(假设theta是视野(fov),我认为假设为30度)

h = n * tan (theta/2);
tanValue = DEG_TO_RAD * theta/2;
[EDIT Line additon here>>]: fFov = tan(tanValue);
h …
Run Code Online (Sandbox Code Playgroud)

c++ opengl algorithm 3d openframeworks

5
推荐指数
1
解决办法
1890
查看次数

无法在类中初始化静态地图

我正在尝试
map<string, int>
在我的程序中初始化一个静态映射,如下所示:

测试应用程序

class testApp(){
public:
void setup();
void update();
void renew();
static map<string, int> _someMap;
};
Run Code Online (Sandbox Code Playgroud)

测试应用程序

testApp::setup(){
   _someMap["something"] = 1;
   _someMap["something2"] = 2;
cout<<_someMap["something"]<<"\n";
}
Run Code Online (Sandbox Code Playgroud)

我不想boost使用 map 的这种短暂使用并为我的代码添加源依赖项。我不在,C++11而且程序中没有构造函数,因为该类是某个框架的类。我在 Xcode 上执行上述操作时.cpp,出现以下错误:

Undefined symbols for architecture i386:
  "testApp::mapppp", referenced from:
      testApp::setup() in testApp.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)

-->另外,假设我的地图是私有的,为此我尝试在课堂上这样做:

...
private:
static someVariable;
static void someFunction(); …
Run Code Online (Sandbox Code Playgroud)

c++ static map

5
推荐指数
1
解决办法
3144
查看次数

或JavaScript对象声明的符号

我刚刚开始阅读一些JavaScript项目.大多数开头的.js文件都有一个声明如下的对象:

window.Example || {
bleh: "123";
blah: "ref"
}
Run Code Online (Sandbox Code Playgroud)

||符号在这做什么?

javascript

4
推荐指数
1
解决办法
361
查看次数

将切换按钮绑定到两个命令

我在silverlight应用程序中有一个切换按钮,如下所示:

<ToggleButton Content="ToggleButton" Margin="0,30,0,0" Style="{StaticResource ChkToggleButton}" />
Run Code Online (Sandbox Code Playgroud)

切换当前正在改变切换的视觉状态,仅此而已.
但是,我需要使用不同的命令绑定每个切换.例如:按下按钮1,command1再次按下运行和按钮,运行command2.

如何才能做到这一点?

c# silverlight wpf xaml

4
推荐指数
1
解决办法
3791
查看次数

获取glFrustum的坐标

我刚开始阅读有关OpenGL主题的内容,特别是关于Viewing我目前的需求.我试图理解glFrustum我在屏幕上绘制的对象的透视投影,据我所知,glFrustum这将使更远的对象比更近的对象更小.
我在openFrameworks这里用于绘制Image/ Box等等对象.这里是我想要做的简短示例:

openFrameworks绘制方法

draw()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 3.0, 500.0);
glMatrixMode(GL_MODELVIEW);

sceneImage.draw(0,0,ofGetWidth(), ofGetHeight()); //draw an image on the screen with window's width and dheight 
}
Run Code Online (Sandbox Code Playgroud)

使用上面的glFrustum,我只是想剪辑图像并查看图像的特定部分进行初始测试.glFrustum即使我glFrustum从红皮书的上述链接中读到这些论点,我也不确定这些论点究竟是什么.当然left, right, bottom, top, near, far,论点是,但是如何计算1.0或被1.0计算?我期待屏幕坐标进入并尝试了类似glFrustum(100, 984, 100, 668,3, 500)但屏幕上没有任何内容.如何glFrustum计算这些论点?

c++ opengl algorithm openframeworks

4
推荐指数
1
解决办法
8407
查看次数

设置不对称的截头体

我有一个程序,我在其中跟踪用户的位置并设置视锥体(将相机设置在用户的位置)以根据用户的位置更改场景的视角.直到现在,我将显示屏的所有四个角都放在同一个z上,我能够根据用户的视角设置不对称平截头体并改变场景.

当前代码如下所示:

UserCam::begin(){
    saveGlobalMatrices();  
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
        glFrustum(_topLeftNear.x, _bottomRightNear.x, _bottomRightNear.y, _topLeftNear.y, _camZNear, _camZFar);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    gluLookAt(_wcUserHead.x, _wcUserHead.y, _topLeftScreen.z, _wcUserHead.x, _wcUserHead.y, _topLeftScreen.z-1, 0, 1, 0);
}

UserCam::end(){
loadGlobalMatrices();
}

UserCam::setupCam(){
    this->_topLeftScreen = _wcTopLeftScreen - _wcUserHead; //wcTopLeftScreen, wcBottomRightScreen and wcUserHead are in the same frame of reference
    this->_bottomRightScreen = _wcBottomRightScreen - _wcUserHead;

    this->_topLeftNear = (_topLeftScreen/ _topLeftScreen.z) * _camZNear;
    this->_bottomRightNear = (_bottomRightScreen/_bottomRightScreen.z )) * _camZNear;
}
Run Code Online (Sandbox Code Playgroud)

但是,我希望能够对显示器做同样的事情,该显示器保持倾斜于用户和/或没有相同的所有顶点Z.

在此输入图像描述 以上可以想象为一种倾斜窗口,其顶点将具有从用户位置定义的平截头体.如果显示器没有所有顶点,那么这种平截头体怎么可能Z呢?

编辑
我正在考虑的设置中有三个平面.中间的一个给出正确的不对称平截头体,因为所有顶点都在同一个Z,而左和右平面有两个顶点,每个顶点在不同的Z.它们的顶点如下:

Plane1: TL : (-426.66, 0, 200), TR: (0, 0, 0), …
Run Code Online (Sandbox Code Playgroud)

c++ opengl algorithm 3d

4
推荐指数
1
解决办法
2215
查看次数

防止指针的双重删除

我在我的程序中有一个vector<Points*> points;(size: 6有所有独特的Points),其中我迭代通过点在屏幕上绘制一些东西.但是,根据我的新要求,我要将向量的长度增加到size: 14.

要添加的新项目必须来自之前的6 Points,所以我没有分配新的内存,而是考虑使用前面的指针,如下所示:

while (currentSize < 14){
  int rndPoint = getRandomPoint(0, 5); //random index to choose from the vector
  points->push_back(points[randPoint]);
}
Run Code Online (Sandbox Code Playgroud)

在类的析构函数中,当我要释放内存时,我正在执行以下操作:

for(int i=0;i<points.size(); ++i){
  if(points[i] != NULL){
    delete (points[i]);
  }
}
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试退出程序时 - 我在循环中遇到访问冲突错误(特别是在i达到索引时6).当我已经用删除的6个独特点delete,为什么是条件if (points[i] != NULL)造成truei=6,7...13

c++ algorithm pointers memory-management

3
推荐指数
1
解决办法
438
查看次数