In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "Android how to create a projection and a camera view", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Android how to create a projection and a camera view" bar!
In the OpenGL ES environment, projections and camera views make the painted objects appear closer to the physical objects that people see with the naked eye. This simulation technology is realized by accurate mathematical transformation of the coordinates of the drawing object.
Projection: this transformation adjusts the coordinates of the drawing object according to the width and height of the GLSurfaceView.
Without this transformation, the object will be distorted by an irregular scale view.
Usually a projection transformation is calculated only when the onSurfaceChange () method of creating OpenGLView or your renderer class changes. For more information about OpenGL ES prediction and coordinate mapping, see the code Mapping Coordinates for Drawn Objects.
Camera view: this transformation adjusts the coordinates of the drawing object based on the position of a virtual camera. The main thing to need is that OpenGL ES does not define a real camera object, but provides some tool methods to transform the display of drawing objects to simulate a camera. A camera view transformation may be calculated once when the GLSurfaceView is created, or change dynamically based on user behavior or application functionality.
This section describes how to create a projection and a camera view and apply them to your GLSurfaceView shape drawing process.
First, define a projection
The data of a projection transformation is calculated in the onSurfaceChanged () method of the GLSurfaceView.Renderer class. The following sample code demonstrates calculating the scale based on the width and height of the GLSurfaceView passed in, and using the Matrix class frustumM () method to populate a projection transformation:
[java] view plaincopyprint? @ Override public void onSurfaceChanged (GL10 unused, int width, int height) {GLES20.glViewport (0,0, width, height); float ratio = (float) width / height; / / in the onDrawFrame () method, apply the projection matrix to the object's coordinates Matrix.frustumM (mProjMatrix, 0,-ratio, ratio,-1, 3, 7);}
This code fills in a projection matrix: mProjMatrix, which can be used in conjunction with a camera view transformation in the onDrawFrame () method.
Note: if only a projection transformation is applied to your drawing object, it will usually result in nothing to be seen. In general, you have to apply for another camera view change to see what's on the screen.
Second, define a camera view
Adding a camera view transformation makes the transformation process of your drawing objects more complete. In the following sample code, the Matrix.setLookAtM () method is used to calculate the camera view transformation, which is then combined with the previously calculated projection matrix. Pass the merged transformation matrix to the drawn shape.
[java] view plaincopyprint? @ Override public void onDrawFrame (GL10 unused) {. / / set camera position (view matrix) Matrix.setLookAtM (mVMatrix, 0,0,0,-3,0f, 0f, 0f, 1.0f, 0.0f); / / calculate projection and view transformation Matrix.multiplyMM (mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0); / / draw shape mTriangle.draw (mMVPMatrix);}
Third, apply projection and camera view transformation
In order to use the merged projection and camera view transformation matrix, you need to modify the draw () method of your graphics object to receive the joint transformation matrix and apply it to your shape:
[java] view plaincopyprint? Public void draw (float [] mvpMatrix) {/ / pass the calculated transformation matrix handle mMVPMatrixHandle = GLES20.glGetUniformLocation (mProgram, "uMVPMatrix"); / / apply projection and view transformation GLES20.glUniformMatrix4fv (mMVPMatrixHandle, 1, false, mvpMatrix, 0); / / draw triangle GLES20.glDrawArrays (GLES20.GL_TRIANGLES, 0, vertexCount) Thank you for reading, the above is the content of "how to create a projection and a camera view of Android". After the study of this article, I believe you have a deeper understanding of how to create a projection and a camera view of Android, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.