This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/compositor/operations/COM_EllipseMaskOperation.cpp
Bastien Montagne 46eef60d93 Cleanup: Internal degrees removal.
This patch changes most of the reamining degrees usage in internal code into radians.
I let a few which I know off asside, for reasons explained below - and I'm not sure to have found out all of them.

WARNING: this introduces forward incompatibility, which means files saved from this version won't open 100% correctly
         in previous versions (a few angle properties would use radians values as degrees...).

Details:
- Data:
-- Lamp.spotsize: Game engine exposed this setting in degrees, to not break the API here I kept it as such
                  (using getter/setter functions), still using radians internally.
-- Mesh.smoothresh: Didn't touch to this one, as we will hopefully replace it completely by loop normals currently in dev.

- Modifiers:
-- EdgeSplitModifierData.split_angle, BevelModifierData.bevel_angle: Done.

- Postprocessing:
-- WipeVars.angle (sequencer's effect), NodeBokehImage.angle, NodeBoxMask.rotation, NodeEllipseMask.rotation: Done.

- BGE:
-- bConstraintActuator: Orientation type done (the minloc[0] & maxloc[0] cases). Did not touch to 'limit location' type,
                        it can also limit rotation, but it exposes through RNA the same limit_min/limit_max, which hence
                        can be either distance or angle values, depending on the mode. Will leave this to BGE team.
-- bSoundActuator.cone_outer_angle_3d, bSoundActuator.cone_inner_angle_3d: Done (note I kept degrees in BGE itself,
                                                                           as it seems this is the expected value here...).
-- bRadarSensor.angle: Done.

Reviewers: brecht, campbellbarton, sergey, gaiaclary, dfelinto, moguri, jbakker, lukastoenne, howardt

Reviewed By: brecht, campbellbarton, sergey, gaiaclary, moguri, jbakker, lukastoenne, howardt
Thanks to all!

Differential Revision: http://developer.blender.org/D59
2013-12-03 20:35:45 +01:00

124 lines
3.2 KiB
C++

/*
* Copyright 2011, Blender Foundation.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor:
* Jeroen Bakker
* Monique Dewanchand
*/
#include "COM_EllipseMaskOperation.h"
#include "BLI_math.h"
#include "DNA_node_types.h"
EllipseMaskOperation::EllipseMaskOperation() : NodeOperation()
{
this->addInputSocket(COM_DT_VALUE);
this->addInputSocket(COM_DT_VALUE);
this->addOutputSocket(COM_DT_VALUE);
this->m_inputMask = NULL;
this->m_inputValue = NULL;
this->m_cosine = 0.0f;
this->m_sine = 0.0f;
}
void EllipseMaskOperation::initExecution()
{
this->m_inputMask = this->getInputSocketReader(0);
this->m_inputValue = this->getInputSocketReader(1);
const double rad = (double)this->m_data->rotation;
this->m_cosine = cos(rad);
this->m_sine = sin(rad);
this->m_aspectRatio = ((float)this->getWidth()) / this->getHeight();
}
void EllipseMaskOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
{
float inputMask[4];
float inputValue[4];
float rx = x / this->getWidth();
float ry = y / this->getHeight();
const float dy = (ry - this->m_data->y) / this->m_aspectRatio;
const float dx = rx - this->m_data->x;
rx = this->m_data->x + (this->m_cosine * dx + this->m_sine * dy);
ry = this->m_data->y + (-this->m_sine * dx + this->m_cosine * dy);
this->m_inputMask->readSampled(inputMask, x, y, sampler);
this->m_inputValue->readSampled(inputValue, x, y, sampler);
const float halfHeight = (this->m_data->height) / 2.0f;
const float halfWidth = this->m_data->width / 2.0f;
float sx = rx - this->m_data->x;
sx *= sx;
const float tx = halfWidth * halfWidth;
float sy = ry - this->m_data->y;
sy *= sy;
const float ty = halfHeight * halfHeight;
bool inside = ((sx / tx) + (sy / ty)) < 1.0f;
switch (this->m_maskType) {
case CMP_NODE_MASKTYPE_ADD:
if (inside) {
output[0] = max(inputMask[0], inputValue[0]);
}
else {
output[0] = inputMask[0];
}
break;
case CMP_NODE_MASKTYPE_SUBTRACT:
if (inside) {
output[0] = inputMask[0] - inputValue[0];
CLAMP(output[0], 0, 1);
}
else {
output[0] = inputMask[0];
}
break;
case CMP_NODE_MASKTYPE_MULTIPLY:
if (inside) {
output[0] = inputMask[0] * inputValue[0];
}
else {
output[0] = 0;
}
break;
case CMP_NODE_MASKTYPE_NOT:
if (inside) {
if (inputMask[0] > 0.0f) {
output[0] = 0;
}
else {
output[0] = inputValue[0];
}
}
else {
output[0] = inputMask[0];
}
break;
}
}
void EllipseMaskOperation::deinitExecution()
{
this->m_inputMask = NULL;
this->m_inputValue = NULL;
}