Original title: Android OpenGLES2.0 | VR effect achieved with spherical skybox
Skyboxes are commonly used in 3D games, and there are generally skybox components in 3D engines that developers can use directly. What is the sky box? How is the sky box implemented? This blog mainly describes how to use OpenGLES to draw a sky box on Android and achieve VR effects.
Sky box, sky dome, sky ball and VR
Although most people know that these things are embarrassing, I think it is still necessary for me to “move†their definitions in case someone doesn’t know it.
The Sky Box is a cube that is placed into the scene. It is often a cube of six faces and often moves with the movement of the viewpoint. The sky box will depict scenes that are beyond the reach of people.
The Sky Dome is similar to the sky box except that it will be replaced by a five-sided surface of the sky box, which can be understood as a hemisphere. It is similar to the Tianyuan place considered by the ancients.
Sky Sphere is the direct replacement of the sky box with a ball - I heard that there is no sky ball this statement? It doesn't matter. Now it has.
VR (Virtual Reality) virtual definition does not say, VR effect of this blog is that the image displayed on the phone is controlled by the phone's attitude.
The realization of the sky box should be the simplest, but the effect may be somewhat embarrassing, especially at the intersection of the two sides can always see the difference. The skies and skies have similar effects. They are much better than the sky boxes, but they are more energy-intensive than the sky boxes.
Draw a ball
In the previous blog Android OpenGLES 2.0 (VI) - Constructing Cone, Cylindrical, and Sphere has introduced how to draw a ball, but the previous ball is unmapped. Now we draw a ball and attach it to the environment. Stickers. It's like drawing a globe.
Vertex coordinates and texture coordinates calculation
First of all, first we need to get the vertex and texture coordinates of the ball:
//Calculate vertex coordinates and texture coordinates
Private voidcalculateAttribute(){ ArrayList alVertix = newArrayList<>(); ArrayList textureVertix = newArrayList<>();
For(double vAngle = 0; vAngle < Math.PI; vAngle = vAngle + angleSpan) {
For(double hAngle = 0; hAngle < 2* Math.PI; hAngle = hAngle + angleSpan) { float x0 = (float) (radius* Math.sin(vAngle) * Math.cos(hAngle)); float y0 = ( Float) (radius* Math.sin(vAngle) * Math.sin(hAngle)); float z0 = (float) (radius * Math.cos((VAngle))); float x1 = (float) (radius* Math. Sin(vAngle) * Math.cos(hAngle + angleSpan)); float y1 = (float) (radius* Math.sin(vAngle) * Math.sin(hAngle + angleSpan)); float z1 = (float) (radius * Math.cos(vAngle)); float x2 = (float) (radius* Math.sin(vAngle + angleSpan) * Math.cos(hAngle + angleSpan)); float y2 = (float) (radius* Math.sin(vAngle + angleSpan) * Math.sin(hAngle + angleSpan)); float z2 = (float) (radius * Math.cos(vAngle + angleSpan)); float x3 = (float) (radius* Math.sin(vAngle + angleSpan) * Math.cos(hAngle)); float y3 = (float) (radius* Math.sin(vAngle + angleSpan) * Math.sin(hAngle)); float z3 = (float) (radius * Math.cos(vAngle + angleSpan)); float s0 = (float) (hAngle / Math.PI/2); float s1 = (float) ((hAngle + angleSpan)/ Math.PI/ 2); float t0 = (float) (vAngle / Math.PI); float t1 = (float) ((VAngle + angleSpan) / Math.PI); alVertix.add(x1); alVertix.add( Y1); alVertix.add(z1); alVertix.add(x0); alVertix.add(y0); alVertix.add(z0); alVertix.add(x3); alVertix.add(y3); alVertix.add(z3 textureVertix.add(s1); // x1 y1 corresponds to the texture coordinate textureVertix.add(t0); textureVertix.add(s0); // x0 y0 corresponds to texture coordinate textureVertix.add(t0); textureVertix.add(s0) ; // x3 y3 corresponds to texture coordinates textureVertix.add(t1); alVertix.add(x1); alVertix.add(y1); alVertix.add(z1); alVertix.add(x3); alVertix.add(y3); alVertix.add(z3); alVertix.add(x2); alVertix.add(y2); alVertix.add(z2); textureVertix.add(s1); // x1 y1 corresponds to texture coordinate textureVertix.add(t0); textureVertix .add(s0); // x3 y3 corresponds to texture coordinate textureVertix.add(t1); textureVertix.add(s1); // x2 y3 corresponds to texture coordinate textureVertix.add(t1); } } vCount = alVertix.size() / 3; posBuffer = convertToFloatBuffer(alVertix); cooBuffer=convertToFloatBuffer(textureVertix);}
// Dynamic array to FloatBuffer
Private FloatBuffer convertToFloatBuffer(ArrayList Data){ float[] d= newfloat[data.size()];
For(int i= 0;i
Fork Type Terminals,Insulated Bullet Sockets Terminals,Insulated Bullet Terminals,Type Fork Insulate Terminal
Taixing Longyi Terminals Co.,Ltd. , https://www.txlyterminals.com