-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathxheightmap.h
83 lines (61 loc) · 1.99 KB
/
xheightmap.h
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
/**
* This file belongs to the 'xlab' game engine.
* Copyright 2009 xfacter
* Copyright 2016 wickles
* This work is licensed under the LGPLv3
* subject to all terms as reproduced in the included LICENSE file.
*/
#pragma once
/* TODO:
change to a better OO design...
*/
#include "xconfig.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct hmap_vertex {
s16 u, v;
ScePspFVector3 p;
} hmap_vertex;
typedef struct hmap_bbox {
ScePspFVector3 p[8];
} hmap_bbox;
typedef struct xHeightmap {
int width;
int height;
float tile_scale;
float z_scale;
hmap_vertex* vertices; // width*height
u16* indices_static; //2*width
} xHeightmap;
typedef struct xHeightmapLOD {
xHeightmap* h;
u16* indices_buffer; //2*width*(height-1) + 8*patches*patches
void* list_buffer; //patches*patches*LIST_SIZE
void** list_ptrs;
hmap_bbox* bboxes; //patches*patches
int patches;
int patch_width;
int ready;
} xHeightmapLOD;
//loads raw 16-bit height data, little endian, stored bottom to top
int xHeightmapLoad(xHeightmap* h, char* filename, int width, float tile_scale, float zscale);
void xHeightmapFree(xHeightmap* h);
//min_level = log2(patches)
int xHeightmapSetupLOD(xHeightmapLOD* l, xHeightmap* h, int min_level);
void xHeightmapFreeLOD(xHeightmapLOD* l);
void xHeightmapGetNormal(xHeightmap* h, ScePspFVector3* out, float x, float y);
float xHeightmapGetHeight(xHeightmap* h, ScePspFVector3* normal, float x, float y);
void xHeightmapDraw(xHeightmap* h);
//p = viewpoint, start = lod start distance, spacing = lod spacing
void xHeightmapBuildLOD(xHeightmapLOD* l, ScePspFVector3* p, float start, float spacing);
/* only x and y of p are used */
void xHeightmapDrawLOD(xHeightmapLOD* l);
int xHeightmapGetPatchID(xHeightmapLOD* l, float x, float y);
void xHeightmapDrawPatchID(xHeightmapLOD* l, int id);
//not for you!
ScePspFVector3* point_from_grid(xHeightmap* h, int x, int y);
void normal_from_grid(xHeightmap* h, ScePspFVector3* out, int x, int y, int which);
#ifdef __cplusplus
}
#endif