English 中文(简体)
如何轮流,然后朝这一方向前进?
原标题:How to rotate and then move on that direction?
  • 时间:2010-11-26 20:29:11
  •  标签:
  • c++
  • opengl

然而,我目前正在尝试让第一手游戏。 能够做的是利用功能gluLookAt()进行照相移动,并使用冰川进行轮换。 我试图做的是更换摄像机,然后朝轮机的方向前进,但轴心保持不变,尽管我已经轮换了照相机。 谁能帮助我? 这是我的法典:

glMatrixMode(GL_MODELVIEW);   
glLoadIdentity();   
glRotatef(cameraPhi,1,0,0);   
glRotatef(cameraTheta,0,1,0);
gluLookAt(move_camera.x,move_camera.y,move_camera.z,move_camera.x,move_camera.y,move_camera.z-10,0,1,0);
drawSkybox2d(treeTexture);
最佳回答

这就需要一种病媒的数学。

鉴于这些职能,行动非常简单,因为:

vec rotx(vec v, double a)
{
    return vec(v.x, v.y*cos(a) - v.z*sin(a), v.y*sin(a) + v.z*cos(a));
}

vec roty(vec v, double a)
{
    return vec(v.x*cos(a) + v.z*sin(a), v.y, -v.x*sin(a) + v.z*cos(a));
}

vec rotz(vec v, double a)
{
    return vec(v.x*cos(a) - v.y*sin(a), v.x*sin(a) + v.y*cos(a), v.z);
}

假设您的定向矢量被定义为{CameraPhi,照相机,0.0},那么,如果你想把照相机向病媒诉照相轴方向移动,则在照相机位置上添加:

p += v.x*roty(rotx(vec(1.0, 0.0, 0.0), CameraPhi), CameraTheta) +
     v.y*roty(rotx(vec(0.0, 1.0, 0.0), CameraPhi), CameraTheta) +
     v.z*roty(rotx(vec(0.0, 0.0, 1.0), CameraPhi), CameraTheta);

And that should do it. Keep Coding :)

问题回答

www.un.org/Depts/DGACM/index_spanish.htm

void gluLookAt(GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ,
               GLdouble centerX, GLdouble centerY, GLdouble centerZ,
               GLdouble upX, GLdouble upY, GLdouble upZ
              );

该摄像机位于eye阵地,从eye>>>>查询。

。 共同界定了照相机轴(方向),第三份矢量代码<>up界定了该轴线的轮换。

You don t need the separate phi and theta rotations, just pass in the correct up vector to get the desired rotation. (0,1,0) means the camera is upright, (0,-1,0) means the camera is upside-down and other vectors define intermediate positions.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签