blob: 137de9f048fad57af2454f9c0c62165a160f722a [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/* libs/graphics/animator/SkDraw3D.cpp
2**
3** Copyright 2006, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#include "SkDraw3D.h"
19#include "SkAnimateMaker.h"
20#include "SkCanvas.h"
21#include "SkTypedArray.h"
22
23#if SK_USE_CONDENSED_INFO == 0
24
25const SkMemberInfo Sk3D_Point::fInfo[] = {
26 SK_MEMBER_ALIAS(x, fPoint.fX, Float),
27 SK_MEMBER_ALIAS(y, fPoint.fY, Float),
28 SK_MEMBER_ALIAS(z, fPoint.fZ, Float)
29};
30
31#endif
32
33DEFINE_NO_VIRTUALS_GET_MEMBER(Sk3D_Point);
34
35Sk3D_Point::Sk3D_Point() {
36 fPoint.set(0, 0, 0);
37}
38
39#if SK_USE_CONDENSED_INFO == 0
40
41const SkMemberInfo Sk3D_Camera::fInfo[] = {
42 SK_MEMBER_ALIAS(axis, fCamera.fAxis, 3D_Point),
43 SK_MEMBER(hackHeight, Float),
44 SK_MEMBER(hackWidth, Float),
45 SK_MEMBER_ALIAS(location, fCamera.fLocation, 3D_Point),
46 SK_MEMBER_ALIAS(observer, fCamera.fObserver, 3D_Point),
47 SK_MEMBER(patch, 3D_Patch),
48 SK_MEMBER_ALIAS(zenith, fCamera.fZenith, 3D_Point),
49};
50
51#endif
52
53DEFINE_GET_MEMBER(Sk3D_Camera);
54
55Sk3D_Camera::Sk3D_Camera() : hackWidth(0), hackHeight(0), patch(NULL) {
56}
57
58Sk3D_Camera::~Sk3D_Camera() {
59}
60
61bool Sk3D_Camera::draw(SkAnimateMaker& maker) {
62 fCamera.update();
63 SkMatrix matrix;
64 fCamera.patchToMatrix(patch->fPatch, &matrix);
65 matrix.preTranslate(hackWidth / 2, -hackHeight / 2);
66 matrix.postTranslate(hackWidth / 2, hackHeight / 2);
67 maker.fCanvas->concat(matrix);
68 return false;
69}
70
71
72enum Sk3D_Patch_Functions {
73 SK_FUNCTION(rotateDegrees)
74};
75
76const SkFunctionParamType Sk3D_Patch::fFunctionParameters[] = {
77 (SkFunctionParamType) SkType_Float,
78 (SkFunctionParamType) SkType_Float,
79 (SkFunctionParamType) SkType_Float,
80 (SkFunctionParamType) 0 // terminator for parameter list (there may be multiple parameter lists)
81};
82
83#if SK_USE_CONDENSED_INFO == 0
84
85const SkMemberInfo Sk3D_Patch::fInfo[] = {
86 SK_MEMBER_ALIAS(origin, fPatch.fOrigin, 3D_Point),
87 SK_MEMBER_FUNCTION(rotateDegrees, Float),
88 SK_MEMBER_ALIAS(u, fPatch.fU, 3D_Point),
89 SK_MEMBER_ALIAS(v, fPatch.fV, 3D_Point)
90};
91
92#endif
93
94DEFINE_GET_MEMBER(Sk3D_Patch);
95
96void Sk3D_Patch::executeFunction(SkDisplayable* target, int index,
97 SkTDArray<SkScriptValue>& parameters, SkDisplayTypes type,
98 SkScriptValue* ) {
99 SkASSERT(target == this);
100 switch (index) {
101 case SK_FUNCTION(rotateDegrees):
102 SkASSERT(parameters.count() == 3);
103 SkASSERT(type == SkType_Float);
104 fPatch.rotateDegrees(parameters[0].fOperand.fScalar,
105 parameters[1].fOperand.fScalar, parameters[2].fOperand.fScalar);
106 break;
107 default:
108 SkASSERT(0);
109 }
110}
111
112const SkFunctionParamType* Sk3D_Patch::getFunctionsParameters() {
113 return fFunctionParameters;
114}
115
116
117