OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/vr/VRPositionState.h" | 5 #include "modules/vr/VRPositionState.h" |
6 | 6 |
7 #include "bindings/core/v8/GeometryInterfaces.h" | |
8 | |
7 namespace blink { | 9 namespace blink { |
8 | 10 |
9 namespace { | 11 namespace { |
10 | 12 |
11 DOMPoint* vecToDomPoint(const WebVRVector4& vec, bool valid) | 13 ScriptValue vecToDomPoint(ScriptState* scriptState, const WebVRVector4& vec, boo l valid) |
12 { | 14 { |
13 if (valid) | 15 if (valid) |
14 return DOMPoint::create(vec.x, vec.y, vec.z, vec.w); | 16 return GeometryInterfaces::createDOMPoint(scriptState, vec.x, vec.y, vec .z, vec.w); |
15 return nullptr; | 17 return ScriptValue::createNull(scriptState); |
16 } | 18 } |
17 DOMPoint* vecToDomPoint(const WebVRVector3& vec, bool valid) | 19 ScriptValue vecToDomPoint(ScriptState* scriptState, const WebVRVector3& vec, boo l valid) |
18 { | 20 { |
19 if (valid) | 21 if (valid) |
20 return DOMPoint::create(vec.x, vec.y, vec.z, 1.0); | 22 return GeometryInterfaces::createDOMPoint(scriptState, vec.x, vec.y, vec .z, 1.0); |
21 return nullptr; | 23 return ScriptValue::createNull(scriptState); |
22 } | 24 } |
23 | 25 |
24 } // namespace | 26 } // namespace |
25 | 27 |
26 VRPositionState::VRPositionState() | 28 VRPositionState::VRPositionState() |
27 : m_timeStamp(0.0) | 29 : m_timeStamp(0.0) |
28 { | 30 { |
29 } | 31 } |
30 | 32 |
31 void VRPositionState::setState(const WebHMDSensorState &state) | 33 void VRPositionState::setState(const WebHMDSensorState &state) |
32 { | 34 { |
33 m_timeStamp = state.timestamp; | 35 m_timeStamp = state.timestamp; |
34 m_orientation = vecToDomPoint(state.orientation, state.flags & WebVRSensorSt ateOrientation); | 36 m_state = state; |
35 m_position = vecToDomPoint(state.position, state.flags & WebVRSensorStatePos ition); | 37 } |
36 m_angularVelocity = vecToDomPoint(state.angularVelocity, state.flags & WebVR SensorStateAngularVelocity); | 38 |
37 m_linearVelocity = vecToDomPoint(state.linearVelocity, state.flags & WebVRSe nsorStateLinearVelocity); | 39 ScriptValue& VRPositionState::orientation(ScriptState* scriptState) |
38 m_angularAcceleration = vecToDomPoint(state.angularAcceleration, state.flags & WebVRSensorStateAngularAcceleration); | 40 { |
39 m_linearAcceleration = vecToDomPoint(state.linearAcceleration, state.flags & WebVRSensorStateLinearAcceleration); | 41 m_orientation = vecToDomPoint(scriptState, m_state.orientation, m_state.flag s & WebVRSensorStateOrientation); |
domenic
2016/02/18 19:04:41
This re-creates the ScriptValue every time. I thin
zino
2016/02/22 09:51:01
Done.
| |
42 return m_orientation; | |
43 } | |
44 | |
45 ScriptValue& VRPositionState::position(ScriptState* scriptState) | |
46 { | |
47 m_position = vecToDomPoint(scriptState, m_state.position, m_state.flags & We bVRSensorStatePosition); | |
48 return m_position; | |
49 } | |
50 | |
51 ScriptValue& VRPositionState::angularVelocity(ScriptState* scriptState) | |
52 { | |
53 m_angularVelocity = vecToDomPoint(scriptState, m_state.angularVelocity, m_st ate.flags & WebVRSensorStateAngularVelocity); | |
54 return m_angularVelocity; | |
55 } | |
56 | |
57 ScriptValue& VRPositionState::linearVelocity(ScriptState* scriptState) | |
58 { | |
59 m_linearVelocity = vecToDomPoint(scriptState, m_state.linearVelocity, m_stat e.flags & WebVRSensorStateLinearVelocity); | |
60 return m_linearVelocity; | |
61 } | |
62 | |
63 ScriptValue& VRPositionState::angularAcceleration(ScriptState* scriptState) | |
64 { | |
65 m_angularAcceleration = vecToDomPoint(scriptState, m_state.angularAccelerati on, m_state.flags & WebVRSensorStateAngularAcceleration); | |
66 return m_angularAcceleration; | |
67 } | |
68 | |
69 ScriptValue& VRPositionState::linearAcceleration(ScriptState* scriptState) | |
70 { | |
71 m_linearAcceleration = vecToDomPoint(scriptState, m_state.linearAcceleratio n, m_state.flags & WebVRSensorStateLinearAcceleration); | |
72 return m_linearAcceleration; | |
40 } | 73 } |
41 | 74 |
42 DEFINE_TRACE(VRPositionState) | 75 DEFINE_TRACE(VRPositionState) |
43 { | 76 { |
44 visitor->trace(m_orientation); | |
45 visitor->trace(m_position); | |
46 visitor->trace(m_angularVelocity); | |
47 visitor->trace(m_linearVelocity); | |
48 visitor->trace(m_angularAcceleration); | |
49 visitor->trace(m_linearAcceleration); | |
50 } | 77 } |
51 | 78 |
52 } // namespace blink | 79 } // namespace blink |
OLD | NEW |