Skip to content

Commit

Permalink
Merge pull request #6863 from felixpalmer/fix-cylinder-normals
Browse files Browse the repository at this point in the history
Fix normal calculation for CylinderGeometry
  • Loading branch information
Hannah authored Aug 30, 2018
2 parents 5c8944e + c3eaacb commit 4cdf9bc
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions Source/Core/CylinderGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,17 @@ define([
var tangentIndex = 0;
var bitangentIndex = 0;

var theta = Math.atan2(bottomRadius - topRadius, length);
var normal = normalScratch;
normal.z = 0;
normal.z = Math.sin(theta);
var normalScale = Math.cos(theta);
var tangent = tangentScratch;
var bitangent = bitangentScratch;

for (i = 0; i < slices; i++) {
var angle = i / slices * CesiumMath.TWO_PI;
var x = Math.cos(angle);
var y = Math.sin(angle);
var x = normalScale * Math.cos(angle);
var y = normalScale * Math.sin(angle);
if (computeNormal) {
normal.x = x;
normal.y = y;
Expand All @@ -254,12 +256,12 @@ define([
}

if (vertexFormat.normal) {
normals[normalIndex++] = x;
normals[normalIndex++] = y;
normals[normalIndex++] = 0;
normals[normalIndex++] = x;
normals[normalIndex++] = y;
normals[normalIndex++] = 0;
normals[normalIndex++] = normal.x;
normals[normalIndex++] = normal.y;
normals[normalIndex++] = normal.z;
normals[normalIndex++] = normal.x;
normals[normalIndex++] = normal.y;
normals[normalIndex++] = normal.z;
}

if (vertexFormat.tangent) {
Expand Down

0 comments on commit 4cdf9bc

Please sign in to comment.