Second Life source Analysis (11) The realization of the ground display
Source: Internet
Author: User
After all the validation, the second life will be connected to the GRID server, from the server to get a lot of information, such as the role of the location, virtual world time and so on. Then will be based on this information to construct a frame of the picture displayed, here first look at the following picture: Cai Junsheng 2008/1/8 qq:9073204 Shenzhen from this picture, you can see the sky, there is ground, there are houses, people and trees and so on. So many things are the same as real time rendering out, now to see how the ground is constructed. The current 3D technology uses grids and textures to construct real-time rendering, so the second Life rendering is the same. So the grid data from the ground comes from there. The texture of the ground picture is coming from there. In the second Life, the ground grid data is relatively simple, only a plane, directly in the program construction can be. Texture pictures are downloaded from the server, as long as the replacement of different texture pictures can achieve different ground patterns. Below is the code to create the ground grid model: #001 bool llvoground::updategeometry (lldrawable *drawable) #002 {#003 Llstrider<llvector3> Verticesp; #004 LLStrider<LLVector3> NORMALSP; #005 LLStrider<LLVector2> TEXCOORDSP; #006 LLStrider<U32> Indicesp; #007 s32 Index_offset; #008 llface *face; #009 #010 lldrawpoolground *poolp = (lldrawpoolground*) Gpipeline.getpool (lldrawpool::P ool_ground); #011 #012 if (Drawable->getnumfaces () < 1) #013 Drawable->addface (POOLP, NULL); #014 face = drawable->getface (0); #015 above get No. 0 surface mesh. #016 if (Face->mvertexbuffer.isnull ()) #017 {#018 face->setsize (5, 12); Sets the number of vertices and indexes for a planar construct. #019 face->mvertexbuffer = new Llvertexbuffer ( Lldrawpoolground::vertex_data_mask, Gl_stream_draw_arb); #020 Face->mvertexbuffer->allocatebuffer (face-> Getgeomcount (), Face->getindicescount (), TRUE); Creates a vertex buffer and allocates the size of the memory. #021 face->setgeomindex (0); #022 face->setindicesindex (0); #023  } #024 #025 index_offset = Face->getgeometry (VERTICESP,NORMALSP, TEXCOORDSP, INDICESP); #026 if ( -1 = index_offset) #027 {#028 return TRUE; #029  } #030 #031 ///////////////////////////////////////#032 //#033 //#034 //#035 llvector3 at_dir = Gcamera->getataxis (); #036 at_dir.mv[vz] = 0.f; #037 if (At_dir.normvec () < 0.01) #038 {#039 //We really don ' t care, as We ' re not looking anywhere near the horizon. #040  } #041 llvector3 left_dir = Gcamera->getleftaxis (); #042 left_dir.mv[vz] = 0.f; #043 left_dir.normvec (); #044 #045 //Our center-point #046 llcolor4 ground_color = Gsky.getfogcolor (); #047 ground_color.mv[3] = 1.f; #048 face->setfacecolor (Ground_color); Set the color of the ground. #049 #050 * (verticesp++) = LLVector3 (64, 64, 0); #051 * (verticesp++) = LLVector3 (-64, 64, 0);#052 * (verticesp++) = LLVector3 (-64,-64, 0); #053 * (verticesp++) = LLVector3 (64,-64, 0); #054 * (verticesp++) = LLVector3 (0, 0,-1024); #055 Sets the coordinates of 5 vertices. #056 #057 //triangles for each side #058 *indicesp++ = index_offset + 0; #059 *indicesp++ = index_offset + 1; #060 *indicesp++ = Index_offset + 4; #061 #062 *indicesp++ = index_offset + 1; #063 *indicesp++ = Index_offset + 2; #064 *indicesp++ = Index_offset + 4; #065 #066 *indicesp++ = Index_offset + 2; #067 *indicesp++ = Index_offset + 3; #068 *indicesp++ = Index_offset + 4; #069 #070 *indicesp++ = Index_offset + 3; #071 *indicesp++ = index_offset + 0; #072 *indicesp++ = Index_offset + 4; #073 Sets the index of 4 triangles to form a ground plane. #074 * (texcoordsp++) = LLVector2 (0.F, 0.F); #075 * (texcoordsp++) = LLVector2 (1.f, 0.F); #076 * (texcoordsp++) = LLVector2 (1.f, 1.F); #077 * (texcoordsp++) = LLVector2 (0.F, 1.F); #078 * (texcoordsp++) = LLVector2 (0.5f, 0.5f); #079 The texture coordinates of the texture surface are set above. #080 LLPipeline::sCompiles++; #081 return TRUE; #082  } #083 Constructs a four-triangle planar grid with the above code and sets the texture coordinates. Before rendering the ground, the texture image of the ground is downloaded from the server and set into the texture channel of OPENGL, which can be displayed as the ground on the image.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.