1 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 9 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 17 const 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 25 DEFINE_NO_VIRTUALS_GET_MEMBER(Sk3D_Point); 26 27 Sk3D_Point::Sk3D_Point() { 28 fPoint.set(0, 0, 0); 29 } 30 31 #if SK_USE_CONDENSED_INFO == 0 32 33 const 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 45 DEFINE_GET_MEMBER(Sk3D_Camera); 46 47 Sk3D_Camera::Sk3D_Camera() : hackWidth(0), hackHeight(0), patch(NULL) { 48 } 49 50 Sk3D_Camera::~Sk3D_Camera() { 51 } 52 53 bool 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 64 enum Sk3D_Patch_Functions { 65 SK_FUNCTION(rotateDegrees) 66 }; 67 68 const 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 77 const 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 86 DEFINE_GET_MEMBER(Sk3D_Patch); 87 88 void Sk3D_Patch::executeFunction(SkDisplayable* target, int index, 89 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); 96 fPatch.rotateDegrees(parameters[0].fOperand.fScalar, 97 parameters[1].fOperand.fScalar, parameters[2].fOperand.fScalar); 98 break; 99 default: 100 SkASSERT(0); 101 } 102 } 103 104 const SkFunctionParamType* Sk3D_Patch::getFunctionsParameters() { 105 return fFunctionParameters; 106 } 107