天球上的星星的OpenGL视觉化。

时间:2022-09-10 18:40:17

I'm fairly new to OpenGL ES on iOS and have a pet project which is best described as essentially trying to create a more primitive version of the wonderful Stellarium on iOS.

我对iOS上的OpenGL ES很不熟悉,我有一个pet项目,最好的描述是尝试在iOS上创建一个更原始的版本。

I'm at a point where I managed to load approx. 9000 vertices (each representing a star's current position visible in the night sky), and by passing the correct model rotation matrices to the vertex shader, they move in real-time, according to the time of day and location of the user. In other words, the math is not the problem, neither is the basic setup of and EAGLView, various buffers and shader compilations etc, where I basically followed this tutorial by Ray Wenderlich.

我正在设法加载近似。9000个顶点(每个顶点表示夜空中可见的恒星当前位置),通过将正确的模型旋转矩阵传递给顶点着色器,它们根据用户的时间和位置实时移动。换句话说,数学不是问题,也不是基本的设置和EAGLView,各种缓冲区和着色器编译等等,在这里我基本上遵循了Ray Wenderlich的教程。

The vertex positions are calculated such that all of them are on the surface of an invisible sphere with arbitrary radius around position (0,0,0), simulating the night sky.

顶点位置的计算是这样的,所有的顶点都在一个不可见的球面上,任意半径的位置(0,0,0),模拟夜空。

Eventually, I'd like to be able to implement basic drag / pinch gestures to move the viewpoint of the observer (located at position 0,0,0) and "zoom" closer to the sphere to see more detail, such as star names.

最后,我希望能够实现基本的拖动/缩放手势,以移动观察者的视角(位于0,0,0)和“缩放”更接近球体,以查看更多细节,比如星星的名字。

The parts I struggle with are the following

下面是我挣扎的部分

1) Projection matrix: any expert advice around which projection to choose given the scene described above? I'm struggling to understand frustum, but think this is the way to go. How would I implement "zooming" closer?

1)投影矩阵:根据上面描述的场景,有什么专家建议可以选择投影吗?我一直在努力理解frustum,但我认为这是一种方法。如何实现“缩放”?

2) Shape of each star: Currently, this is a single vertex which yields a single dot on the screen. What's the best way to apply a star texture?

2)每个星星的形状:目前,这是一个单顶点,在屏幕上产生一个点。应用星形纹理的最好方法是什么?

3) There are eventually going to be some vertices in my array of vertices which are going to remain motionless, for example a celestial grid, showing azimuth and altitude, i.e. they should not be rotated like the stars. How can I apply a rotation matrix to some vertices, but not others? Can this be achieved by splitting glDrawElements() into several parts?

3)我的顶点数组中最终会有一些顶点会保持静止不动,比如一个天体网格,显示方位和高度,也就是说它们不应该像星星一样旋转。如何将旋转矩阵应用于某些顶点,而不是其他顶点?可以将glDrawElements()分解成几个部分来实现吗?

1 个解决方案

#1


1  

  1. Projection matrices are frequently calculated with a helper function. For example, gluPerspective. If you'd like to implement zooming, you can adjust the FOV (smaller/larger values will zoom in/out). Frequently, zooming is also implemented by modifying the view matrix (again, generally calculated with a helper function), it's up to you which method (or combination) you go with.

    投影矩阵通常用辅助函数来计算。例如,gluPerspective。如果您想实现缩放,可以调整FOV(较小/较大的值将放大/缩小)。通常,缩放也是通过修改视图矩阵来实现的(同样,通常用辅助函数来计算),这取决于您使用的方法(或组合)。

  2. To apply a texture, GL has a special fragment shader input variable called gl_PointCoord, which can be used to easily map a texture across a GL_POINT primitive (see GL ES 2.0 spec, section 3.3 'points'). You could also write a geometry shader, that will transform the points into quads, and write a 'standard' fragment shader - although that is likely much more work.

    要应用纹理,GL有一个特殊的片段着色输入变量gl_PointCoord,它可以用来轻松地在GL_POINT原语中映射纹理(参见GL ES 2.0规范第3.3节“point”)。您还可以编写一个几何着色器,将这些点转换为四元组,并编写一个“标准”碎片着色器——尽管这可能需要更多的工作。

  3. It's likely easier to split geometry that will be processed with different uniform data (eg. model/view/projection matrices) into separate draw calls. This is in general how most game engines render objects, except when the expected number of draw calls grows large, and then they frequently implement some sort of batched drawing. However, if you only have two sets, that should not be a large concern.

    使用不同的统一数据处理的几何图形可能更容易拆分(例如)。模型/视图/投影矩阵)进入单独的绘制调用。这通常是大多数游戏引擎渲染对象的方式,除非预期的绘制调用数量增加,然后它们经常实现某种批处理绘图。但是,如果您只有两个集合,那就不应该引起很大的关注。

#1


1  

  1. Projection matrices are frequently calculated with a helper function. For example, gluPerspective. If you'd like to implement zooming, you can adjust the FOV (smaller/larger values will zoom in/out). Frequently, zooming is also implemented by modifying the view matrix (again, generally calculated with a helper function), it's up to you which method (or combination) you go with.

    投影矩阵通常用辅助函数来计算。例如,gluPerspective。如果您想实现缩放,可以调整FOV(较小/较大的值将放大/缩小)。通常,缩放也是通过修改视图矩阵来实现的(同样,通常用辅助函数来计算),这取决于您使用的方法(或组合)。

  2. To apply a texture, GL has a special fragment shader input variable called gl_PointCoord, which can be used to easily map a texture across a GL_POINT primitive (see GL ES 2.0 spec, section 3.3 'points'). You could also write a geometry shader, that will transform the points into quads, and write a 'standard' fragment shader - although that is likely much more work.

    要应用纹理,GL有一个特殊的片段着色输入变量gl_PointCoord,它可以用来轻松地在GL_POINT原语中映射纹理(参见GL ES 2.0规范第3.3节“point”)。您还可以编写一个几何着色器,将这些点转换为四元组,并编写一个“标准”碎片着色器——尽管这可能需要更多的工作。

  3. It's likely easier to split geometry that will be processed with different uniform data (eg. model/view/projection matrices) into separate draw calls. This is in general how most game engines render objects, except when the expected number of draw calls grows large, and then they frequently implement some sort of batched drawing. However, if you only have two sets, that should not be a large concern.

    使用不同的统一数据处理的几何图形可能更容易拆分(例如)。模型/视图/投影矩阵)进入单独的绘制调用。这通常是大多数游戏引擎渲染对象的方式,除非预期的绘制调用数量增加,然后它们经常实现某种批处理绘图。但是,如果您只有两个集合,那就不应该引起很大的关注。