- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
所以我在 OpenGL ES 中生成了一个球体(具体来说,OpenGL ES 2.0,在 Java 中,适用于 Android)。当这个球体放置在与用于我的 View 矩阵的中心相同的位置时,它很好,但是当偏离中心时,球体会严重扭曲(见下文)。
为什么会发生这种情况,我该如何阻止它?
那是同一个球体。右上角的只是翻译成 x 和 y(不是 z)。
我实现 GLSurfaceView.renderer 的一些代码 fragment ,
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
GLES20.glEnable(GLES20.GL_CULL_FACE);
GLES20.glEnable(GLES20.GL_DEPTH_TEST);
// Both centred on (0,0,0), of radius 1.0.
outerSphere = new Sphere();
centreSphere = new Sphere();
}
public void onSurfaceChanged(GL10 unused, int width, int height) {
GLES20.glViewport(0, 0, width, height);
ratio = (float) width / height;
final float left = -ratio;
final float right = ratio;
final float bottom = -1.0f;
final float top = 1.0f;
final float near = 1.0f;
final float far = 100.0f;
Matrix.frustumM(projMatrix, 0, left, right, bottom, top, near, far);
}
public void onDrawFrame(GL10 unused) {
GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
float eyeX = 0.0f;
float eyeY = 0.0f;
float eyeZ = 10.0f;
final float lookX = 0.0f;
final float lookY = 0.0f;
final float lookZ = 0.0f;
final float upX = 0.0f;
final float upY = 1.0f;
final float upZ = 0.0f;
Matrix.setLookAtM(viewMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ,
upX, upY, upZ);
// Set identity matrix as input for translations.
Matrix.setIdentityM(outerModelMatrix, 0);
// Translate outer sphere by 5 in x and y.
Matrix.translateM(outerModelMatrix, 0, 5.0f, 5.0f, 0.0f);
// MVP matrix = Projection * View * Model.
Matrix.multiplyMM(centreMVPMatrix, 0, viewMatrix, 0, centreModelMatrix, 0);
Matrix.multiplyMM(centreMVPMatrix, 0, projectionMatrix, 0, centreMVPMatrix, 0);
Matrix.multiplyMM(outerMVPMatrix, 0, viewMatrix, 0, outerModelMatrix, 0);
Matrix.multiplyMM(outerMVPMatrix, 0, projectionMatrix, 0, outerMVPMatrix, 0);
outerSphere.draw(outerMVPMatrix);
centreSphere.draw(outerMVPMatrix);
}
我的着色器很简单,
private final static String vertexShaderCode =
"uniform mat4 u_MVPMatrix;" +
"attribute vec4 a_Position;" +
"uniform vec4 u_Color;" +
"void main() {" +
" gl_Position = u_MVPMatrix * a_Position;" +
"}";
private final static String fragmentShaderCode =
"precision mediump float;" +
"uniform vec4 u_Color;" +
"void main() {" +
" gl_FragColor = u_Color;" +
"}";
我几乎省略了 Sphere 类的所有代码,以及其他我认为不需要的东西(?),但如果需要它们,我会把它们放上去。
最佳答案
欢迎来到 perspective distortion 的世界!
更多细节:您的视野太窄,您必须调整平截头体的形状,使其更大一些。
关于android - (OpenGL ES) 远离 View 中心的对象被拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15457210/
我想创建一个随页面宽度变化的页眉。 我的标题由三部分组成,固定宽度的两侧和可拉伸(stretch)的中间部分。 我使用 displa
我正在尝试在导航栏下方创建一列内容,以便内容的宽度与导航栏的宽度完全匹配。事实证明这比我预期的要困难。 给定这样的东西: link
我有一个大小为 12*30 的字符串的图像。我想创建一个动画,让它给人一种拉伸(stretch)字符串的感觉。我通过缩放图像来做到这一点,但我面临的问题是缩放图像没有发生碰撞。它仅出现在原始图像大小的
在 Silverlight 中,如何拉伸(stretch) Line 的宽度以填充作为子元素的 StackPanel 的宽度?更喜欢 XAML 解决方案,而不是代码隐藏。这是我在 WPF 中的操作方法
QML 怎么可能?自动拉伸(stretch)元素以使其所有子元素都适合它?以及如何指定间距?例如,我想在文本周围有一个矩形。矩形应该有一些内部间距。 如果我写以下内容,则矩形的大小为 0,0。 Rec
我已经习惯了使用 matlab,现在正在尝试转换 matplotlib 和 numpy。 matplotlib 中是否有一种方法可以让您绘制的图像占据整个图形窗口。 import numpy as n
我有一个(简化的)2x2 网格,里面有三个控件。左控制在两行上延伸。
假设我有 3 个大小不匹配的列表,[3, 7, 6]、[12, 67, 89, 98] 和 [1, 2, 3, 4, 5, 6, 7]我想要一个函数来执行此操作: >>> stretch([3, 7,
如果 Image 被 Stretched,我可以获取 Height 和 Width 吗>UniformToFill? 我尝试了 Width 和 Height 属性,但它们始终是 NaN。 最佳答案 如
当我为微调器使用我自己的背景主题时,它是拉伸(stretch)图标。 我的微调器代码是: 我的 spinner.xml 是: 和我从 sdk 4 复制的图
我正在尝试在 OpenGL 中创建一个简单的 GUI。我创建了一张图片,以便我可以引用它并使解释更简单: 当我将按钮 (32x32) 的纹理应用到大小为 120x20 的四边形多边形(即不是矩形作为纹
SurfaceTexture 预览被拉伸(stretch)了!我正在开发一个 camera2 应用程序。每个设备都工作不好。视频和照片的预览被拉伸(stretch)。 public class Cam
我使用一些ImageButtons 创建了一个Android layout。我的布局在小屏幕(例如 3.6 英寸到 4.2 英寸)上运行良好,但是当我在 7 英寸或 9 英寸平板电脑上使用我的应用程序
我在拉伸(stretch) GridView 以适应显示宽度时遇到问题。任何人都知道如何解决这个问题?我希望 GridView 占据整个宽度,包括蓝色标记的字段(见下图)
我使用位图作为 Activity 的背景。自定义背景代码为: 但是它位于中间,并没有占据整个屏幕空间。我怎样才能让它填满所有可用空间?我尝试将宽度和高度设置为 fill_parent。 谢谢 最
所以我最近一直在为 iOS 开发应用程序,但遇到了一个难题。我正在制作一个迷你合成器,然后开始制作 GUI。我开始制作键盘(目前为 2 个 Octave )并测量了白键的大致长度。一切都很好,直到我在
好的,所以我在 slider 内有一个图像,但它不能正确缩放。 先小后伸,想一直伸到底,怎么实现? 看一下截图(忽略第二张截图中的红色部分): 还有CSS: .slider-wrapper {
我有下面的 HTML,我希望容器 div 拉伸(stretch)到窗口的整个高度。这对 wine 有效,但是当您移除容器内的两个蓝色 div 时会发生什么?容器延伸到其中蓝色 div 的底部,但不会延
我正尝试在 this example 之后制作背景,但我需要嵌套 2 个容器。 我的代码看起来像这样: XHTML:
这是关于用颜色填充背景。 我正在构建 this project 的 SwiftUI 版本.这是一个选项卡式应用程序(测试工具)。 This is my Working Project 我要做的第一件事
我是一名优秀的程序员,十分优秀!