public void Select(JLoader loader) { JModelTexture texture = new JModelTexture(loader.loadTexture(SphereTexturePathSelected)); SphereTexturedModel = new JTexturedModel(SphereModel, texture); SphereEntity = new JEntity(SphereTexturedModel, SphereEntity.Position, new Vector3(0, 0, 1), 0.5f); }
public JPerlinTerrain(int gridX, int gridZ, JLoader loader, JTerrainTexturePack texturePack) { X = gridX * SIZE; Z = gridZ * SIZE; TexturePack = texturePack; TerrainModel = generateTerrain(loader); }
/// <summary> /// Load the model and texture of the JBoundingSphere if we want to render it in the world. /// </summary> /// <param name="loader"></param> public void LoadSphereModel(JLoader loader) { SphereModelData = JObjFileLoader.LoadObj(SphereModelPath); SphereModel = loader.LoadToVAO(SphereModelData.Vertices, SphereModelData.TextureCoords, SphereModelData.Normals, SphereModelData.Indices); JModelTexture texture = new JModelTexture(loader.loadTexture(SphereTexturePathUnselected)); SphereTexturedModel = new JTexturedModel(SphereModel, texture); SphereEntity = new JEntity(SphereTexturedModel, new Vector3(50, 0, -50), new Vector3(0, 0, 1), 0.5f); }
private JRawModel generateTerrain(JLoader loader) { Console.WriteLine("Generating terrain..."); float[,] test = JNoise.GenerateNoiseMap(100, 100, 20.0f, 4, 0.5f, 2.0f); int count = VERTEX_COUNT * VERTEX_COUNT; heights = new float[VERTEX_COUNT, VERTEX_COUNT]; float[] vertices = new float[count * 3]; float[] normals = new float[count * 3]; float[] textureCoords = new float[count * 2]; uint[] indices = new uint[6 * (VERTEX_COUNT - 1) * (VERTEX_COUNT - 1)]; int vertexPointer = 0; for (int i = 0; i < VERTEX_COUNT; i++) { for (int j = 0; j < VERTEX_COUNT; j++) { vertices[vertexPointer * 3] = (float)j / ((float)VERTEX_COUNT - 1) * SIZE; float height = JMathUtils.HeightCurve2(test[j, i]) * MAX_HEIGHT; vertices[vertexPointer * 3 + 1] = height; heights[j, i] = height; vertices[vertexPointer * 3 + 2] = (float)i / ((float)VERTEX_COUNT - 1) * SIZE; Vector3 normal = CalculateNormal(j, i, test); normals[vertexPointer * 3] = normal.X; normals[vertexPointer * 3 + 1] = normal.Y; normals[vertexPointer * 3 + 2] = normal.Z; textureCoords[vertexPointer * 2] = (float)j / ((float)VERTEX_COUNT - 1); textureCoords[vertexPointer * 2 + 1] = (float)i / ((float)VERTEX_COUNT - 1); vertexPointer++; } } int pointer = 0; for (uint gz = 0; gz < VERTEX_COUNT - 1; gz++) { for (uint gx = 0; gx < VERTEX_COUNT - 1; gx++) { uint topLeft = (uint)(gz * VERTEX_COUNT) + gx; uint topRight = topLeft + 1; uint bottomLeft = (uint)((gz + 1) * VERTEX_COUNT) + gx; uint bottomRight = bottomLeft + 1; indices[pointer++] = topLeft; indices[pointer++] = bottomLeft; indices[pointer++] = topRight; indices[pointer++] = topRight; indices[pointer++] = bottomLeft; indices[pointer++] = bottomRight; } } Console.WriteLine("Terrain generation complete..."); return(loader.LoadToVAO(vertices, textureCoords, normals, indices)); }
public JWaterRenderer(JLoader loader, JWaterShader waterShader, Matrix4 projectionMatrix, JWaterFrameBuffer frameBuffer, JWaterTile waterTile) { this.WaterShader = waterShader; this.FrameBuffer = frameBuffer; this.WaterTile = waterTile; dudvMapTexture = JFileUtils.GetPathToResFile("waterDUDV.png"); normalMapTexture = JFileUtils.GetPathToResFile("matchingNormalMap.png"); dudvMap = loader.loadTexture(dudvMapTexture); normalMap = loader.loadTexture(normalMapTexture); distortionVariance = 0; WaterShader.start(); WaterShader.LoadTextures(); WaterShader.LoadProjectionMatrix(projectionMatrix); WaterShader.stop(); SetupVAO(loader); }
/// <summary> /// JBoundedEntity has a JBoundingSphere which allows selection of the JBoundedEntity with a mouse click. /// </summary> /// <param name="model"></param> /// <param name="position"></param> /// <param name="rotX"></param> /// <param name="rotY"></param> /// <param name="rotZ"></param> /// <param name="scale"></param> /// <param name="loader"></param> public JBoundedEntity(JTexturedModel model, Vector3 position, Vector3 orientation, float scale, JLoader loader) : base(model, position, orientation, scale) { BoundingSphere = new JBoundingSphere(); BoundingSphere.LoadSphereModel(loader); IsSelected = false; IsAtDestination = true; Destination = new JVector3(); }
/// <summary> /// Change the JBoundingSphere texture to indicate it is not currently selected. /// </summary> /// <param name="loader"></param> public void DeSelect(JLoader loader) { BoundingSphere.DeSelect(loader); IsSelected = false; }
/// <summary> /// Change the JBoundingSphere texture to indicate it is currently selected. /// </summary> /// <param name="loader"></param> public void Select(JLoader loader) { BoundingSphere.Select(loader); IsSelected = true; }
/// <summary> /// /// </summary> /// <param name="loader"></param> /// <param name="terrain"></param> public JEntityGenerator(JLoader loader, JPerlinTerrain terrain, JWaterTile waterTile) { Loader = loader; Terrain = terrain; WaterTile = waterTile; }
private void SetupVAO(JLoader loader) { // Just X and Z vertices. We will set Y to 0 everywhere for flat quad. float[] vertices = { -1, -1, -1, 1, 1, -1, 1, -1, -1, 1, 1, 1 }; WaterQuad = loader.LoadToVAO(vertices, 2); }