michael@0: michael@0: /* michael@0: * Copyright 2006 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #include "SkDraw3D.h" michael@0: #include "SkAnimateMaker.h" michael@0: #include "SkCanvas.h" michael@0: #include "SkTypedArray.h" michael@0: michael@0: #if SK_USE_CONDENSED_INFO == 0 michael@0: michael@0: const SkMemberInfo Sk3D_Point::fInfo[] = { michael@0: SK_MEMBER_ALIAS(x, fPoint.fX, Float), michael@0: SK_MEMBER_ALIAS(y, fPoint.fY, Float), michael@0: SK_MEMBER_ALIAS(z, fPoint.fZ, Float) michael@0: }; michael@0: michael@0: #endif michael@0: michael@0: DEFINE_NO_VIRTUALS_GET_MEMBER(Sk3D_Point); michael@0: michael@0: Sk3D_Point::Sk3D_Point() { michael@0: fPoint.set(0, 0, 0); michael@0: } michael@0: michael@0: #if SK_USE_CONDENSED_INFO == 0 michael@0: michael@0: const SkMemberInfo Sk3D_Camera::fInfo[] = { michael@0: SK_MEMBER_ALIAS(axis, fCamera.fAxis, 3D_Point), michael@0: SK_MEMBER(hackHeight, Float), michael@0: SK_MEMBER(hackWidth, Float), michael@0: SK_MEMBER_ALIAS(location, fCamera.fLocation, 3D_Point), michael@0: SK_MEMBER_ALIAS(observer, fCamera.fObserver, 3D_Point), michael@0: SK_MEMBER(patch, 3D_Patch), michael@0: SK_MEMBER_ALIAS(zenith, fCamera.fZenith, 3D_Point), michael@0: }; michael@0: michael@0: #endif michael@0: michael@0: DEFINE_GET_MEMBER(Sk3D_Camera); michael@0: michael@0: Sk3D_Camera::Sk3D_Camera() : hackWidth(0), hackHeight(0), patch(NULL) { michael@0: } michael@0: michael@0: Sk3D_Camera::~Sk3D_Camera() { michael@0: } michael@0: michael@0: bool Sk3D_Camera::draw(SkAnimateMaker& maker) { michael@0: fCamera.update(); michael@0: SkMatrix matrix; michael@0: fCamera.patchToMatrix(patch->fPatch, &matrix); michael@0: matrix.preTranslate(hackWidth / 2, -hackHeight / 2); michael@0: matrix.postTranslate(hackWidth / 2, hackHeight / 2); michael@0: maker.fCanvas->concat(matrix); michael@0: return false; michael@0: } michael@0: michael@0: michael@0: enum Sk3D_Patch_Functions { michael@0: SK_FUNCTION(rotateDegrees) michael@0: }; michael@0: michael@0: const SkFunctionParamType Sk3D_Patch::fFunctionParameters[] = { michael@0: (SkFunctionParamType) SkType_Float, michael@0: (SkFunctionParamType) SkType_Float, michael@0: (SkFunctionParamType) SkType_Float, michael@0: (SkFunctionParamType) 0 // terminator for parameter list (there may be multiple parameter lists) michael@0: }; michael@0: michael@0: #if SK_USE_CONDENSED_INFO == 0 michael@0: michael@0: const SkMemberInfo Sk3D_Patch::fInfo[] = { michael@0: SK_MEMBER_ALIAS(origin, fPatch.fOrigin, 3D_Point), michael@0: SK_MEMBER_FUNCTION(rotateDegrees, Float), michael@0: SK_MEMBER_ALIAS(u, fPatch.fU, 3D_Point), michael@0: SK_MEMBER_ALIAS(v, fPatch.fV, 3D_Point) michael@0: }; michael@0: michael@0: #endif michael@0: michael@0: DEFINE_GET_MEMBER(Sk3D_Patch); michael@0: michael@0: void Sk3D_Patch::executeFunction(SkDisplayable* target, int index, michael@0: SkTDArray& parameters, SkDisplayTypes type, michael@0: SkScriptValue* ) { michael@0: SkASSERT(target == this); michael@0: switch (index) { michael@0: case SK_FUNCTION(rotateDegrees): michael@0: SkASSERT(parameters.count() == 3); michael@0: SkASSERT(type == SkType_Float); michael@0: fPatch.rotateDegrees(parameters[0].fOperand.fScalar, michael@0: parameters[1].fOperand.fScalar, parameters[2].fOperand.fScalar); michael@0: break; michael@0: default: michael@0: SkASSERT(0); michael@0: } michael@0: } michael@0: michael@0: const SkFunctionParamType* Sk3D_Patch::getFunctionsParameters() { michael@0: return fFunctionParameters; michael@0: }