小编Dar*_*ium的帖子

使用GLM正确旋转Open GL相机

我有一个相机类,它被初始化如下:

CameraFP::CameraFP()  {
    this->aspect_ratio = 800.0f / 600.0f;
    this->fov = 45.0f;
    this->near_plane = 0.1f;
    this->far_plane = 1000.0f;
    this->position = glm::vec3(0, 0, 0);
    this->target = position + glm::vec3(0, 0, -1);
    this->up = glm::vec3(0, 1, 0);
    this->m_rotation = glm::mat4(1.0);

    m_view = glm::lookAt(position, target, up);
    m_projection = glm::perspective(fov, aspect_ratio, near_plane, far_plane);
}
Run Code Online (Sandbox Code Playgroud)

以下是导入的其他功能:

void CameraFP::update(sf::Window *app)  {
    process_keyboard(app);
    process_mouse(app);

    calculate_view();
}

void CameraFP::process_keyboard(sf::Window *app)  {
    const sf::Input *input = &app->GetInput();

    up = m_rotation * glm::vec3(0, 1, 0);

    glm::vec3 forward = glm::vec3(0, 0, -1); …
Run Code Online (Sandbox Code Playgroud)

c++ opengl camera matrix glm-math

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

在Open GL 2.0和glm中创建第一人称相机

我对Open GL和c ++都很陌生,并且遇到了创建第一人称相机的问题.我不理解矩阵数学,所以这对我来说更加困难.到目前为止,为了计算相机的旋转,我已经为此做了:

void CameraFP::calculate_view()  {
    m_view = glm::rotate(m_view, this->get_rotation_x(), glm::vec3(1, 0, 0));
    m_view = glm::rotate(m_view, this->get_rotation_y(), glm::vec3(0, 1, 0));
}
Run Code Online (Sandbox Code Playgroud)

每次更新调用都会调用该函数.

为了通过mous处理相机的旋转,我做了以下工作:

void CameraFP::process_mouse(sf::Window *app)  {
    GLfloat mouse_x = app->GetInput().GetMouseX();
    GLfloat mouse_y = app->GetInput().GetMouseY();

    GLfloat mouse_x_delta = std::max(mouse_x, old_mouse_x) - std::min(mouse_x, old_mouse_x);
    GLfloat mouse_y_delta = std::max(mouse_y, old_mouse_y) - std::min(mouse_y, old_mouse_y);

    y_rot += mouse_x_delta / (float)app->GetWidth();
    x_rot += mouse_y_delta / (float)app->GetHeight();

    this->old_mouse_x = mouse_x;
    this->old_mouse_y = mouse_y;

    app->SetCursorPosition(app->GetWidth() / 2, app->GetHeight() / 2);
}
Run Code Online (Sandbox Code Playgroud)

为了处理运动,我做了以下事情:

void CameraFP::process_keyboard(sf::Window *app)  {
    const …
Run Code Online (Sandbox Code Playgroud)

c++ opengl matrix glm-math

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

在XNA中统一调整窗口大小

好吧,我试图让我的游戏窗口能够统一调整大小.我到处检查过,但我似乎无法找到任何关于它的信息.

有任何想法吗?

由于字符限制,我无法发布代码.非常感谢有人可以帮助我,看看我做错了什么:)

同样有用的是如何在发生这种情况时调整后备缓冲区的大小,因为我不认为只有一半精灵可见的游戏才可玩:)

   void Window_ClientSizeChanged( object sender, EventArgs e )
   {
       int new_width = graphics.GraphicsDevice.Viewport.Width;
       int new_height = graphics.GraphicsDevice.Viewport.Height;

       if (new_width != Variables.SCREEN_WIDTH)
       {
           Variables.SCREEN_HEIGHT = (int)(new_width * ascept_ratio);
           Variables.SCREEN_WIDTH = new_width;
       }
       if (new_height != Variables.SCREEN_HEIGHT)
       {
           Variables.SCREEN_WIDTH = (int)(new_height / ascept_ratio);
           Variables.SCREEN_HEIGHT = new_height;
       }

       UpdateParameters();
   }
Run Code Online (Sandbox Code Playgroud)

...

   public void UpdateParameters()
   {
       graphics.PreferredBackBufferWidth = Variables.SCREEN_WIDTH;
       graphics.PreferredBackBufferHeight = Variables.SCREEN_HEIGHT;
       graphics.ApplyChanges();
   }
Run Code Online (Sandbox Code Playgroud)

谢谢,

亲切的问候,Darestium

c# xna window

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

超级模糊纹理 - XNA

当我近距离观察纹理时,我似乎得到了非常模糊的纹理.我正在创建一个像Minecraft一样的地形的东西,我希望纹理像素化 - 就像它是制作而不是XNA尝试为我平滑它.

以下是它的显示方式:http://s1100.photobucket.com/albums/g420/darestium/?action = view¤t = bluryminecraftterrain.png

任何建议都会受到很多限制.

c# xna textures

2
推荐指数
1
解决办法
3614
查看次数

笛卡儿到极地(3d坐标)

如何在3D空间中的笛卡尔坐标系和极坐标系之间进行转换?最好用ac#例子,但是真的很感激.谢谢!

编辑 当考虑20%的变化时(不形成球体)

在此输入图像描述

编辑2

private void Spherise() {
        for (int i = 0; i < vertices.Count; i++) {
            float radius = this.radius;
            float longitude = 0;
            float latitude = 0;

            float sphereRadius = 32;

            Color color = vertices[i].Color;

            ToPolar(vertices[i].Position - centre, out radius, out longitude, out latitude);
            Vector3 position = ToCartesian(sphereRadius, longitude, latitude) + centre;

            Vector3 normal = vertices[i].Position - centre;
            normal.Normalize();

            const float lerpAmount = 0.6f;
            Vector3 lerp = (position - vertices[i].Position) * lerpAmount + vertices[i].Position;
            vertices[i] = new …
Run Code Online (Sandbox Code Playgroud)

c# xna cartesian polar-coordinates

2
推荐指数
1
解决办法
4615
查看次数

如何在vbs中发送"〜"字符

我正在创建一个VBScript,通过DOSBox自动执行我最喜欢的DOS游戏.由于DOS只支持8个字符的文件名,当我尝试挂载目录"C:\ Users\jordanh\Documents\DOS\Roms\INDIAN~3\INDY264"时,VBScript发送回车键而不是"~3\INDY264" ,如在VBS"〜"= {ENTER}.

任何想法如何发送"〜"字符而不是输入?

vbscript sendkeys

0
推荐指数
1
解决办法
1359
查看次数

错误,动态地将对象分配给数组

我有一个指向结构数组的指针,如下所示:

class Terrian  {
     ...
    private:
        Vector *terrian_vertices;
     ...
}
Run Code Online (Sandbox Code Playgroud)

并且指针的数据在"construct_vertices"函数中生成

Terrian::Terrian(int width, int height)  {
    this->width = width;
    this->height = height;

    std::cout << "Width: " << width << "  Height: " << height << "\n";

    std::cout << "Vertices\n";
    construct_vertices();
    std::cout << "Element\n";
    construct_elements();
    std::cout << "Buffers\n";
    construct_buffers();
}

void Terrian::construct_vertices()  {
    terrian_vertices = new Vector[width * height];

    std::cout << "Generating data\n";

    for (int x = 0; x < width; x++)  {
        for (int y = 0; y < height; …
Run Code Online (Sandbox Code Playgroud)

c++ dynamic dynamic-memory-allocation

0
推荐指数
1
解决办法
273
查看次数

四叉树程序引起的蓝屏死机

我正在为行星编写一个四叉树结构,当你远离四边形并接近它时,它会减少并增加细节.但是,我遇到了一些非常严重且烦人的错误.

我有两个预处理器定义的常量,当我将值更改为除32之外的任何值(例如16或64)时,确定Quad树的大小(QUAD_WIDTH和QUAD_HEIGHT)我得到一个蓝屏死机.我使用code :: blocks作为我的IDE,另外一件事:每当我尝试在code :: blocks中调试程序时,我也会得到一个蓝色的死亡屏幕(如果常量为32则无关紧要)

为什么会这样?我该如何解决呢? 在此输入图像描述 PQuad.cpp

#include "..\include\PQuad.h"
#include "..\include\Color3.h"

#include <iostream>
#include <vector>
#include <cmath>

#include <GL/glew.h>
#include <GL/glu.h>
#include <GL/gl.h>

#define QUAD_WIDTH 32
#define QUAD_HEIGHT 32

#define NUM_OF_CHILDREN 4

#define MAX_DEPTH 4

PQuad::PQuad(FaceDirection face_direction, float planet_radius)  {
    this->built = false;
    this->spherised = false;
    this->face_direction = face_direction;
    this->radius = planet_radius;
    this->planet_centre = glm::vec3(0, 0, 0);
}

PQuad::~PQuad()  {
}

std::vector<PQuad> PQuad::get_children()  {
    return children;
}

bool PQuad::get_built()  {
    return this->built;
}

int PQuad::get_depth()  {
    return this->depth;
} …
Run Code Online (Sandbox Code Playgroud)

c++ opengl bsod quadtree c-preprocessor

-1
推荐指数
1
解决办法
1014
查看次数