[英]Setting OpenGL ES maximum distance on Android
在OpenGL ES中,如何指定最大可見距離? 我發現當我這樣做時:
gl.glTranslatef(0,0,-10f);
我繪制的所有內容都不可見,因為它離相機太遠了。 我如何指定它應該把東西拉得更遠?
解決您的問題HappyEngineer的方法只是簡單地修改靜態GLU.gluPerspective()方法。 這是我在項目(我也在學習)中用於渲染簡單多維數據集(只是視圖設置代碼)的代碼:
public void onSurfaceChanged(GL10 gl, int width, int height)
{
//Reset The Projection Matrix
Log.v("Home", String.valueOf(height));
gl.glViewport(0, 0, width, height); //Reset The Current Viewport
gl.glMatrixMode(GL10.GL_PROJECTION); //Select The Projection Matrix
gl.glLoadIdentity();
//Calculate The Aspect Ratio Of The Window
GLU.gluPerspective(gl, 45.0f, (float)width / (float)height, 0.1f, 1000.0f);
gl.glMatrixMode(GL10.GL_MODELVIEW); //Select The Modelview Matrix
gl.glLoadIdentity();
}
因此,即使您不熟悉GL,如果您具有3D背景知識,那么這些函數的名稱+參數也應該很明顯。 對於感興趣的功能gluPerspective,您正在傳遞對GL實例的引用,FOV或視場的角度,長寬比,然后是遠平面或最大視距。 為了讓您了解使用此代碼的上下文,我在onSurfaceChanged事件中的GLWallpaperService(GL LiveWallpaper)內部使用了它。 有關此內容的更多nfo,請參見以下內容:
http://mindtherobot.com/blog/376/android-ui-making-a-live-wallpaper-fire-simulation/
http://www.rbgrn.net/content/354-glsurfaceview-adapted-3d-live-wallpapers
還有一些在droid上使用glES的不錯的教程:
http://blog.jayway.com/2009/12/03/opengl-es-tutorial-for-android-part-i/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.