-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod_array.c
More file actions
79 lines (64 loc) · 1.55 KB
/
mod_array.c
File metadata and controls
79 lines (64 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Copyright (c) 2015 Milovann Yanatchkov
*
* This file is part of Mud, a free software
* licensed under the GNU General Public License v2
* see /LICENSE for more information
*
*/
#include "blenlib.h"
#include "modifier.h"
#include "llist.h"
#include "mud.h"
#include "stdmath.h"
#include "stdvec.h"
typedef struct Array_Data
{
int count;
t_mn_mat4 *matrix;
}t_array_data;
static t_array_data *array_data_new( int count, t_mn_mat4 *mat)
{
t_array_data *data = ( t_array_data *) calloc( 1, sizeof( t_array_data));
data->count = count;
data->matrix = mat;
return data;
}
float unity[4][4] = {
{ 1.0, 0.0, 0.0, 0.0},
{ 0.0, 1.0, 0.0, 0.0},
{ 0.0, 0.0, 1.0, 0.0},
{ 0.0, 0.0, 0.0, 1.0}
};
void mud_modifier_array( t_mud *mud, s_modifier *mod)
{
t_array_data *data = ( t_array_data *) mod->data;
int i;
int count = data->count;
t_mn_mat4 *mat = data->matrix;
t_mn_mat4 *matrix = mn_mat4_new( unity);
t_mud *copy = mud_copy( mud);
for( i = 0; i < count; i++)
{
t_mud *c = mud_copy( copy);
unit_m4( matrix->m);
int j;
for( j = 0; j < i; j++)
{
mul_m4_m4m4( matrix->m, matrix->m, mat->m);
}
mud_add_modifier_matrix( c, matrix);
mud_apply_modifiers( c);
mud_merge( c, mud);
// memory leak
// "c" mud copy cannot be freed
// his points are used in "final" merge
}
mud_free( copy);
}
void mud_add_modifier_array( struct Mud *mud, int count, t_mn_mat4 *mat)
{
t_array_data *data = array_data_new( count, mat);
s_modifier *mod = modifier_new("array", data, mud_modifier_array);
mud_add_modifier( mud, mod);
}