Tyler Denniston | 32b3089 | 2021-01-26 14:36:32 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "modules/svg/include/SkSVGAttributeParser.h" |
| 9 | #include "modules/svg/include/SkSVGFeLightSource.h" |
| 10 | #include "modules/svg/include/SkSVGValue.h" |
| 11 | |
Tyler Denniston | 8cfe718 | 2021-04-29 14:54:25 -0400 | [diff] [blame] | 12 | SkPoint3 SkSVGFeDistantLight::computeDirection() const { |
| 13 | // Computing direction from azimuth+elevation is two 3D rotations: |
| 14 | // - Rotate [1,0,0] about y axis first (elevation) |
| 15 | // - Rotate result about z axis (azimuth) |
| 16 | // Which is just the first column vector in the 3x3 matrix Rz*Ry. |
| 17 | const float azimuthRad = SkDegreesToRadians(fAzimuth); |
| 18 | const float elevationRad = SkDegreesToRadians(fElevation); |
| 19 | const float sinAzimuth = sinf(azimuthRad), cosAzimuth = cosf(azimuthRad); |
| 20 | const float sinElevation = sinf(elevationRad), cosElevation = cosf(elevationRad); |
| 21 | return SkPoint3::Make(cosAzimuth * cosElevation, sinAzimuth * cosElevation, sinElevation); |
| 22 | } |
| 23 | |
Tyler Denniston | 32b3089 | 2021-01-26 14:36:32 -0500 | [diff] [blame] | 24 | bool SkSVGFeDistantLight::parseAndSetAttribute(const char* n, const char* v) { |
| 25 | return INHERITED::parseAndSetAttribute(n, v) || |
| 26 | this->setAzimuth(SkSVGAttributeParser::parse<SkSVGNumberType>("azimuth", n, v)) || |
| 27 | this->setElevation(SkSVGAttributeParser::parse<SkSVGNumberType>("elevation", n, v)); |
| 28 | } |
| 29 | |
| 30 | bool SkSVGFePointLight::parseAndSetAttribute(const char* n, const char* v) { |
| 31 | return INHERITED::parseAndSetAttribute(n, v) || |
| 32 | this->setX(SkSVGAttributeParser::parse<SkSVGNumberType>("x", n, v)) || |
| 33 | this->setY(SkSVGAttributeParser::parse<SkSVGNumberType>("y", n, v)) || |
| 34 | this->setZ(SkSVGAttributeParser::parse<SkSVGNumberType>("z", n, v)); |
| 35 | } |
| 36 | |
| 37 | bool SkSVGFeSpotLight::parseAndSetAttribute(const char* n, const char* v) { |
| 38 | return INHERITED::parseAndSetAttribute(n, v) || |
| 39 | this->setX(SkSVGAttributeParser::parse<SkSVGNumberType>("x", n, v)) || |
| 40 | this->setY(SkSVGAttributeParser::parse<SkSVGNumberType>("y", n, v)) || |
| 41 | this->setZ(SkSVGAttributeParser::parse<SkSVGNumberType>("z", n, v)) || |
| 42 | this->setPointsAtX(SkSVGAttributeParser::parse<SkSVGNumberType>("pointsAtX", n, v)) || |
| 43 | this->setPointsAtY(SkSVGAttributeParser::parse<SkSVGNumberType>("pointsAtY", n, v)) || |
| 44 | this->setPointsAtZ(SkSVGAttributeParser::parse<SkSVGNumberType>("pointsAtZ", n, v)) || |
| 45 | this->setSpecularExponent( |
| 46 | SkSVGAttributeParser::parse<SkSVGNumberType>("specularExponent", n, v)) || |
| 47 | this->setLimitingConeAngle( |
| 48 | SkSVGAttributeParser::parse<SkSVGNumberType>("limitingConeAngle", n, v)); |
| 49 | } |