Skip to content

Commit

Permalink
finished dish primitive (ellipsoid part)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvonne Jung committed Aug 13, 2013
1 parent bef038e commit 68b35c1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
30 changes: 22 additions & 8 deletions src/nodes/GeometryEDF.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,14 @@ x3dom.registerNodeType(
this._mesh._texCoords[0] = [];
this._mesh._indices[0] = [];

var halfDia = this._vf.diameter / 2, r = this._vf.radius, h = this._vf.height;
var halfDia = this._vf.diameter / 2, r = this._vf.radius,
h = (r == 0) ? Math.min(this._vf.height, halfDia) : this._vf.height;
var offset = (r == 0) ? (halfDia - h) : 0;
var twoPi = Math.PI * 2, halfPi = Math.PI / 2;

var latitudeBands = this._vf.subdivision.x, longitudeBands = this._vf.subdivision.y;
var latNumber, longNumber;
var a, b, c;

var theta, sinTheta, cosTheta;
var phi, sinPhi, cosPhi;
Expand All @@ -295,6 +297,15 @@ x3dom.registerNodeType(
if (r == 0) {
var segTheta = halfPi - Math.asin(1 - h / halfDia);
var segL = Math.ceil(latitudeBands / halfPi * segTheta);

a = halfDia;
b = halfDia;
c = halfDia;
}
else {
a = halfDia;
b = h;
c = r;
}

for (latNumber = 0; latNumber <= latitudeBands; latNumber++) {
Expand All @@ -312,18 +323,21 @@ x3dom.registerNodeType(
sinPhi = Math.sin(phi);
cosPhi = Math.cos(phi);

x = halfDia * (-cosPhi * sinTheta);
y = halfDia * cosTheta;
z = halfDia * (-sinPhi * sinTheta);
x = a * (-cosPhi * sinTheta);
y = b * cosTheta;
z = c * (-sinPhi * sinTheta);

u = 0.25 - (longNumber / longitudeBands);
v = latNumber / latitudeBands;

this._mesh._positions[0].push(x, y - offset, z);
this._mesh._normals[0].push(x);
this._mesh._normals[0].push(y);
this._mesh._normals[0].push(z);
this._mesh._texCoords[0].push(u, v);
if (r == 0) {
this._mesh._normals[0].push(x, y, z);
}
else {
this._mesh._normals[0].push(x/(a*a), y/(b*b), z/(c*c));
}

if ((latNumber == latitudeBands) || (r == 0 && segL == latNumber)) {
tmpPosArr.push(x, y - offset, z);
Expand Down Expand Up @@ -360,9 +374,9 @@ x3dom.registerNodeType(
this._mesh._positions[0].push(tmpPosArr[3*i ]);
this._mesh._positions[0].push(tmpPosArr[3*i+1]);
this._mesh._positions[0].push(tmpPosArr[3*i+2]);
this._mesh._normals[0].push(0, -1, 0);
this._mesh._texCoords[0].push(tmpTcArr[2*i ]);
this._mesh._texCoords[0].push(tmpTcArr[2*i+1]);
this._mesh._normals[0].push(0, -1, 0);

if (i >= 2) {
this._mesh._indices[0].push(origPos);
Expand Down
31 changes: 27 additions & 4 deletions test/functional/torus.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,30 @@
</table>
</fieldset>
</div>
<div id='X3DOM_AOPT_Daneben' class='group' style='margin:2px; padding:4px; background-color:rgba(199,202,204,.7); position:absolute; float:center; top:160px; z-index:1000;'>
<div id='X3DOM_AOPT_TotalDaneben' class='group' style='margin:2px; padding:4px; background-color:rgba(199,202,204,.7); position:absolute; float:center; left:550px; z-index:1000;'>
<fieldset>
<legend>Dish</legend>
<table>
<tr>
<td>radius</td>
<td><input type="text" id="radius" value="0" onchange="document.getElementById('geod').setAttribute('radius', this.value);"></td>
</tr>
<tr>
<td>height</td>
<td><input type="text" id="height" value="1" onchange="document.getElementById('geod').setAttribute('height', this.value);"></td>
</tr>
<tr>
<td>diameter</td>
<td><input type="text" id="diameter" value="2" onchange="document.getElementById('geod').setAttribute('diameter', this.value);"></td>
</tr>
<tr>
<td>subdivision</td>
<td><input type="text" id="subdivision1" value="24 24" onchange="document.getElementById('geod').setAttribute('subdivision', this.value);"></td>
</tr>
</table>
</fieldset>
</div>
<div id='X3DOM_AOPT_Daneben' class='group' style='margin:2px; padding:4px; background-color:rgba(199,202,204,.7); position:absolute; float:center; top:150px; z-index:1000;'>
<fieldset>
<legend>Rectangular Torus</legend>
<table>
Expand All @@ -156,7 +179,7 @@
</table>
</fieldset>
</div>
<div id='X3DOM_AOPT_Daneben' class='group' style='margin:2px; padding:4px; background-color:rgba(199,202,204,.7); position:absolute; float:center; top:350px; z-index:1000;'>
<div id='X3DOM_AOPT_Daneben' class='group' style='margin:2px; padding:4px; background-color:rgba(199,202,204,.7); position:absolute; float:center; top:325px; z-index:1000;'>
<fieldset>
<legend>Pyramid</legend>
<table>
Expand Down Expand Up @@ -262,9 +285,9 @@
<shape>
<appearance>
<!--imageTexture url="media/texture/generic/earth.jpg"></imageTexture-->
<material diffuseColor='0.4 0.5 0.6' specularColor='0.3 0.3 0.3'></material>
<material diffuseColor='0.4 0.5 0.6' specularColor='0.3 0.3 0.3' shininess="0.5"></material>
</appearance>
<dish id="geod" radius="0" height="0.7" diameter="2.0">
<dish id="geod" radius="0" height="1" diameter="2">
</dish>
</shape>
</transform>
Expand Down

0 comments on commit 68b35c1

Please sign in to comment.