Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. package engine.rendering.lighting;
  2.  
  3. import org.lwjgl.util.vector.Vector3f;
  4.  
  5. public class ConeGenerator{
  6.    
  7.     private Vector3f[] positions;
  8.     private short[] indices;
  9.    
  10.     public void create(int subdivisions){
  11.        
  12.         positions = new Vector3f[subdivisions + 1];
  13.  
  14.         positions[0] = new Vector3f(0, 0, 0);
  15.        
  16.         for(int i = 0; i < subdivisions; i++){
  17.             positions[i + 1] = new Vector3f((float)Math.cos(Math.PI * 2 * i / subdivisions), (float)Math.sin(Math.PI * 2 * i / subdivisions), 1);
  18.         }
  19.        
  20.         indices = new short[(subdivisions*2 - 2) * 3];
  21.        
  22.         int index = 0;
  23.         for(int i = 1; i < subdivisions; i++){
  24.             indices[index++] = 0; //Source point
  25.             indices[index++] = (short)(i+1);
  26.             indices[index++] = (short)i;
  27.         }
  28.         indices[index++] = 0; //Source point
  29.         indices[index++] = 1;
  30.         indices[index++] = (short)subdivisions;
  31.        
  32.        
  33.         for(int i = 2; i < subdivisions; i++){
  34.             indices[index++] = 1;
  35.             indices[index++] = (short)i;
  36.             indices[index++] = (short)(i+1);
  37.         }
  38.        
  39.     }
  40.    
  41.     public Vector3f[] getPositions(){
  42.         return positions;
  43.     }
  44.    
  45.     public short[] getIndices(){
  46.         return indices;
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement