blob: e7e92df3e30c0c90fa1ecfe2147abd7a9a685cec [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2006 The Android Open Source Project
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
reed@android.com8a1c16f2008-12-17 15:59:43 +00009
10#include "SkDraw3D.h"
11#include "SkAnimateMaker.h"
12#include "SkCanvas.h"
13#include "SkTypedArray.h"
14
15#if SK_USE_CONDENSED_INFO == 0
16
17const SkMemberInfo Sk3D_Point::fInfo[] = {
18 SK_MEMBER_ALIAS(x, fPoint.fX, Float),
19 SK_MEMBER_ALIAS(y, fPoint.fY, Float),
20 SK_MEMBER_ALIAS(z, fPoint.fZ, Float)
21};
22
23#endif
24
25DEFINE_NO_VIRTUALS_GET_MEMBER(Sk3D_Point);
26
27Sk3D_Point::Sk3D_Point() {
rmistry@google.comd6176b02012-08-23 18:14:13 +000028 fPoint.set(0, 0, 0);
reed@android.com8a1c16f2008-12-17 15:59:43 +000029}
30
31#if SK_USE_CONDENSED_INFO == 0
32
33const SkMemberInfo Sk3D_Camera::fInfo[] = {
34 SK_MEMBER_ALIAS(axis, fCamera.fAxis, 3D_Point),
35 SK_MEMBER(hackHeight, Float),
36 SK_MEMBER(hackWidth, Float),
37 SK_MEMBER_ALIAS(location, fCamera.fLocation, 3D_Point),
38 SK_MEMBER_ALIAS(observer, fCamera.fObserver, 3D_Point),
39 SK_MEMBER(patch, 3D_Patch),
40 SK_MEMBER_ALIAS(zenith, fCamera.fZenith, 3D_Point),
41};
42
43#endif
44
45DEFINE_GET_MEMBER(Sk3D_Camera);
46
halcanary96fcdcc2015-08-27 07:41:13 -070047Sk3D_Camera::Sk3D_Camera() : hackWidth(0), hackHeight(0), patch(nullptr) {
reed@android.com8a1c16f2008-12-17 15:59:43 +000048}
49
50Sk3D_Camera::~Sk3D_Camera() {
51}
52
53bool Sk3D_Camera::draw(SkAnimateMaker& maker) {
54 fCamera.update();
55 SkMatrix matrix;
56 fCamera.patchToMatrix(patch->fPatch, &matrix);
57 matrix.preTranslate(hackWidth / 2, -hackHeight / 2);
58 matrix.postTranslate(hackWidth / 2, hackHeight / 2);
59 maker.fCanvas->concat(matrix);
60 return false;
61}
62
63
64enum Sk3D_Patch_Functions {
65 SK_FUNCTION(rotateDegrees)
66};
67
68const SkFunctionParamType Sk3D_Patch::fFunctionParameters[] = {
69 (SkFunctionParamType) SkType_Float,
70 (SkFunctionParamType) SkType_Float,
71 (SkFunctionParamType) SkType_Float,
72 (SkFunctionParamType) 0 // terminator for parameter list (there may be multiple parameter lists)
73};
74
75#if SK_USE_CONDENSED_INFO == 0
76
77const SkMemberInfo Sk3D_Patch::fInfo[] = {
78 SK_MEMBER_ALIAS(origin, fPatch.fOrigin, 3D_Point),
79 SK_MEMBER_FUNCTION(rotateDegrees, Float),
80 SK_MEMBER_ALIAS(u, fPatch.fU, 3D_Point),
81 SK_MEMBER_ALIAS(v, fPatch.fV, 3D_Point)
82};
83
84#endif
85
86DEFINE_GET_MEMBER(Sk3D_Patch);
87
rmistry@google.comd6176b02012-08-23 18:14:13 +000088void Sk3D_Patch::executeFunction(SkDisplayable* target, int index,
reed@android.com8a1c16f2008-12-17 15:59:43 +000089 SkTDArray<SkScriptValue>& parameters, SkDisplayTypes type,
90 SkScriptValue* ) {
91 SkASSERT(target == this);
92 switch (index) {
93 case SK_FUNCTION(rotateDegrees):
94 SkASSERT(parameters.count() == 3);
95 SkASSERT(type == SkType_Float);
rmistry@google.comd6176b02012-08-23 18:14:13 +000096 fPatch.rotateDegrees(parameters[0].fOperand.fScalar,
reed@android.com8a1c16f2008-12-17 15:59:43 +000097 parameters[1].fOperand.fScalar, parameters[2].fOperand.fScalar);
98 break;
99 default:
100 SkASSERT(0);
101 }
102}
103
104const SkFunctionParamType* Sk3D_Patch::getFunctionsParameters() {
105 return fFunctionParameters;
106}