Blender V2.61 - r43446

node_texture_rotate.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version. 
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2005 Blender Foundation.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): Robin Allen
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00033 #include <math.h>
00034 
00035 #include "node_texture_util.h"
00036 #include "NOD_texture.h"
00037 
00038 static bNodeSocketTemplate inputs[]= { 
00039     { SOCK_RGBA, 1, "Color", 0.0f, 0.0f, 0.0f, 1.0f},
00040     { SOCK_FLOAT, 1, "Turns",   0.0f, 0.0f, 0.0f, 0.0f,  -1.0f, 1.0f, PROP_NONE },
00041     { SOCK_VECTOR, 1, "Axis",   0.0f, 0.0f, 1.0f, 0.0f,  -1.0f, 1.0f, PROP_DIRECTION },
00042     { -1, 0, "" } 
00043 };
00044 
00045 static bNodeSocketTemplate outputs[]= { 
00046     { SOCK_RGBA, 0, "Color"}, 
00047     { -1, 0, "" } 
00048 };
00049 
00050 static void rotate(float new_co[3], float a, float ax[3], float co[3])
00051 {
00052     float para[3];
00053     float perp[3];
00054     float cp[3];
00055     
00056     float cos_a = cos(a * (float)(2*M_PI));
00057     float sin_a = sin(a * (float)(2*M_PI));
00058     
00059     // x' = xcosa + n(n.x)(1-cosa) + (x*n)sina
00060     
00061     mul_v3_v3fl(perp, co, cos_a);
00062     mul_v3_v3fl(para, ax, dot_v3v3(co, ax)*(1 - cos_a));
00063     
00064     cross_v3_v3v3(cp, ax, co);
00065     mul_v3_fl(cp, sin_a);
00066     
00067     new_co[0] = para[0] + perp[0] + cp[0];
00068     new_co[1] = para[1] + perp[1] + cp[1];
00069     new_co[2] = para[2] + perp[2] + cp[2];
00070 }
00071 
00072 static void colorfn(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
00073 {
00074     float new_co[3], new_dxt[3], new_dyt[3], a, ax[3];
00075     
00076     a= tex_input_value(in[1], p, thread);
00077     tex_input_vec(ax, in[2], p, thread);
00078 
00079     rotate(new_co, a, ax, p->co);
00080     if (p->osatex) {
00081         rotate(new_dxt, a, ax, p->dxt);
00082         rotate(new_dyt, a, ax, p->dyt);
00083     }
00084     
00085     {
00086         TexParams np = *p;
00087         np.co = new_co;
00088         np.dxt = new_dxt;
00089         np.dyt = new_dyt;
00090         tex_input_rgba(out, in[0], &np, thread);
00091     }
00092 }
00093 static void exec(void *data, bNode *node, bNodeStack **in, bNodeStack **out) 
00094 {
00095     tex_output(node, in, out[0], &colorfn, data);
00096 }
00097 
00098 void register_node_type_tex_rotate(bNodeTreeType *ttype)
00099 {
00100     static bNodeType ntype;
00101     
00102     node_type_base(ttype, &ntype, TEX_NODE_ROTATE, "Rotate", NODE_CLASS_DISTORT, NODE_OPTIONS);
00103     node_type_socket_templates(&ntype, inputs, outputs);
00104     node_type_size(&ntype, 140, 100, 320);
00105     node_type_exec(&ntype, exec);
00106     
00107     nodeRegisterType(ttype, &ntype);
00108 }