-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrawnodes.c
More file actions
205 lines (157 loc) · 7.25 KB
/
drawnodes.c
File metadata and controls
205 lines (157 loc) · 7.25 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include "raylib.h"
#include "drawgui.h"
#include "moduleLoop.h"
#include "drawnodes.h"
#include <math.h>
#include "raymath.h"
#include "gameplay.h"
void DrawNodes()
{
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
BeginMode3D(drawNodesCam);
DrawCube(cubePosition, 1.0f, 1.0f, 1.0f, RED);
DrawGrid(1000, 1.0f);
struct nodeProperties *curNode;
struct nodeProperties *nextNode;
curNode = nodePropListStart;
while (curNode != NULL)
{
Color tint = WHITE;
if ( (*curNode).selected)
{
tint = LIME;
}
if ( (*curNode).nodeType == NODE)
{
//struct nodeTypeData *data = (struct nodeTypeData*)( (*curNode).nodeData );
DrawCube( (*curNode).loc, (*curNode).scale.x, (*curNode).scale.y, (*curNode).scale.z, tint);
BeginBlendMode(BLEND_MULTIPLIED);
if ( (*curNode).colShape == BOX)
{
DrawCube( (*curNode).loc, (*curNode).colScale.x, (*curNode).colScale.y, (*curNode).colScale.z, SKYBLUE);
}
else if ( (*curNode).colShape == SPHERE )
{
DrawSphere( (*curNode).loc, (*curNode).colScale.x, SKYBLUE);
}
EndBlendMode();
}
else if ( (*curNode).nodeType == MODEL)
{
struct modelTypeData *data = (struct modelTypeData*)( (*curNode).nodeData );
//DrawModel( (*data).model, (*curNode).loc, 1.0f, tint);
(*data).model.transform = MatrixRotateXYZ(
(Vector3)
{
(*curNode).rot.x * DEG2RAD,
(*curNode).rot.y * DEG2RAD,
(*curNode).rot.z * DEG2RAD
});
//BeginShaderMode(alphaShader);
DrawModelEx( (*data).model, (*curNode).loc, Vector3Zero(), 0.0f, (*curNode).scale, tint);
//EndShaderMode();
BeginBlendMode(BLEND_MULTIPLIED);
if ( (*curNode).colShape == BOX)
{
//DrawCube( (*curNode).loc, (*curNode).colScale.x, (*curNode).colScale.y, (*curNode).colScale.z, SKYBLUE);
}
else if ( (*curNode).colShape == SPHERE )
{
//DrawSphere( (*curNode).loc, (*curNode).colScale.x, SKYBLUE);
}
EndBlendMode();
}
curNode = (*curNode).next;
}
EndMode3D();
}
void SetCameraModeEditor(Camera camera, int mode)
{
Vector3 v1 = camera.position;
Vector3 v2 = camera.target;
float dx = v2.x - v1.x;
float dy = v2.y - v1.y;
float dz = v2.z - v1.z;
EDITORCAMERA.targetDistance = sqrtf(dx*dx + dy*dy + dz*dz); // Distance to target
// Camera angle calculation
EDITORCAMERA.angle.x = atan2f(dx, dz); // Camera angle in plane XZ (0 aligned with Z, move positive CCW)
EDITORCAMERA.angle.z = atan2f(dy, sqrtf(dx*dx + dz*dz)); // Camera angle in plane XY (0 aligned with X, move positive CW)
EDITORCAMERA.playerEyesPosition = camera.position.y; // Init player eyes position to camera Y position
// Lock cursor for first person and third person cameras
previousMousePosition = GetMousePosition();
if ((mode == CAMERA_FIRST_PERSON) || (mode == CAMERA_THIRD_PERSON)) DisableCursor();
else EnableCursor();
EDITORCAMERA.mode = mode;
}
void UpdateEditorCamera(Camera3D *camera)
{
bool direction[6] = { IsKeyDown(EDITORCAMERA.moveControl[MOVE_FRONT]),
IsKeyDown(EDITORCAMERA.moveControl[MOVE_BACK]),
IsKeyDown(EDITORCAMERA.moveControl[MOVE_RIGHT]),
IsKeyDown(EDITORCAMERA.moveControl[MOVE_LEFT]),
IsKeyDown(EDITORCAMERA.moveControl[MOVE_UP]),
IsKeyDown(EDITORCAMERA.moveControl[MOVE_DOWN]) };
static Vector2 previousMousePosition = { 0.0f, 0.0f };
Vector2 mousePosition = GetMousePosition();
Vector2 mousePositionDelta = { 0.0f, 0.0f };
mousePositionDelta.x = mousePosition.x - previousMousePosition.x;
mousePositionDelta.y = mousePosition.y - previousMousePosition.y;
previousMousePosition = mousePosition;
camera->position.x += (sinf(EDITORCAMERA.angle.x)*direction[MOVE_BACK] -
sinf(EDITORCAMERA.angle.x)*direction[MOVE_FRONT] -
cosf(EDITORCAMERA.angle.x)*direction[MOVE_LEFT] +
cosf(EDITORCAMERA.angle.x)*direction[MOVE_RIGHT])*genProps.camSpeed;
camera->position.y += (sinf(EDITORCAMERA.angle.z)*direction[MOVE_FRONT] -
sinf(EDITORCAMERA.angle.z)*direction[MOVE_BACK] +
1.0f*direction[MOVE_UP] - 1.0f*direction[MOVE_DOWN])*genProps.camSpeed;
camera->position.z += (cosf(EDITORCAMERA.angle.x)*direction[MOVE_BACK] -
cosf(EDITORCAMERA.angle.x)*direction[MOVE_FRONT] +
sinf(EDITORCAMERA.angle.x)*direction[MOVE_LEFT] -
sinf(EDITORCAMERA.angle.x)*direction[MOVE_RIGHT])*genProps.camSpeed;
// Camera orientation calculation
EDITORCAMERA.angle.x += (mousePositionDelta.x*-CAMERA_MOUSE_MOVE_SENSITIVITY);
EDITORCAMERA.angle.z += (mousePositionDelta.y*-CAMERA_MOUSE_MOVE_SENSITIVITY);
// Angle clamp
if (EDITORCAMERA.angle.z > CAMERA_FIRST_PERSON_MIN_CLAMP*DEG2RAD) EDITORCAMERA.angle.z = CAMERA_FIRST_PERSON_MIN_CLAMP*DEG2RAD;
else if (EDITORCAMERA.angle.z < CAMERA_FIRST_PERSON_MAX_CLAMP*DEG2RAD) EDITORCAMERA.angle.z = CAMERA_FIRST_PERSON_MAX_CLAMP*DEG2RAD;
// Recalculate camera target considering translation and rotation
Matrix translation = MatrixTranslate(0, 0, (EDITORCAMERA.targetDistance/CAMERA_FREE_PANNING_DIVIDER));
Matrix rotation = MatrixRotateXYZ((Vector3){ PI*2 - EDITORCAMERA.angle.z, PI*2 - EDITORCAMERA.angle.x, 0 });
Matrix transform = MatrixMultiply(translation, rotation);
camera->target.x = camera->position.x - transform.m12;
camera->target.y = camera->position.y - transform.m13;
camera->target.z = camera->position.z - transform.m14;
}
void UpdateEditorCameraCustom(Camera3D *camera)//fucked and i don't know why. maybe cus i can't math.
{
bool direction[6] = { IsKeyDown(EDITORCAMERA.moveControl[MOVE_FRONT]),
IsKeyDown(EDITORCAMERA.moveControl[MOVE_BACK]),
IsKeyDown(EDITORCAMERA.moveControl[MOVE_RIGHT]),
IsKeyDown(EDITORCAMERA.moveControl[MOVE_LEFT]),
IsKeyDown(EDITORCAMERA.moveControl[MOVE_UP]),
IsKeyDown(EDITORCAMERA.moveControl[MOVE_DOWN]) };
Vector2 mousePosition = GetMousePosition();
Vector2 mousePositionDelta = { 0.0f, 0.0f };
mousePositionDelta.x = mousePosition.x - previousMousePosition.x;
mousePositionDelta.y = mousePosition.y - previousMousePosition.y;
// Camera orientation calculation
EDITORCAMERA.angle.x += (mousePositionDelta.x*CAMERA_MOUSE_MOVE_SENSITIVITY);
EDITORCAMERA.angle.z += (mousePositionDelta.y*CAMERA_MOUSE_MOVE_SENSITIVITY);
// Angle clamp
/*if (EDITORCAMERA.angle.x > 360.0f) EDITORCAMERA.angle.x = 0.0f;
else if (EDITORCAMERA.angle.x < 0.0f) EDITORCAMERA.angle.x = 360.0f;
if (EDITORCAMERA.angle.z > 360.0f) EDITORCAMERA.angle.z = 0.0f;
else if (EDITORCAMERA.angle.z < 0.0f) EDITORCAMERA.angle.z = 360.0f;*/
EDITORCAMERA.angle.x = fmod(EDITORCAMERA.angle.x, 360.0f);
EDITORCAMERA.angle.z = fmod(EDITORCAMERA.angle.z, 360.0f);
TraceLog(LOG_INFO, "x:%f", EDITORCAMERA.angle.x);
//TraceLog(LOG_INFO, "%f", EDITORCAMERA.angle.z);
previousMousePosition = mousePosition;
Vector3 dir;
dir.x = cosf( EDITORCAMERA.angle.x * DEG2RAD );
dir.z = sinf( EDITORCAMERA.angle.z * DEG2RAD );
dir = Vector3Scale(dir, 10.0f);
camera->target.x = dir.x;
camera->target.y = dir.y;
camera->target.z = dir.z;
}