This repository was archived by the owner on Sep 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgriddeform.c
More file actions
64 lines (56 loc) · 1.49 KB
/
griddeform.c
File metadata and controls
64 lines (56 loc) · 1.49 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
/*
Some basic routines for manipulating the content of a grid
Copyright 2003 Erik Faye-Lund aka kusma/excess
*/
#include <math.h>
/* tell msvc to inline sin() and cos() */
#pragma intrinsic(sin,cos)
#include "grid.h"
void grid_flat(grid* grid, float xscroll, float yscroll){
float xscale = 256.f/(grid->width);
float yscale = 256.f/(grid->height);
int x,y;
grid_node *pointer = grid->data;
for(y=0;y<grid->height;y++)
for(x=0;x<grid->width;x++){
pointer->u = (x*xscale)+xscroll;
pointer->v = (y*yscale)+yscroll;
pointer++;
}
}
void grid_zero(grid* grid){
int x,y;
grid_node *pointer = grid->data;
for(y=0;y<grid->height;y++)
for(x=0;x<grid->width;x++){
pointer->u = 0;
pointer->v = 0;
pointer++;
}
}
void grid_wave(grid* grid, float scale, float anim, float power){
int x,y;
float wh = ((float)grid->width/2);
float hh = ((float)grid->height/2);
grid_node *pointer = grid->data;
for(y=0;y<grid->height;y++)
for(x=0;x<grid->width;x++){
float cx = x-wh;
float cy = y-hh;
float dist = (float)sqrt(cx*cx+cy*cy);
float mul = (1+(float)cos(dist*scale-anim))*power;
pointer->u += cx*mul;
pointer->v += cy*mul;
pointer++;
}
}
void grid_sinus(grid* grid, float xscale, float yscale, float xoffset, float yoffset, float power){
int x,y;
grid_node *pointer = grid->data;
for(y=0;y<grid->height;y++)
for(x=0;x<grid->width;x++){
pointer->u += (float)sin(y*yscale+yoffset)*power;
pointer->v += (float)sin(x*xscale+xoffset)*power;
pointer++;
}
}