Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
Hubs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ar-noc
Hubs
Commits
e793f546
Commit
e793f546
authored
7 years ago
by
netpro2k
Browse files
Options
Downloads
Patches
Plain Diff
Add ratchet turning, this removes the need for rig-selctor for now.
parent
7a675d4b
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
public/index.html
+27
-43
27 additions, 43 deletions
public/index.html
src/components/axis-dpad.js
+81
-0
81 additions, 0 deletions
src/components/axis-dpad.js
src/components/snap-rotation.js
+62
-0
62 additions, 0 deletions
src/components/snap-rotation.js
src/index.js
+5
-2
5 additions, 2 deletions
src/index.js
with
175 additions
and
45 deletions
public/index.html
+
27
−
43
View file @
e793f546
...
@@ -24,53 +24,37 @@
...
@@ -24,53 +24,37 @@
<script
id=
"hand-template"
type=
"text/html"
>
<script
id=
"hand-template"
type=
"text/html"
>
<
a
-
box
class
=
"
hand
"
scale
=
"
0.2 0.1 0.3
"
><
/a-box
>
<
a
-
box
class
=
"
hand
"
scale
=
"
0.2 0.1 0.3
"
><
/a-box
>
</script>
</script>
<script
id=
"vive-rig"
type=
"text/html"
>
<
a
-
entity
id
=
"
player-rig
"
networked
wasd
-
controls
>
<
a
-
entity
id
=
"
head
"
camera
=
"
userHeight: 1.6
"
look
-
controls
networked
=
"
template:#head-template;showLocalTemplate:false;
"
><
/a-entity
>
<
a
-
entity
id
=
"
left-hand
"
vive
-
controls
=
"
hand: left
"
teleport
-
controls
=
"
cameraRig: #player-rig
"
networked
=
"
template:#hand-template;showLocalTemplate:false;
"
><
/a-entity
>
<
a
-
entity
id
=
"
right-hand
"
vive
-
controls
=
"
hand: right
"
teleport
-
controls
=
"
cameraRig: #player-rig
"
networked
=
"
template:#hand-template;showLocalTemplate:false;
"
><
/a-entity
>
<
/a-entity
>
</script>
<script
id=
"oculus-rig"
type=
"text/html"
>
<
a
-
entity
id
=
"
player-rig
"
networked
wasd
-
controls
>
<
a
-
entity
id
=
"
head
"
camera
=
"
userHeight: 1.6
"
look
-
controls
networked
=
"
template:#head-template;showLocalTemplate:false;
"
><
/a-entity
>
<
a
-
entity
oculus
-
touch
-
controls
=
"
left
"
teleport
-
controls
=
"
cameraRig:#player-rig;button:trigger;
"
networked
=
"
template:#hand-template;showLocalTemplate:false;
"
><
/a-entity
>
<
a
-
entity
oculus
-
touch
-
controls
=
"
right
"
teleport
-
controls
=
"
cameraRig:#player-rig;button:trigger;
"
networked
=
"
template:#hand-template;showLocalTemplate:false;
"
><
/a-entity
>
<
/a-entity
>
</script>
<script
id=
"daydream-rig"
type=
"text/html"
>
<
a
-
entity
id
=
"
player-rig
"
networked
wasd
-
controls
>
<
a
-
entity
id
=
"
head
"
camera
=
"
userHeight: 1.6
"
look
-
controls
networked
=
"
template:#head-template;showLocalTemplate:false;
"
><
/a-entity
>
<
a
-
entity
daydream
-
controls
networked
=
"
template:#hand-template;showLocalTemplate:true;
"
><
/a-entity
>
<
/a-entity
>
</script>
<script
id=
"gearvr-rig"
type=
"text/html"
>
<
a
-
entity
id
=
"
player-rig
"
networked
wasd
-
controls
>
<
a
-
entity
id
=
"
head
"
camera
=
"
userHeight: 1.6
"
look
-
controls
networked
=
"
template:#head-template;showLocalTemplate:false;
"
><
/a-entity
>
<
a
-
entity
gearvr
-
controls
networked
=
"
template:#hand-template;showLocalTemplate:true;
"
><
/a-entity
>
<
/a-entity
>
</script>
<script
id=
"dolly-rig"
type=
"text/html"
>
<
a
-
entity
id
=
"
player-rig
"
networked
wasd
-
controls
>
<
a
-
entity
id
=
"
head
"
camera
=
"
userHeight: 1.6
"
look
-
controls
networked
=
"
template:#head-template;showLocalTemplate:false;
"
><
/a-entity
>
<
/a-entity
>
</script>
</a-assets>
</a-assets>
<a-entity
rig-selector=
"vive:#vive-rig;oculus:oculus-rig;daydream:#daydream-rig;desktop:#dolly-rig;mobile:dolly-rig;"
></a-entity>
<a-entity
id=
"player-rig"
networked
wasd-controls
snap-rotation=
"leftEventSrc: #right-hand; rightEventSrc: #right-hand"
>
<a-entity
id=
"head"
camera=
"userHeight: 1.6"
look-controls
networked=
"template:#head-template;showLocalTemplate:false;"
></a-entity>
<a-entity
id=
"left-hand"
vive-controls=
"hand: left"
oculus-touch-controls=
"left"
axis-dpad=
"centerZone: 1"
teleport-controls=
"cameraRig: #player-rig; button: dpadcenter"
networked=
"template:#hand-template;showLocalTemplate:false;"
></a-entity>
<a-entity
id=
"right-hand"
vive-controls=
"hand: right"
oculus-touch-controls=
"right"
daydream-controls
gearvr-controls
axis-dpad
teleport-controls=
"cameraRig: #player-rig; button: dpadcenter"
networked=
"template:#hand-template;showLocalTemplate:false;"
></a-entity>
</a-entity>
<a-entity
id=
"ground"
position=
"0 0 0"
<a-entity
id=
"ground"
position=
"0 0 0"
geometry=
"primitive: plane; width: 100
00
; height: 100
00
;"
rotation=
"-90 0 0"
geometry=
"primitive: plane; width: 100; height: 100;"
rotation=
"-90 0 0"
material=
"shader: flat; src: #grid; repeat: 100
00 100
00;"
></a-entity>
material=
"shader: flat; src: #grid; repeat: 100
1
00;"
></a-entity>
<a-sky
src=
"#sky"
rotation=
"0 -90 0"
></a-sky>
<a-sky
src=
"#sky"
rotation=
"0 -90 0"
></a-sky>
</a-scene>
</a-scene>
</body>
</body>
...
...
This diff is collapsed.
Click to expand it.
src/components/axis-dpad.js
0 → 100644
+
81
−
0
View file @
e793f546
/**
* @fileOverview
* Treats a pair of axes and a button as a dpad
* This is useful for Vive trackpad and Oculus Touch thumbstick
*
* @name axis-dpad.js
* @TODO allow use of thumbstick without press
* @TODO make axes configurable
*/
const
angleToDirection
=
function
(
angle
)
{
angle
=
(
angle
*
THREE
.
Math
.
RAD2DEG
+
180
+
45
)
%
360
;
if
(
angle
>
0
&&
angle
<
90
)
{
return
"
down
"
;
}
else
if
(
angle
>=
90
&&
angle
<
180
)
{
return
"
left
"
;
}
else
if
(
angle
>=
180
&&
angle
<
270
)
{
return
"
up
"
;
}
else
{
return
"
right
"
;
}
};
AFRAME
.
registerComponent
(
"
axis-dpad
"
,
{
schema
:
{
centerZone
:
{
default
:
0.5
},
moveEvents
:
{
default
:
[
"
axismove
"
]
},
downEvents
:
{
default
:
[
"
trackpaddown
"
,
"
thumbstickdown
"
]
},
upEvents
:
{
default
:
[
"
trackpadup
"
,
"
thumbstickup
"
]
}
},
init
:
function
()
{
this
.
onAxisMove
=
this
.
onAxisMove
.
bind
(
this
);
this
.
onButtonPressed
=
this
.
onButtonPressed
.
bind
(
this
);
this
.
lastPos
=
[
0
,
0
];
},
play
:
function
()
{
const
{
moveEvents
,
downEvents
,
upEvents
}
=
this
.
data
;
moveEvents
.
forEach
(
moveEvent
=>
{
this
.
el
.
addEventListener
(
moveEvent
,
this
.
onAxisMove
);
});
downEvents
.
concat
(
upEvents
).
forEach
(
eventName
=>
{
this
.
el
.
addEventListener
(
eventName
,
this
.
onButtonPressed
);
});
},
pause
:
function
()
{
const
{
moveEvents
,
downEvents
,
upEvents
}
=
this
.
data
;
moveEvents
.
forEach
(
moveEvent
=>
{
this
.
el
.
removeEventListener
(
moveEvent
,
this
.
onAxisMove
);
});
downEvents
.
concat
(
upEvents
).
forEach
(
eventName
=>
{
this
.
el
.
removeEventListener
(
eventName
,
this
.
onButtonPressed
);
});
},
onAxisMove
:
function
(
e
)
{
this
.
lastPos
=
e
.
detail
.
axis
;
},
onButtonPressed
:
function
(
e
)
{
const
[
x
,
y
]
=
this
.
lastPos
;
const
{
upEvents
,
centerZone
}
=
this
.
data
;
const
state
=
upEvents
.
includes
(
e
.
type
)
?
"
up
"
:
"
down
"
;
const
direction
=
state
===
"
up
"
&&
this
.
lastDirection
// Always trigger the up event for the last down event
?
this
.
lastDirection
:
x
*
x
+
y
*
y
<
centerZone
*
centerZone
// If within center zone angle does not matter
?
"
center
"
:
angleToDirection
(
Math
.
atan2
(
x
,
y
));
this
.
el
.
emit
(
`dpad
${
direction
}${
state
}
`
);
if
(
state
===
"
down
"
)
{
this
.
lastDirection
=
direction
;
}
else
{
delete
this
.
lastDirection
;
}
}
});
This diff is collapsed.
Click to expand it.
src/components/snap-rotation.js
0 → 100644
+
62
−
0
View file @
e793f546
/**
* @fileOverview
* Rotate an entity in fixed increments based on events or keyboard input
* @name snap-rotation.js
* @TODO pull keyboard input out into a component that just emits events
* @TODO allow specifying multiple events and sources
*/
AFRAME
.
registerComponent
(
"
snap-rotation
"
,
{
schema
:
{
rotationAxis
:
{
type
:
"
vec3
"
,
default
:
{
x
:
0
,
y
:
1
,
z
:
0
}
},
rotationDegres
:
{
default
:
45
},
leftKey
:
{
default
:
"
q
"
},
leftEvent
:
{
default
:
"
dpadleftdown
"
},
leftEventSrc
:
{
type
:
"
selector
"
},
rightKey
:
{
default
:
"
e
"
},
rightEvent
:
{
default
:
"
dpadrightdown
"
},
rightEventSrc
:
{
type
:
"
selector
"
}
},
init
:
function
()
{
this
.
onButtonPressed
=
this
.
onButtonPressed
.
bind
(
this
);
},
play
:
function
()
{
const
{
leftEventSrc
,
leftEvent
,
rightEventSrc
,
rightEvent
}
=
this
.
data
;
window
.
addEventListener
(
"
keypress
"
,
this
.
onButtonPressed
);
rightEventSrc
&&
rightEventSrc
.
addEventListener
(
rightEvent
,
this
.
onButtonPressed
);
leftEventSrc
&&
leftEventSrc
.
addEventListener
(
leftEvent
,
this
.
onButtonPressed
);
},
pause
:
function
()
{
const
{
leftEventSrc
,
leftEvent
,
rightEventSrc
,
rightEvent
}
=
this
.
data
;
window
.
removeEventListener
(
"
keypress
"
,
this
.
onButtonPRessed
);
rightEventSrc
&&
rightEventSrc
.
removeEventListener
(
rightEvent
,
this
.
onButtonPressed
);
leftEventSrc
&&
leftEventSrc
.
removeEventListener
(
leftEvent
,
this
.
onButtonPressed
);
},
onButtonPressed
:
function
(
e
)
{
const
{
rotationAxis
,
rotationDegres
,
leftKey
,
leftEvent
,
rightKey
,
rightEvent
}
=
this
.
data
;
const
obj
=
this
.
el
.
object3D
;
if
(
e
.
type
===
leftEvent
||
(
leftKey
&&
e
.
key
===
leftKey
))
{
obj
.
rotateOnAxis
(
rotationAxis
,
rotationDegres
*
THREE
.
Math
.
DEG2RAD
);
}
else
if
(
e
.
type
===
rightEvent
||
(
rightKey
&&
e
.
key
===
rightKey
))
{
obj
.
rotateOnAxis
(
rotationAxis
,
-
rotationDegres
*
THREE
.
Math
.
DEG2RAD
);
}
}
});
This diff is collapsed.
Click to expand it.
src/index.js
+
5
−
2
View file @
e793f546
require
(
"
networked-aframe
"
);
require
(
"
networked-aframe
"
);
require
(
"
./components/rig-selector
"
);
require
(
"
aframe-teleport-controls
"
);
require
(
'
aframe-teleport-controls
'
);
// require("./components/rig-selector");
require
(
"
./components/axis-dpad
"
);
require
(
"
./components/snap-rotation
"
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment