我想知道,还有什么其他的东西(例如3D引擎)我必须学习如何创建像Mafia 2或GTA IV这样的游戏.
我有一个球,我必须从一个高度下降它应该表现,因为它在现实世界的行为意味着它应该下降与g = 9.8并且还反弹.任何人告诉我如何在开放的gl中做到这一点C++?
可能重复:
浮点比较
嗯,这是一个奇怪的.通常以下if( 4.0 == 4.0 ){return true}将永远返回true.在一个简单的小型opengl 3d'射手'程序中,当我试图添加"跳跃"效果时,情况并非如此.
这个想法相当简单,我有一个三角形条带的地形,因为"角色"移动/走动你沿着一个2d阵列的高度移动,因此你在山丘/低谷的各个高度上下走动.
在drawScene()函数之外(或者如果你知道opengl,那么glutDisplayFunc()),我有一个update()函数,当他'跳'时,它会上升和下调字符,这就是调用drawScene().用语言来说,我可以解释它的高级别,跳跃算法如下:
参数:
double currentJumpingHeight
double maximumJumpingHeight = 4.0
double ypos;
const double jumpingIncrement = 0.1; //THE PROBLEM!!!! HAS TO BE A MULTIPLE OF 0.5!!
bool isJumping = false;
bool ascending = true;
Run Code Online (Sandbox Code Playgroud)
算法:
(when space is pressed) isJumping = true.
if ascending = true and isJumping = true,
currentJumpHeight += jumpingIncrement (and the same for ypos)
if currentJumpingHeight …Run Code Online (Sandbox Code Playgroud) 我写的OpenGL代码有一个奇怪的错误.作为测试,我正在创建一个球体矢量并使用push_back(s1).我在向量中添加了多个球体.但是,当我运行程序时,它只绘制最近被推入向量的球体.
#include "Sphere.h";
#include <iostream>;
#include <vector>;
using namespae std;
vector<Sphere> spheres;
Sphere s1 = Sphere(1.0, "One");
Sphere s2 = Sphere(2.0, "Two");
Sphere s3 = Sphere(3.0, "Three");
void init(void) {
spheres.push_back(s1);
spheres.push_back(s2);
spheres.push_back(s3);
for each(Sphere s in spheres) {
cout << s.getName() << "\n";
}
}
// OTHER CODE OMMITED
void display(void) {
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 0.0);
glPushMatrix();
for each(Sphere in s) {
s.draw();
}
glPopMatrix();
}
Run Code Online (Sandbox Code Playgroud)
显然有一个主要的方法,所有GL的东西都设置好了,我知道那里没有问题.
因此球体有自己的绘制方法.现在有趣的部分是在控制台输出:
Three
Three
Three
Run Code Online (Sandbox Code Playgroud)
并继续绘制s3,三次到屏幕.
所以我的问题是:为什么它只在向量中绘制最后一项三次?我也尝试使用迭代器和普通for循环,但它们都产生相同的结果.
有人有想法吗?
EDITS
getName()函数:
string Sphere::getName() { …Run Code Online (Sandbox Code Playgroud) 我正在尝试编译一个程序(在OpenGL中)Ubuntu,但是我收到了这个错误
fatal error: common.h: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我不确定我需要为此安装哪个软件包.
我的python代码不会运行!?
我不知道如何解决这个问题.有人可以帮帮我吗?
错误:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\OpenGL\GLUT\special.py", line 120, in safeCall
return function( *args, **named )
File "C:/Users/zera7777/Desktop/New.py", line 106, in testCyrusBeck
numpy = point2Array([[0,3],[0,6],[4,6],[6,4],[6,0],[3,0]])
TypeError: 'list' object is not callable
GLUT Idle callback <function testCyrusBeck at 0x02AD8F30> with (),{} failed: returning None 'list' object is not callable
Run Code Online (Sandbox Code Playgroud)
代码:
from OpenGL.GL import *
from OpenGL.GLU import *
from OpenGL.GLUT import *
class Line2Segment(object):
def Vector2(self):
Vector2=norm()
Vector2.c = second - first
Vector2.normalVector = c.GetNormalVector()
return normalVector
def …Run Code Online (Sandbox Code Playgroud) 我想了解如何在 OpenGL 中跟踪移动对象。对象的位置将是连续输入。另外,如果对象移出屏幕怎么办?
我导入了一个由多个网格组成的FBX模型.不幸的是,我无法将每个网格显示在正确的位置.对于每个网格,我将网格的几何变换与网格的局部变换相乘,然后将其传递给着色器.我该如何解决这个问题?
gl_Position = modelViewProjectionMatrix *TransformationMatrix*vertexPositionsOfMesh;
Run Code Online (Sandbox Code Playgroud)
GLKMatrix4 LcLTransformation = createTransformationMatrix(
Mesh->LclRotation,
Mesh->LclScaling,
Mesh->LclTranslation);
GLKMatrix4 GeoTransformation = createTransformationMatrix(
Mesh->GeometricRotation,
Mesh->GeometricScaling,
Mesh->GeometricTranslation);
TransformationMatrix=GLKMatrix4Transpose(GLKMatrix4Multiply(LcLTransformation,
GeoTransformation));
Run Code Online (Sandbox Code Playgroud)
GLKMatrix4 createTransformationMatrix(float* _rotation, float* _scaling, float* _translation)
{
GLKMatrix4 Rx = GLKMatrix4Make(1, 0, 0, 0,
0, cos(_rotation[0]), -sin(_rotation[0]), 0,
0, sin(_rotation[0]), cos(_rotation[0]), 0,
0, 0, 0, 1
);
GLKMatrix4 Ry = GLKMatrix4Make(cos(_rotation[1]), 0, sin(_rotation[1]), 0,
0, 1, 0, 0,
-sin(_rotation[1]), 0, cos(_rotation[1]), 0,
0, 0, 0, 1
);
GLKMatrix4 Rz = GLKMatrix4Make(cos(_rotation[2]), -sin(_rotation[2]), 0, 0,
sin(_rotation[2]), …Run Code Online (Sandbox Code Playgroud)