Skip to content

Commit

Permalink
Merge pull request #7 from QuinnCiccoretti/archery
Browse files Browse the repository at this point in the history
Archery
  • Loading branch information
QuinnCiccoretti committed May 21, 2018
2 parents a37aa1b + cbf77c3 commit bc2a9a6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
40 changes: 15 additions & 25 deletions js/controllers/RBowController.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ THREE.RBowController = function ( id ) {

if(this.getButtonState("trigger")){ //while trigger held
if(typeof arrow !== "undefined"){
var handpos = this.position;
var bowpos = controller1.position;
var handpos = this.get_absolute_position();
var bowpos = controller1.get_absolute_position();
// var midpoint = handpos.clone().add(bowpos).divideScalar(2);
//position arrow
//position arrow
var diff = bowpos.clone().sub(handpos);
diff.normalize();
var arrowHelper = new THREE.ArrowHelper(diff, new THREE.Vector3());
arrow.position.set(handpos.x, handpos.y, handpos.z);
arrow.__dirtyPosition = true; //needed for the physics scene to update pos

//quaternion that will align objects between the two controllers
var rot_between = calculate_euler(bowpos.clone(), handpos.clone());
var rot_between = arrowHelper.rotation;
// console.log(rot_between);
arrow.rotation.set(rot_between.x, rot_between.y, rot_between.z);
// console.log("a");
Expand Down Expand Up @@ -58,13 +61,14 @@ THREE.RBowController = function ( id ) {
function onTriggerUp(){
last_threshold = .1; //reset threshold for vibrating with distance
var my_pos = this.get_absolute_position();
var diff = my_pos.sub(controller1.get_absolute_position());
user.remove(arrow);

arrow.position.set(my_pos.x, my_pos.y, my_pos.z);
arrow.__dirtyPosition = true; //needed for the physics scene to update pos
scene.add(arrow);
arrow.setLinearVelocity(diff.multiplyScalar(-20));
// scene.add(arrow);
var diff = my_pos.sub(controller1.get_absolute_position());
// user.remove(arrow);


arrow.setLinearVelocity(diff.multiplyScalar(-40));
}
/**
* instantiates new arrow with physics
Expand All @@ -80,22 +84,8 @@ THREE.RBowController = function ( id ) {
var handpos = this.get_absolute_position();
arrow.position.set(handpos.x,handpos.y,handpos.z);
arrow.__dirtyPosition = true;
user.add(arrow);
}
/**
* WORK IN PROGRESS -> TODO: Use local coords and add to user, then remove from scene
* calculates a euler that will rotate the arrow parralell to
* the line between both controllers.
*/
function calculate_euler(a,b){
var diff = a.sub(b);
var spher = new THREE.Spherical().setFromVector3(diff);
spher.makeSafe();
var rot = new THREE.Euler( spher.phi, 0, -1*spher.theta);

return rot;
}

scene.add(arrow);
}

this.addEventListener( 'triggerdown', onTriggerDown );
this.addEventListener( 'triggerup', onTriggerUp );
Expand Down
8 changes: 4 additions & 4 deletions vrmain.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<script src="./js/controllers/MoveController.js"></script>
<script src="./js/controllers/DragController.js"></script>
<script src="./js/controllers/SlingshotController.js"></script>
<!-- <script src="./js/controllers/LBowController.js"></script> -->
<!-- <script src="./js/controllers/RBowController.js"></script> -->
<script src="./js/controllers/LBowController.js"></script>
<script src="./js/controllers/RBowController.js"></script>
<script src="./js/controllers/CreateController.js"></script>
<script src="./js/controllers/RefreshController.js"></script>
<!-- <script src="./js/controllers/BatController.js"></script> -->
Expand Down Expand Up @@ -206,7 +206,7 @@
new THREE.MoveController( 0 ),
new THREE.DragController( 0 ),
new THREE.SlingshotController( 0 ),
/*new THREE.LBowController(0),*/
new THREE.LBowController(0),
new THREE.CreateController(0),
new THREE.RefreshController(0),
new THREE.GravityController( 0 )
Expand Down Expand Up @@ -245,7 +245,7 @@
new THREE.DragController( 1 ),
new THREE.SlingshotController( 1 ),
new THREE.RefreshController(1),
/* new THREE.RBowController(1),*/
new THREE.RBowController(1),
new THREE.GravityController( 1 ),
new THREE.CreateController(1)
];
Expand Down

0 comments on commit bc2a9a6

Please sign in to comment.