Skip to content

Commit

Permalink
more cleanups and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Yvonne Jung committed Aug 31, 2012
1 parent 01b765f commit 55210cb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
42 changes: 27 additions & 15 deletions src/Viewarea.js
Expand Up @@ -488,12 +488,10 @@ x3dom.Viewarea.prototype.getLightsShadow = function () {
}
};

x3dom.Viewarea.prototype.getViewpointMatrix = function () {
x3dom.Viewarea.prototype.updateSpecialNavigation = function (viewpoint, mat_viewpoint) {
var navi = this._scene.getNavigationInfo();
var viewpoint = this._scene.getViewpoint();
var mat_viewpoint = viewpoint.getCurrentTransform();

// helicopter mode needs to manipulate view matrix

// helicopter mode needs to manipulate view matrix specially
if (navi._vf.type[0].toLowerCase() == "helicopter" && !navi._heliUpdated)
{
var typeParams = navi.getTypeParams();
Expand Down Expand Up @@ -524,9 +522,14 @@ x3dom.Viewarea.prototype.getViewpointMatrix = function () {

navi._heliUpdated = true;
}
// end of special helicopter handling
};

//return mat_viewpoint.mult(viewpoint.getViewMatrix());
x3dom.Viewarea.prototype.getViewpointMatrix = function () {
var viewpoint = this._scene.getViewpoint();
var mat_viewpoint = viewpoint.getCurrentTransform();

this.updateSpecialNavigation(viewpoint, mat_viewpoint);

return viewpoint.getViewMatrix().mult(mat_viewpoint.inverse());
};

Expand Down Expand Up @@ -1052,7 +1055,7 @@ x3dom.Viewarea.prototype.onMoveView = function (translation, rotation)
{
var distance = 10;

if (this._scene._lastMin !== undefined && this._scene._lastMax !== undefined)
if (this._scene._lastMin && this._scene._lastMax)
{
distance = (this._scene._lastMax.subtract(this._scene._lastMin)).length();
distance = (distance < x3dom.fields.Eps) ? 1 : distance;
Expand Down Expand Up @@ -1121,7 +1124,7 @@ x3dom.Viewarea.prototype.onDrag = function (x, y, buttonState)
}
if (buttonState & 4) //middle
{
if (this._scene._lastMin !== undefined && this._scene._lastMax !== undefined)
if (this._scene._lastMin && this._scene._lastMax)
{
d = (this._scene._lastMax.subtract(this._scene._lastMin)).length();
d = (d < x3dom.fields.Eps) ? 1 : d;
Expand All @@ -1130,15 +1133,20 @@ x3dom.Viewarea.prototype.onDrag = function (x, y, buttonState)
{
min = x3dom.fields.SFVec3f.MAX();
max = x3dom.fields.SFVec3f.MIN();
ok = this._scene.getVolume(min, max, false);

ok = this._scene.getVolume(min, max, true);
if (ok) {
this._scene._lastMin = min;
this._scene._lastMax = max;
}

d = ok ? (max.subtract(min)).length() : 10;
d = (d < x3dom.fields.Eps) ? 1 : d;
}
//x3dom.debug.logInfo("PAN: " + min + " / " + max + " D=" + d);
//x3dom.debug.logInfo("w="+this._width+", h="+this._height);

vec = new x3dom.fields.SFVec3f(d*dx/this._width,d*(-dy)/this._height,0);
vec = new x3dom.fields.SFVec3f(d*dx/this._width, d*(-dy)/this._height, 0);
this._movement = this._movement.add(vec);

//TODO; move real distance along viewing plane
Expand All @@ -1148,7 +1156,7 @@ x3dom.Viewarea.prototype.onDrag = function (x, y, buttonState)
}
if (buttonState & 2) //right
{
if (this._scene._lastMin !== undefined && this._scene._lastMax !== undefined)
if (this._scene._lastMin && this._scene._lastMax)
{
d = (this._scene._lastMax.subtract(this._scene._lastMin)).length();
d = (d < x3dom.fields.Eps) ? 1 : d;
Expand All @@ -1157,15 +1165,20 @@ x3dom.Viewarea.prototype.onDrag = function (x, y, buttonState)
{
min = x3dom.fields.SFVec3f.MAX();
max = x3dom.fields.SFVec3f.MIN();
ok = this._scene.getVolume(min, max, false);

ok = this._scene.getVolume(min, max, true);
if (ok) {
this._scene._lastMin = min;
this._scene._lastMax = max;
}

d = ok ? (max.subtract(min)).length() : 10;
d = (d < x3dom.fields.Eps) ? 1 : d;
}
//x3dom.debug.logInfo("ZOOM: " + min + " / " + max + " D=" + d);
//x3dom.debug.logInfo((dx+dy)+" w="+this._width+", h="+this._height);

vec = new x3dom.fields.SFVec3f(0,0,d*(dx+dy)/this._height);
vec = new x3dom.fields.SFVec3f(0, 0, d*(dx+dy)/this._height);
this._movement = this._movement.add(vec);

//TODO; move real distance along viewing ray
Expand All @@ -1182,7 +1195,6 @@ x3dom.Viewarea.prototype.onDrag = function (x, y, buttonState)
this._lastY = y;
};


x3dom.Viewarea.prototype.prepareEvents = function (x, y, buttonState, eventType)
{
var avoidTraversal = (this._scene._vf.pickMode.toLowerCase() === "idbuf" ||
Expand Down
13 changes: 3 additions & 10 deletions src/nodes/EnvironmentalEffects.js
Expand Up @@ -60,7 +60,6 @@ x3dom.registerNodeType(
this.addField_SFFloat(ctx, 'visibilityRange', 0);
},
{
// methods
}
)
);
Expand Down Expand Up @@ -91,7 +90,9 @@ x3dom.registerNodeType(
{
fieldChanged: function(fieldName)
{
if (fieldName.indexOf("Url") > 0) {
if (fieldName.indexOf("Url") > 0 ||
fieldName.search("sky") >= 0 ||
fieldName.search("ground") >= 0) {
this._dirty = true;
}
else if (fieldName === "set_bind") {
Expand Down Expand Up @@ -119,14 +120,6 @@ x3dom.registerNodeType(
this._nameSpace.getURL(this._vf.topUrl[0]),
this._nameSpace.getURL(this._vf.leftUrl[0]),
this._nameSpace.getURL(this._vf.rightUrl[0])
/*
this._nameSpace.getURL(this._vf.rightUrl[0]),
this._nameSpace.getURL(this._vf.leftUrl[0]),
this._nameSpace.getURL(this._vf.topUrl[0]),
this._nameSpace.getURL(this._vf.bottomUrl[0]),
this._nameSpace.getURL(this._vf.frontUrl[0]),
this._nameSpace.getURL(this._vf.backUrl[0])
*/
];
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/nodes/Grouping.js
Expand Up @@ -652,6 +652,9 @@ x3dom.registerNodeType(
this.addField_SFString(ctx, 'pickMode', "idBuf");
// experimental field to switch off picking
this.addField_SFBool(ctx, 'doPickPass', true);

this._lastMin = null;
this._lastMax = null;
},
{
/* bindable getter (e.g. getViewpoint) are added automatically */
Expand Down

0 comments on commit 55210cb

Please sign in to comment.