1*bebae9c0SAndroid Build Coastguard Worker /*
2*bebae9c0SAndroid Build Coastguard Worker * Copyright (C) 2010 The Android Open Source Project
3*bebae9c0SAndroid Build Coastguard Worker *
4*bebae9c0SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*bebae9c0SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*bebae9c0SAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*bebae9c0SAndroid Build Coastguard Worker *
8*bebae9c0SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*bebae9c0SAndroid Build Coastguard Worker *
10*bebae9c0SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*bebae9c0SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*bebae9c0SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*bebae9c0SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*bebae9c0SAndroid Build Coastguard Worker * limitations under the License.
15*bebae9c0SAndroid Build Coastguard Worker */
16*bebae9c0SAndroid Build Coastguard Worker
17*bebae9c0SAndroid Build Coastguard Worker /* 3DMacroscopic implementation */
18*bebae9c0SAndroid Build Coastguard Worker
19*bebae9c0SAndroid Build Coastguard Worker #include "sles_allinclusive.h"
20*bebae9c0SAndroid Build Coastguard Worker
21*bebae9c0SAndroid Build Coastguard Worker
I3DMacroscopic_SetSize(SL3DMacroscopicItf self,SLmillimeter width,SLmillimeter height,SLmillimeter depth)22*bebae9c0SAndroid Build Coastguard Worker static SLresult I3DMacroscopic_SetSize(SL3DMacroscopicItf self,
23*bebae9c0SAndroid Build Coastguard Worker SLmillimeter width, SLmillimeter height, SLmillimeter depth)
24*bebae9c0SAndroid Build Coastguard Worker {
25*bebae9c0SAndroid Build Coastguard Worker SL_ENTER_INTERFACE
26*bebae9c0SAndroid Build Coastguard Worker
27*bebae9c0SAndroid Build Coastguard Worker if (!((0 <= width) && (width <= SL_MILLIMETER_MAX) &&
28*bebae9c0SAndroid Build Coastguard Worker (0 <= height) && (height <= SL_MILLIMETER_MAX) &&
29*bebae9c0SAndroid Build Coastguard Worker (0 <= depth) && (depth <= SL_MILLIMETER_MAX))) {
30*bebae9c0SAndroid Build Coastguard Worker result = SL_RESULT_PARAMETER_INVALID;
31*bebae9c0SAndroid Build Coastguard Worker } else {
32*bebae9c0SAndroid Build Coastguard Worker I3DMacroscopic *thiz = (I3DMacroscopic *) self;
33*bebae9c0SAndroid Build Coastguard Worker interface_lock_exclusive(thiz);
34*bebae9c0SAndroid Build Coastguard Worker thiz->mSize.mWidth = width;
35*bebae9c0SAndroid Build Coastguard Worker thiz->mSize.mHeight = height;
36*bebae9c0SAndroid Build Coastguard Worker thiz->mSize.mDepth = depth;
37*bebae9c0SAndroid Build Coastguard Worker interface_unlock_exclusive(thiz);
38*bebae9c0SAndroid Build Coastguard Worker result = SL_RESULT_SUCCESS;
39*bebae9c0SAndroid Build Coastguard Worker }
40*bebae9c0SAndroid Build Coastguard Worker
41*bebae9c0SAndroid Build Coastguard Worker SL_LEAVE_INTERFACE
42*bebae9c0SAndroid Build Coastguard Worker }
43*bebae9c0SAndroid Build Coastguard Worker
44*bebae9c0SAndroid Build Coastguard Worker
I3DMacroscopic_GetSize(SL3DMacroscopicItf self,SLmillimeter * pWidth,SLmillimeter * pHeight,SLmillimeter * pDepth)45*bebae9c0SAndroid Build Coastguard Worker static SLresult I3DMacroscopic_GetSize(SL3DMacroscopicItf self,
46*bebae9c0SAndroid Build Coastguard Worker SLmillimeter *pWidth, SLmillimeter *pHeight, SLmillimeter *pDepth)
47*bebae9c0SAndroid Build Coastguard Worker {
48*bebae9c0SAndroid Build Coastguard Worker SL_ENTER_INTERFACE
49*bebae9c0SAndroid Build Coastguard Worker
50*bebae9c0SAndroid Build Coastguard Worker if (NULL == pWidth || NULL == pHeight || NULL == pDepth) {
51*bebae9c0SAndroid Build Coastguard Worker result = SL_RESULT_PARAMETER_INVALID;
52*bebae9c0SAndroid Build Coastguard Worker } else {
53*bebae9c0SAndroid Build Coastguard Worker I3DMacroscopic *thiz = (I3DMacroscopic *) self;
54*bebae9c0SAndroid Build Coastguard Worker interface_lock_shared(thiz);
55*bebae9c0SAndroid Build Coastguard Worker SLmillimeter width = thiz->mSize.mWidth;
56*bebae9c0SAndroid Build Coastguard Worker SLmillimeter height = thiz->mSize.mHeight;
57*bebae9c0SAndroid Build Coastguard Worker SLmillimeter depth = thiz->mSize.mDepth;
58*bebae9c0SAndroid Build Coastguard Worker interface_unlock_shared(thiz);
59*bebae9c0SAndroid Build Coastguard Worker *pWidth = width;
60*bebae9c0SAndroid Build Coastguard Worker *pHeight = height;
61*bebae9c0SAndroid Build Coastguard Worker *pDepth = depth;
62*bebae9c0SAndroid Build Coastguard Worker result = SL_RESULT_SUCCESS;
63*bebae9c0SAndroid Build Coastguard Worker }
64*bebae9c0SAndroid Build Coastguard Worker
65*bebae9c0SAndroid Build Coastguard Worker SL_LEAVE_INTERFACE
66*bebae9c0SAndroid Build Coastguard Worker }
67*bebae9c0SAndroid Build Coastguard Worker
68*bebae9c0SAndroid Build Coastguard Worker
I3DMacroscopic_SetOrientationAngles(SL3DMacroscopicItf self,SLmillidegree heading,SLmillidegree pitch,SLmillidegree roll)69*bebae9c0SAndroid Build Coastguard Worker static SLresult I3DMacroscopic_SetOrientationAngles(SL3DMacroscopicItf self,
70*bebae9c0SAndroid Build Coastguard Worker SLmillidegree heading, SLmillidegree pitch, SLmillidegree roll)
71*bebae9c0SAndroid Build Coastguard Worker {
72*bebae9c0SAndroid Build Coastguard Worker SL_ENTER_INTERFACE
73*bebae9c0SAndroid Build Coastguard Worker
74*bebae9c0SAndroid Build Coastguard Worker if (!((-360000 <= heading) && (heading <= 360000) &&
75*bebae9c0SAndroid Build Coastguard Worker (-90000 <= pitch) && (pitch <= 90000) &&
76*bebae9c0SAndroid Build Coastguard Worker (-360000 <= roll) && (roll <= 360000))) {
77*bebae9c0SAndroid Build Coastguard Worker result = SL_RESULT_PARAMETER_INVALID;
78*bebae9c0SAndroid Build Coastguard Worker } else {
79*bebae9c0SAndroid Build Coastguard Worker I3DMacroscopic *thiz = (I3DMacroscopic *) self;
80*bebae9c0SAndroid Build Coastguard Worker interface_lock_exclusive(thiz);
81*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationAngles.mHeading = heading;
82*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationAngles.mPitch = pitch;
83*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationAngles.mRoll = roll;
84*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationActive = ANGLES_SET_VECTORS_UNKNOWN;
85*bebae9c0SAndroid Build Coastguard Worker thiz->mRotatePending = SL_BOOLEAN_FALSE;
86*bebae9c0SAndroid Build Coastguard Worker // ++thiz->mGeneration;
87*bebae9c0SAndroid Build Coastguard Worker interface_unlock_exclusive(thiz);
88*bebae9c0SAndroid Build Coastguard Worker result = SL_RESULT_SUCCESS;
89*bebae9c0SAndroid Build Coastguard Worker }
90*bebae9c0SAndroid Build Coastguard Worker
91*bebae9c0SAndroid Build Coastguard Worker SL_LEAVE_INTERFACE
92*bebae9c0SAndroid Build Coastguard Worker }
93*bebae9c0SAndroid Build Coastguard Worker
94*bebae9c0SAndroid Build Coastguard Worker
I3DMacroscopic_SetOrientationVectors(SL3DMacroscopicItf self,const SLVec3D * pFront,const SLVec3D * pAbove)95*bebae9c0SAndroid Build Coastguard Worker static SLresult I3DMacroscopic_SetOrientationVectors(SL3DMacroscopicItf self,
96*bebae9c0SAndroid Build Coastguard Worker const SLVec3D *pFront, const SLVec3D *pAbove)
97*bebae9c0SAndroid Build Coastguard Worker {
98*bebae9c0SAndroid Build Coastguard Worker SL_ENTER_INTERFACE
99*bebae9c0SAndroid Build Coastguard Worker
100*bebae9c0SAndroid Build Coastguard Worker if (NULL == pFront || NULL == pAbove) {
101*bebae9c0SAndroid Build Coastguard Worker result = SL_RESULT_PARAMETER_INVALID;
102*bebae9c0SAndroid Build Coastguard Worker } else {
103*bebae9c0SAndroid Build Coastguard Worker I3DMacroscopic *thiz = (I3DMacroscopic *) self;
104*bebae9c0SAndroid Build Coastguard Worker SLVec3D front = *pFront;
105*bebae9c0SAndroid Build Coastguard Worker SLVec3D above = *pAbove;
106*bebae9c0SAndroid Build Coastguard Worker // NTH Check for vectors close to zero or close to parallel
107*bebae9c0SAndroid Build Coastguard Worker interface_lock_exclusive(thiz);
108*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationVectors.mFront = front;
109*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationVectors.mAbove = above;
110*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationVectors.mUp = above; // wrong
111*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationActive = ANGLES_UNKNOWN_VECTORS_SET;
112*bebae9c0SAndroid Build Coastguard Worker thiz->mRotatePending = SL_BOOLEAN_FALSE;
113*bebae9c0SAndroid Build Coastguard Worker interface_unlock_exclusive(thiz);
114*bebae9c0SAndroid Build Coastguard Worker result = SL_RESULT_SUCCESS;
115*bebae9c0SAndroid Build Coastguard Worker }
116*bebae9c0SAndroid Build Coastguard Worker
117*bebae9c0SAndroid Build Coastguard Worker SL_LEAVE_INTERFACE
118*bebae9c0SAndroid Build Coastguard Worker }
119*bebae9c0SAndroid Build Coastguard Worker
120*bebae9c0SAndroid Build Coastguard Worker
I3DMacroscopic_Rotate(SL3DMacroscopicItf self,SLmillidegree theta,const SLVec3D * pAxis)121*bebae9c0SAndroid Build Coastguard Worker static SLresult I3DMacroscopic_Rotate(SL3DMacroscopicItf self,
122*bebae9c0SAndroid Build Coastguard Worker SLmillidegree theta, const SLVec3D *pAxis)
123*bebae9c0SAndroid Build Coastguard Worker {
124*bebae9c0SAndroid Build Coastguard Worker SL_ENTER_INTERFACE
125*bebae9c0SAndroid Build Coastguard Worker
126*bebae9c0SAndroid Build Coastguard Worker if (!((-360000 <= theta) && (theta <= 360000)) || NULL == pAxis) {
127*bebae9c0SAndroid Build Coastguard Worker result = SL_RESULT_PARAMETER_INVALID;
128*bebae9c0SAndroid Build Coastguard Worker } else {
129*bebae9c0SAndroid Build Coastguard Worker SLVec3D axis = *pAxis;
130*bebae9c0SAndroid Build Coastguard Worker // NTH Check that axis is not (close to) zero vector, length does not matter
131*bebae9c0SAndroid Build Coastguard Worker I3DMacroscopic *thiz = (I3DMacroscopic *) self;
132*bebae9c0SAndroid Build Coastguard Worker interface_lock_exclusive(thiz);
133*bebae9c0SAndroid Build Coastguard Worker while (thiz->mRotatePending)
134*bebae9c0SAndroid Build Coastguard Worker interface_cond_wait(thiz);
135*bebae9c0SAndroid Build Coastguard Worker thiz->mTheta = theta;
136*bebae9c0SAndroid Build Coastguard Worker thiz->mAxis = axis;
137*bebae9c0SAndroid Build Coastguard Worker thiz->mRotatePending = SL_BOOLEAN_TRUE;
138*bebae9c0SAndroid Build Coastguard Worker interface_unlock_exclusive(thiz);
139*bebae9c0SAndroid Build Coastguard Worker result = SL_RESULT_SUCCESS;
140*bebae9c0SAndroid Build Coastguard Worker }
141*bebae9c0SAndroid Build Coastguard Worker
142*bebae9c0SAndroid Build Coastguard Worker SL_LEAVE_INTERFACE
143*bebae9c0SAndroid Build Coastguard Worker }
144*bebae9c0SAndroid Build Coastguard Worker
145*bebae9c0SAndroid Build Coastguard Worker
I3DMacroscopic_GetOrientationVectors(SL3DMacroscopicItf self,SLVec3D * pFront,SLVec3D * pUp)146*bebae9c0SAndroid Build Coastguard Worker static SLresult I3DMacroscopic_GetOrientationVectors(SL3DMacroscopicItf self,
147*bebae9c0SAndroid Build Coastguard Worker SLVec3D *pFront, SLVec3D *pUp)
148*bebae9c0SAndroid Build Coastguard Worker {
149*bebae9c0SAndroid Build Coastguard Worker SL_ENTER_INTERFACE
150*bebae9c0SAndroid Build Coastguard Worker
151*bebae9c0SAndroid Build Coastguard Worker if (NULL == pFront || NULL == pUp) {
152*bebae9c0SAndroid Build Coastguard Worker result = SL_RESULT_PARAMETER_INVALID;
153*bebae9c0SAndroid Build Coastguard Worker } else {
154*bebae9c0SAndroid Build Coastguard Worker I3DMacroscopic *thiz = (I3DMacroscopic *) self;
155*bebae9c0SAndroid Build Coastguard Worker interface_lock_exclusive(thiz);
156*bebae9c0SAndroid Build Coastguard Worker for (;;) {
157*bebae9c0SAndroid Build Coastguard Worker enum AnglesVectorsActive orientationActive = thiz->mOrientationActive;
158*bebae9c0SAndroid Build Coastguard Worker switch (orientationActive) {
159*bebae9c0SAndroid Build Coastguard Worker case ANGLES_COMPUTED_VECTORS_SET: // not in 1.0.1
160*bebae9c0SAndroid Build Coastguard Worker case ANGLES_REQUESTED_VECTORS_SET: // not in 1.0.1
161*bebae9c0SAndroid Build Coastguard Worker case ANGLES_UNKNOWN_VECTORS_SET:
162*bebae9c0SAndroid Build Coastguard Worker case ANGLES_SET_VECTORS_COMPUTED:
163*bebae9c0SAndroid Build Coastguard Worker {
164*bebae9c0SAndroid Build Coastguard Worker SLVec3D front = thiz->mOrientationVectors.mFront;
165*bebae9c0SAndroid Build Coastguard Worker SLVec3D up = thiz->mOrientationVectors.mUp;
166*bebae9c0SAndroid Build Coastguard Worker interface_unlock_exclusive(thiz);
167*bebae9c0SAndroid Build Coastguard Worker *pFront = front;
168*bebae9c0SAndroid Build Coastguard Worker *pUp = up;
169*bebae9c0SAndroid Build Coastguard Worker }
170*bebae9c0SAndroid Build Coastguard Worker break;
171*bebae9c0SAndroid Build Coastguard Worker case ANGLES_SET_VECTORS_UNKNOWN:
172*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationActive = ANGLES_SET_VECTORS_REQUESTED;
173*bebae9c0SAndroid Build Coastguard Worker FALLTHROUGH_INTENDED;
174*bebae9c0SAndroid Build Coastguard Worker case ANGLES_SET_VECTORS_REQUESTED:
175*bebae9c0SAndroid Build Coastguard Worker // matched by cond_broadcast in case multiple requesters
176*bebae9c0SAndroid Build Coastguard Worker #if 0
177*bebae9c0SAndroid Build Coastguard Worker interface_cond_wait(thiz);
178*bebae9c0SAndroid Build Coastguard Worker #else
179*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationActive = ANGLES_SET_VECTORS_COMPUTED;
180*bebae9c0SAndroid Build Coastguard Worker #endif
181*bebae9c0SAndroid Build Coastguard Worker continue;
182*bebae9c0SAndroid Build Coastguard Worker default:
183*bebae9c0SAndroid Build Coastguard Worker interface_unlock_exclusive(thiz);
184*bebae9c0SAndroid Build Coastguard Worker assert(SL_BOOLEAN_FALSE);
185*bebae9c0SAndroid Build Coastguard Worker pFront->x = 0;
186*bebae9c0SAndroid Build Coastguard Worker pFront->y = 0;
187*bebae9c0SAndroid Build Coastguard Worker pFront->z = 0;
188*bebae9c0SAndroid Build Coastguard Worker pUp->x = 0;
189*bebae9c0SAndroid Build Coastguard Worker pUp->y = 0;
190*bebae9c0SAndroid Build Coastguard Worker pUp->z = 0;
191*bebae9c0SAndroid Build Coastguard Worker break;
192*bebae9c0SAndroid Build Coastguard Worker }
193*bebae9c0SAndroid Build Coastguard Worker break;
194*bebae9c0SAndroid Build Coastguard Worker }
195*bebae9c0SAndroid Build Coastguard Worker result = SL_RESULT_SUCCESS;
196*bebae9c0SAndroid Build Coastguard Worker }
197*bebae9c0SAndroid Build Coastguard Worker
198*bebae9c0SAndroid Build Coastguard Worker SL_LEAVE_INTERFACE
199*bebae9c0SAndroid Build Coastguard Worker }
200*bebae9c0SAndroid Build Coastguard Worker
201*bebae9c0SAndroid Build Coastguard Worker
202*bebae9c0SAndroid Build Coastguard Worker static const struct SL3DMacroscopicItf_ I3DMacroscopic_Itf = {
203*bebae9c0SAndroid Build Coastguard Worker I3DMacroscopic_SetSize,
204*bebae9c0SAndroid Build Coastguard Worker I3DMacroscopic_GetSize,
205*bebae9c0SAndroid Build Coastguard Worker I3DMacroscopic_SetOrientationAngles,
206*bebae9c0SAndroid Build Coastguard Worker I3DMacroscopic_SetOrientationVectors,
207*bebae9c0SAndroid Build Coastguard Worker I3DMacroscopic_Rotate,
208*bebae9c0SAndroid Build Coastguard Worker I3DMacroscopic_GetOrientationVectors
209*bebae9c0SAndroid Build Coastguard Worker };
210*bebae9c0SAndroid Build Coastguard Worker
I3DMacroscopic_init(void * self)211*bebae9c0SAndroid Build Coastguard Worker void I3DMacroscopic_init(void *self)
212*bebae9c0SAndroid Build Coastguard Worker {
213*bebae9c0SAndroid Build Coastguard Worker I3DMacroscopic *thiz = (I3DMacroscopic *) self;
214*bebae9c0SAndroid Build Coastguard Worker thiz->mItf = &I3DMacroscopic_Itf;
215*bebae9c0SAndroid Build Coastguard Worker thiz->mSize.mWidth = 0;
216*bebae9c0SAndroid Build Coastguard Worker thiz->mSize.mHeight = 0;
217*bebae9c0SAndroid Build Coastguard Worker thiz->mSize.mDepth = 0;
218*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationAngles.mHeading = 0;
219*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationAngles.mPitch = 0;
220*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationAngles.mRoll = 0;
221*bebae9c0SAndroid Build Coastguard Worker memset(&thiz->mOrientationVectors, 0x55, sizeof(thiz->mOrientationVectors));
222*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationVectors.mFront.x = 0;
223*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationVectors.mFront.y = 0;
224*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationVectors.mFront.z = -1000;
225*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationVectors.mUp.x = 0;
226*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationVectors.mUp.y = 1000;
227*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationVectors.mUp.z = 0;
228*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationVectors.mAbove.x = 0;
229*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationVectors.mAbove.y = 0;
230*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationVectors.mAbove.z = 0;
231*bebae9c0SAndroid Build Coastguard Worker thiz->mOrientationActive = ANGLES_SET_VECTORS_COMPUTED;
232*bebae9c0SAndroid Build Coastguard Worker thiz->mTheta = 0x55555555;
233*bebae9c0SAndroid Build Coastguard Worker thiz->mAxis.x = 0x55555555;
234*bebae9c0SAndroid Build Coastguard Worker thiz->mAxis.y = 0x55555555;
235*bebae9c0SAndroid Build Coastguard Worker thiz->mAxis.z = 0x55555555;
236*bebae9c0SAndroid Build Coastguard Worker thiz->mRotatePending = SL_BOOLEAN_FALSE;
237*bebae9c0SAndroid Build Coastguard Worker }
238