Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated inheritance model. Camera and Player both inherit from Lookin…
…gObject which inherits from WorldObject. Both levels of superclasses have synchronization methods which will be used to keep the player and camera in sync
- Loading branch information
1 parent
7cada04
commit 7c298a4
Showing
7 changed files
with
101 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
class Camera extends WorldObject | ||
class Camera extends LookingObject | ||
constructor: (x=0,y=0,z=0)-> | ||
super(x,y,z) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
class LookingObject extends WorldObject | ||
pitch: 0 | ||
yaw: 0 | ||
fresh_look: false | ||
look: new Vector3(0,0,0) | ||
|
||
constructor: (x=0,y=0,z=0) -> | ||
super(x,y,z) | ||
|
||
setLook: (x,y,z) -> | ||
if x instanceof Vector3 | ||
@look = x | ||
else if x? and y? and z? | ||
@look.x = x | ||
@look.y = y | ||
@look.z = z | ||
|
||
addToPitch: (p) -> | ||
@pitch += p | ||
if @pitch > 89.9 | ||
@pitch = 89.9 | ||
else if @pitch < -89.9 | ||
@pitch = 89.9 | ||
@fresh_look = false | ||
|
||
addToYaw: (y) -> | ||
@yaw += y + 360 | ||
@yaw %= 360 | ||
@fresh_look = false | ||
|
||
getPitch: -> | ||
return @pitch | ||
|
||
getYaw: -> | ||
return @yaw | ||
|
||
getLook: -> | ||
if not @fresh_look | ||
@look = new Vector3(Math.sin((@yaw*Math.PI)/180)*Math.cos((@pitch*Math.PI)/180), -Math.sin((@pitch*Math.PI)/180), -Math.cos((@yaw*Math.PI)/180)*Math.cos((@pitch*Math.PI)/180)) | ||
@look.normalize() | ||
@fresh_look = true | ||
return @look | ||
|
||
getHorizontalLook: -> | ||
vlook = @getLook() | ||
hlook = new Vector2(vlook.x, vlook.z) | ||
hlook.normalize() | ||
return hlook | ||
|
||
synchronizeWithLookingObject: (obj)-> | ||
if obj.look instanceof Vector3 | ||
@look = obj.look | ||
@synchronizeWithWorldObject(obj) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
class Player extends WorldObject | ||
class Player extends LookingObject | ||
|
||
constructor: (x=0, y=0, z=0) -> | ||
super(x,y,z) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
#TEST VECTOR CONSTRUCTOR | ||
v = new Vector2(1,2); | ||
console.log (v) | ||
console.log(v.y) | ||
v = new Vector3(20, 1.3, 15) | ||
v.normalize() | ||
console.log(v.length()) | ||
y = v.normalize() | ||
console.log(y) | ||
|
||
w = new Player(0,0,0) | ||
w.setLocation(new Vector3(1,2,3)) | ||
w.addToPitch(200) | ||
w.addToYaw(370) | ||
console.log(w) | ||
console.log(w.getLook()) | ||
console.log(w.getLocation()) | ||
|
||
c = new Camera(0,0,0) | ||
c.synchronizeWithLookingObject(w); | ||
console.log(c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,27 @@ | ||
### | ||
***WorldObject*** | ||
The constructor for world object takes one of: | ||
*Nothing; indicating a default location of (0,0,0) | ||
*A Vector3 indicating the default location | ||
*an x,y, and, z indicating the default location | ||
### | ||
class WorldObject | ||
location : new Vector3(0,0,0) | ||
look: 0 | ||
pitch: 0 | ||
yaw: 0 | ||
fresh_look: false | ||
constructor: (x=0,y=0,z=0)-> | ||
@location = new Vector3(x,y,z) | ||
@look = new Vector3(x,y,z) | ||
setLocation: (x=0,y=0,z=0)-> | ||
@location = new Vector3(x,y,z) | ||
setPitch: (p) -> | ||
@pitch = p | ||
@fresh_look = false | ||
setYaw: (y) -> | ||
@yaw = y | ||
@fresh_look = false | ||
getPitch: -> | ||
return @pitch | ||
getYaw: -> | ||
return @yaw | ||
location: new Vector3(0,0,0) | ||
|
||
constructor: (x=0,y=0,z=0) -> | ||
@setLocation(x,y,z) | ||
|
||
setLocation: (x,y,z) -> | ||
if x instanceof Vector3 | ||
@location = x | ||
else if x? and y? and z? | ||
@location.x = x | ||
@location.y = y | ||
@location.z = z | ||
|
||
getLocation: -> | ||
return @location | ||
getLook: -> | ||
if not @fresh_look | ||
@look = new Vector3(Math.sin((@yaw*Math.PI)/180)*Math.cos((@pitch*Math.PI)/180), -Math.sin((@pitch*Math.PI)/180), -Math.cos((@yaw*Math.PI)/180)*Math.cos((@pitch*Math.PI)/180)) | ||
@look.normalize() | ||
@fresh_look = true | ||
return @look | ||
getHorizontalLook: -> | ||
vlook = @getLook() | ||
hlook = new Vector2(vlook.x, vlook.z) | ||
hlook.normalize() | ||
return hlook | ||
synchronizeWithWorldObject: (obj)-> | ||
@location = obj.getLocation() | ||
|
||
synchronizeWithWorldObject: (obj) -> | ||
if obj.location instanceof Vector3 | ||
@location = obj.location |