Danilo Vuita
Danilo Vuita

Reputation: 37

Cannot get a vertex in position to complete a triangle

When I try to create that side of the cube, I don't know why but I cannot find the position of that one vertex to be such that it completes the triangle and I have a face on that side.

The goal is to have a cube on top so that it looks like a train car. I've tried many different takes but it just wont make 2 triangles, it's just one that keeps moving up and down.

Below I have put the function that creates that front car.

Image from the rendering

function makeTrainCar(){

  s = 0.5;
  var position = [
    -s, -s, -s, 
    s, -s, -s,
     s, s, -s, 
     -s, s, -s,

  -s, -s, s,
   s, -s, s,
    s, s, s,
     -s, s, s,
  
  -s, -s, -s,
   -s, s, -s,
    -s, s, s,
     -s, -s, s,

    s, -s, -s,
     s, s, -s,
      s, s, s,
       s, -s, s,

  -s, -s, -s,
   -s, -s, s,
    s, -s, s,
     s, -s, -s,
  //Top of car

  -s, s, -s, 
  -s, s, s, 
  s*0, s, s, 
  s*0, s, -s,

  s*0, s*2.5,-s,
  s*0, s*2.5,s,
  s*0, s,  s,
  s*0, s, -s,

  s, s,  -s,
  s, s,   s,
  s, s*2.5, s,
  s, s*2.5,-s,

  s, s, -s, 
  s, s*2.5, -s,
  s*0, s*2.5, -s, 
  s*0, s, -s,

  -s*0, s*2.5, s, 
  s, s, s,
  s, s*2.5, s, 
  -s*0, s, s,

];


  var normal = [0, 0, 1, 0, 0, 1,0, 0, 1,0, 0, 1,0, 0, 1,0, 0, 1,0, 0, 1,0, 0, 1];

  var texture = [0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1,
    1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1,
    1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0,
    0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1,
    1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0,
    0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0,
    //
    0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0,
    0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0,
  ];

  var index = [0, 1, 2, 0, 2, 3,
    4, 5, 6, 4, 6, 7,
    8, 9, 10, 8, 10, 11,
    12, 13, 14, 12, 14, 15,
    16, 17, 18, 16, 18, 19,
    20, 21, 22, 20, 22, 23,
    //
    24, 25, 26, 24, 26, 27,
    28, 29, 30, 28, 30, 31,
    32, 33, 34, 32, 34, 35,
    36, 39, 38, 36, 38, 39,];
    
  return {
    position: position,
    normal: normal,
    texture: texture,
    index: index
  }

}

Upvotes: 0

Views: 29

Answers (1)

Rabbid76
Rabbid76

Reputation: 211277

The last line in the index array is incorrect: 36, 39, 38, 36, 38, 39. It should be 36, 37, 38, 36, 38, 39:

var index = [0, 1, 2, 0, 2, 3,
    4, 5, 6, 4, 6, 7,
    8, 9, 10, 8, 10, 11,
    12, 13, 14, 12, 14, 15,
    16, 17, 18, 16, 18, 19,
    20, 21, 22, 20, 22, 23,
    //
    24, 25, 26, 24, 26, 27,
    28, 29, 30, 28, 30, 31,
    32, 33, 34, 32, 34, 35,
    36, 37, 38, 36, 38, 39,];

Upvotes: 1

Related Questions