Skip to content

Commit

Permalink
Update to latest nexus_Add nexus raycaster (not really working yet)
Browse files Browse the repository at this point in the history
It seems to output the same answer for a ray
that intersects the object anywhere. No good for 3d mouse.
  • Loading branch information
foobarbecue committed May 31, 2017
1 parent 37ce489 commit e92efbc
Show file tree
Hide file tree
Showing 4 changed files with 1,070 additions and 990 deletions.
23 changes: 18 additions & 5 deletions imports/client/climbsim.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,24 @@ function onmousemove(e) {
mouse2D.z = 0.5;
raycaster.setFromCamera(mouse2D, Climbsim.camera);
if (typeof Climbsim.boulderMesh !== 'undefined') {
intersects = raycaster.intersectObject(Climbsim.boulderMesh, true);
if (intersects.length > 0) {
var pos = intersects[0].point;
if (typeof pos != null) {
Climbsim.mouse3D.position.set(pos.x, pos.y, pos.z);
// If the object is a Nexus object, it has its own raycast function and we'll use that
if('raycast' in Climbsim.boulderMesh){
let intersects = [];
Climbsim.boulderMesh.raycast(raycaster, intersects);
console.log(intersects);
if (intersects.length > 0) {
let pos = intersects[0].object.position;
if (typeof pos != null) {
Climbsim.mouse3D.position.set(pos.x, pos.y, pos.z);
}
}
} else {
intersects = raycaster.intersectObject(Climbsim.boulderMesh, true);
if (intersects.length > 0) {
let pos = intersects[0].point;
if (typeof pos != null) {
Climbsim.mouse3D.position.set(pos.x, pos.y, pos.z);
}
}
}
}
Expand Down
39 changes: 36 additions & 3 deletions imports/client/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* Created by aaron on 5/28/2017.
*/

import ol from "openlayers"
//import ol from "openlayers"
//Use below to load unminified openlayers for debugging. npm/ is an alias defined in .babelrc and implemented using
//babel-plugin-module-resolver
//import ol from "npm/openlayers/dist/ol-debug.js"
import ol from "npm/openlayers/dist/ol-debug.js"

Template.areaMap.onRendered(function(){
this.subscribe("boulders");
Expand All @@ -14,6 +14,32 @@ Template.areaMap.onRendered(function(){
let areaBoulders = Boulders.find({area:area}); // could this be const?
let boulderVectorSource = new ol.source.Vector();
let clickLinks = new ol.interaction.Select({condition: ol.events.condition.click});
clickLinks.on('select', function(evt){
window.open(evt.target.getFeatures().getArray()[0].get('url'));
});
let fill = new ol.style.Fill({
color: 'rgba(255,255,255,0.4)'
});
let stroke = new ol.style.Stroke({
color: '#3399CC',
width: 1.25
});
let markerStyle = function(feature) {
return [new ol.style.Style({
image: new ol.style.Circle({
fill: fill,
stroke: stroke,
radius: 5
}),
fill: fill,
stroke: stroke,
text: new ol.style.Text({
text: feature.get('name'),
fill: fill,
stroke: stroke
})
})];
};

let olmap = new ol.Map({
target: 'map',
Expand All @@ -24,7 +50,10 @@ Template.areaMap.onRendered(function(){
key:'AnPtlHlc_-w6pMue8NZ_LsUszDvhVRBV7s5fIm--skojzTnNKFHneZrPdpecItva',
})
}),
new ol.layer.Vector({source:boulderVectorSource})
new ol.layer.Vector({
source:boulderVectorSource,
style: markerStyle
})
],
view: new ol.View({
projection: 'EPSG:3857', // Web Mercator. This is the default, just being explicit.
Expand All @@ -34,6 +63,9 @@ Template.areaMap.onRendered(function(){
interactions: [clickLinks]
});

// Zoom to the points


areaBoulders.observe({
added: function(boulder){
let boulderFeature = new ol.Feature({
Expand All @@ -46,6 +78,7 @@ Template.areaMap.onRendered(function(){
boulderVectorSource.addFeature(boulderFeature);
console.log(boulderFeature);
}
olmap.getView().fit(boulderVectorSource.getExtent(), olmap.getSize());
}
});
});
Expand Down
Loading

0 comments on commit e92efbc

Please sign in to comment.