Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Side by Side Diff: third_party/WebKit/Source/modules/sensor/OrientationSensor.cpp

Issue 2746573002: [Sensors] Implement bindings for AbsoluteOrientationSensor (Closed)
Patch Set: [Sensors] Implement bindings for AbsoluteOrientationSensor Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "modules/sensor/OrientationSensor.h"
6
7 #include "bindings/core/v8/ExceptionState.h"
8
9 using device::mojom::blink::SensorType;
10
11 namespace blink {
12
13 Vector<double> OrientationSensor::quaternion(bool& isNull) const {
14 isNull = !canReturnReadings();
shalamov 2017/03/23 08:41:06 Can we return [SameObject] unless reading is chang
Mikhail 2017/03/24 14:47:09 Cached using [CachedAttribute]
15 return isNull ? Vector<double>()
16 : Vector<double>({readingValueUnchecked(3), // W
17 readingValueUnchecked(0), // Vx
18 readingValueUnchecked(1), // Vy
19 readingValueUnchecked(2)}); // Vz
20 }
21
22 void OrientationSensor::populateMatrix(DOMFloat32Array* buffer,
23 ExceptionState& exceptionState) {
24 if (buffer->length() < 16) {
25 exceptionState.throwTypeError(
26 "Target buffer must have minimal size of 16.");
27 return;
28 }
29 if (!isActivated()) {
30 exceptionState.throwDOMException(
31 InvalidStateError, "The Sensor must be in 'connected' state.");
32 return;
33 }
34 if (!canReturnReadings())
35 return;
36
37 float x = readingValueUnchecked(0);
38 float y = readingValueUnchecked(1);
39 float z = readingValueUnchecked(2);
40 float w = readingValueUnchecked(3);
41
42 float* out = buffer->data();
43 out[0] = 1.0 - 2 * (y * y - z * z);
44 out[1] = 2 * (x * y - z * w);
45 out[2] = 2 * (x * z + y * w);
46 out[4] = 2 * (x * y + z * w);
47 out[5] = 1.0 - 2 * (x * x - z * z);
48 out[6] = 2 * (y * z - x * w);
49 out[8] = 2 * (x * z - y * w);
50 out[9] = 2 * (y * z + x * w);
51 out[10] = 1.0 - 2 * (x * x - y * y);
52 out[15] = 1.0;
53 }
54
55 OrientationSensor::OrientationSensor(ExecutionContext* executionContext,
56 const SensorOptions& options,
57 ExceptionState& exceptionState,
58 device::mojom::blink::SensorType type)
59 : Sensor(executionContext, options, exceptionState, type) {}
60
61 DEFINE_TRACE(OrientationSensor) {
62 Sensor::trace(visitor);
63 }
64
65 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698