-
Notifications
You must be signed in to change notification settings - Fork 8
/
KinemeGLGridGeneratorPatch.m
109 lines (92 loc) · 3.03 KB
/
KinemeGLGridGeneratorPatch.m
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* KinemeGLGridGeneratorPatch.m
* GLTools
*
* Created by Christopher Wright on 8/16/09.
* Copyright (c) 2009 Kosada Incorporated. All rights reserved.
*
*/
#import "KinemeGLGridGeneratorPatch.h"
@implementation KinemeGLGridGeneratorPatch : QCPatch
+ (QCPatchExecutionMode)executionModeWithIdentifier:(id)fp8
{
return 0;
}
+ (BOOL)allowsSubpatchesWithIdentifier:(id)fp8
{
return NO;
}
- (id)initWithIdentifier:(id)fp8
{
if(self=[super initWithIdentifier:fp8])
{
[[self userInfo] setObject:@"Kineme GL Grid Generator" forKey:@"name"];
}
return self;
}
- (BOOL)execute:(QCOpenGLContext *)context time:(double)time arguments:(NSDictionary *)arguments
{
unsigned int x, y;
unsigned int width, height;
KinemeVertex *vertex;
{
width = [inputWidth indexValue];
height = [inputHeight indexValue];
if(width && height)
vertex = (KinemeVertex*)malloc(sizeof(KinemeVertex)*(width+1)*(height+1));
else
{
[outputGrid setValue:nil];
return YES;
}
}
{
//NSLog(@"regenerating");
for(y = 0; y <= height; ++y)
{
for(x = 0; x<= width; ++x)
{
vertex[y*(width+1)+x].x = ((float)x)/width - 0.5f;
vertex[y*(width+1)+x].y = ((float)y)/height - 0.5f;
vertex[y*(width+1)+x].z = 0.0;
vertex[y*(width+1)+x].r = 1;
vertex[y*(width+1)+x].g = 1;
vertex[y*(width+1)+x].b = 1;
vertex[y*(width+1)+x].a = 1;
vertex[y*(width+1)+x].u = ((float)x)/width;
vertex[y*(width+1)+x].v = ((float)y)/height;
}
}
}
/* generate the grid structure */
NSMutableArray *meshArray = [[NSMutableArray alloc] initWithCapacity:(width+1)*(height+1)];
for(y = 0; y <= height; ++y)
{
for(x = 0; x <= width; ++x)
{
QCStructure *vertexStructure = [[QCStructure alloc] init];
{
[vertexStructure setMember:[NSNumber numberWithFloat: vertex[y*(width+1)+x].x] forKey:@"x"];
[vertexStructure setMember:[NSNumber numberWithFloat: vertex[y*(width+1)+x].y] forKey:@"y"];
[vertexStructure setMember:[NSNumber numberWithFloat: vertex[y*(width+1)+x].z] forKey:@"z"];
[vertexStructure setMember:[NSNumber numberWithFloat: vertex[y*(width+1)+x].u] forKey:@"u"];
[vertexStructure setMember:[NSNumber numberWithFloat: vertex[y*(width+1)+x].v] forKey:@"v"];
[vertexStructure setMember:[NSNumber numberWithFloat: vertex[y*(width+1)+x].r] forKey:@"r"];
[vertexStructure setMember:[NSNumber numberWithFloat: vertex[y*(width+1)+x].g] forKey:@"g"];
[vertexStructure setMember:[NSNumber numberWithFloat: vertex[y*(width+1)+x].b] forKey:@"b"];
[vertexStructure setMember:[NSNumber numberWithFloat: vertex[y*(width+1)+x].a] forKey:@"a"];
}
[meshArray addObject:vertexStructure];
[vertexStructure release];
}
}
QCStructure *meshStructure = [[QCStructure alloc] initWithMembers:meshArray keyPrefix:@"vertex_"];
[meshArray release];
[meshStructure setMember:[NSNumber numberWithInt:width] forKey:@"width"];
[meshStructure setMember:[NSNumber numberWithInt:height] forKey:@"height"];
[outputGrid setStructureValue: meshStructure];
[meshStructure release];
free(vertex);
return YES;
}
@end