~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/nodes/intern/SHD_nodes/SHD_vectMath.c

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * $Id: SHD_vectMath.c,v 1.6 2007/04/04 13:58:12 jesterking Exp $
 
3
 *
 
4
 * ***** BEGIN GPL LICENSE BLOCK *****
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU General Public License
 
8
 * as published by the Free Software Foundation; either version 2
 
9
 * of the License, or (at your option) any later version. 
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software Foundation,
 
18
 * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
19
 *
 
20
 * The Original Code is Copyright (C) 2005 Blender Foundation.
 
21
 * All rights reserved.
 
22
 *
 
23
 * The Original Code is: all of this file.
 
24
 *
 
25
 * Contributor(s): none yet.
 
26
 *
 
27
 * ***** END GPL LICENSE BLOCK *****
 
28
 */
 
29
 
 
30
 
 
31
#include "../SHD_util.h"
 
32
 
 
33
 
 
34
/* **************** VECTOR MATH ******************** */ 
 
35
static bNodeSocketType sh_node_vect_math_in[]= { 
 
36
        { SOCK_VECTOR, 1, "Vector", 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f}, 
 
37
        { SOCK_VECTOR, 1, "Vector", 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 1.0f}, 
 
38
        { -1, 0, "" } 
 
39
};
 
40
 
 
41
static bNodeSocketType sh_node_vect_math_out[]= {
 
42
        { SOCK_VECTOR, 0, "Vector", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f}, 
 
43
        { SOCK_VALUE, 0, "Value", 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f},
 
44
        { -1, 0, "" } 
 
45
};
 
46
 
 
47
static void node_shader_exec_vect_math(void *data, bNode *node, bNodeStack **in, bNodeStack **out) 
 
48
 
49
        float vec1[3], vec2[3];
 
50
        
 
51
        nodestack_get_vec(vec1, SOCK_VECTOR, in[0]);
 
52
        nodestack_get_vec(vec2, SOCK_VECTOR, in[1]);
 
53
        
 
54
        if(node->custom1 == 0) {        /* Add */
 
55
                out[0]->vec[0]= vec1[0] + vec2[0];
 
56
                out[0]->vec[1]= vec1[1] + vec2[1];
 
57
                out[0]->vec[2]= vec1[2] + vec2[2];
 
58
                
 
59
                out[1]->vec[0]= (fabs(out[0]->vec[0]) + fabs(out[0]->vec[0]) + fabs(out[0]->vec[0])) / 3;
 
60
        }
 
61
        else if(node->custom1 == 1) {   /* Subtract */
 
62
                out[0]->vec[0]= vec1[0] - vec2[0];
 
63
                out[0]->vec[1]= vec1[1] - vec2[1];
 
64
                out[0]->vec[2]= vec1[2] - vec2[2];
 
65
                
 
66
                out[1]->vec[0]= (fabs(out[0]->vec[0]) + fabs(out[0]->vec[0]) + fabs(out[0]->vec[0])) / 3;
 
67
        }
 
68
        else if(node->custom1 == 2) {   /* Average */
 
69
                out[0]->vec[0]= vec1[0] + vec2[0];
 
70
                out[0]->vec[1]= vec1[1] + vec2[1];
 
71
                out[0]->vec[2]= vec1[2] + vec2[2];
 
72
                
 
73
                out[1]->vec[0] = Normalize( out[0]->vec );
 
74
        }
 
75
        else if(node->custom1 == 3) {   /* Dot product */
 
76
                out[1]->vec[0]= (vec1[0] * vec2[0]) + (vec1[1] * vec2[1]) + (vec1[2] * vec2[2]);
 
77
        }
 
78
        else if(node->custom1 == 4) {   /* Cross product */
 
79
                out[0]->vec[0]= (vec1[1] * vec2[2]) - (vec1[2] * vec2[1]);
 
80
                out[0]->vec[1]= (vec1[2] * vec2[0]) - (vec1[0] * vec2[2]);
 
81
                out[0]->vec[2]= (vec1[0] * vec2[1]) - (vec1[1] * vec2[0]);
 
82
                
 
83
                out[1]->vec[0] = Normalize( out[0]->vec );
 
84
        }
 
85
        else if(node->custom1 == 5) {   /* Normalize */
 
86
                if(in[0]->hasinput || !in[1]->hasinput) {       /* This one only takes one input, so we've got to choose. */
 
87
                        out[0]->vec[0]= vec1[0];
 
88
                        out[0]->vec[1]= vec1[1];
 
89
                        out[0]->vec[2]= vec1[2];
 
90
                }
 
91
                else {
 
92
                        out[0]->vec[0]= vec2[0];
 
93
                        out[0]->vec[1]= vec2[1];
 
94
                        out[0]->vec[2]= vec2[2];
 
95
                }
 
96
                
 
97
                out[1]->vec[0] = Normalize( out[0]->vec );
 
98
        }
 
99
        
 
100
}
 
101
 
 
102
bNodeType sh_node_vect_math= { 
 
103
        /* *next,*prev */       NULL, NULL,
 
104
        /* type code   */ SH_NODE_VECT_MATH, 
 
105
        /* name        */ "Vector Math", 
 
106
        /* width+range */ 80, 75, 140, 
 
107
        /* class+opts  */ NODE_CLASS_CONVERTOR, NODE_OPTIONS, 
 
108
        /* input sock  */ sh_node_vect_math_in, 
 
109
        /* output sock */ sh_node_vect_math_out, 
 
110
        /* storage     */ "node_vect_math", 
 
111
        /* execfunc    */ node_shader_exec_vect_math,
 
112
        /* butfunc     */       NULL,
 
113
        /* initfunc    */       NULL,
 
114
        /* freestoragefunc    */        NULL,
 
115
        /* copystoragefunc    */        NULL,
 
116
        /* id          */       NULL
 
117
};
 
118