summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-07-10 23:11:10 +0800
committerchai <chaifix@163.com>2020-07-10 23:11:10 +0800
commit21bd7a08615b388bc536d3ffb1e3efce7e5f7673 (patch)
treef99133d42d83ce49966fb3c05ba8d0bcc0fd1d47
parente5e5295ed38cb24feb5ee6f827b2765a4153bfc8 (diff)
*icon
-rw-r--r--Release/OrbitView.icobin0 -> 4286 bytes
-rw-r--r--Release/PanView.icobin0 -> 4286 bytes
-rw-r--r--Release/SoftShadeRoom.exebin129536 -> 130560 bytes
-rw-r--r--src/extend/camera.c22
-rw-r--r--src/extern/wog.c16
-rw-r--r--src/extern/wog.h4
-rw-r--r--src/gizmo/gizmo.c75
-rw-r--r--src/gizmo/gizmo.h1
-rw-r--r--src/main.c5
-rw-r--r--src/shaders/pbr.c1
10 files changed, 117 insertions, 7 deletions
diff --git a/Release/OrbitView.ico b/Release/OrbitView.ico
new file mode 100644
index 0000000..4886b94
--- /dev/null
+++ b/Release/OrbitView.ico
Binary files differ
diff --git a/Release/PanView.ico b/Release/PanView.ico
new file mode 100644
index 0000000..32f5a28
--- /dev/null
+++ b/Release/PanView.ico
Binary files differ
diff --git a/Release/SoftShadeRoom.exe b/Release/SoftShadeRoom.exe
index e1c52b4..22f0d90 100644
--- a/Release/SoftShadeRoom.exe
+++ b/Release/SoftShadeRoom.exe
Binary files differ
diff --git a/src/extend/camera.c b/src/extend/camera.c
index 6b4c0d1..dd77172 100644
--- a/src/extend/camera.c
+++ b/src/extend/camera.c
@@ -2,6 +2,12 @@
#include "../core/device.h"
#include "camera.h"
+typedef enum {
+ CursorType_Arrow = 0,
+ CursorType_Hand = 1,
+ CursorType_Eye = 2
+}CursorType;
+
// A unity editor style camera
typedef struct Camera {
Transform transform;
@@ -23,6 +29,7 @@ typedef struct Camera {
bool move_around;
/*window*/
wog_Window* wnd;
+ CursorType cursor;
} Camera;
Camera* camera_create(wog_Window* wnd, CameraConfig* config) {
@@ -134,11 +141,21 @@ void camera_onevent(Camera* cam, wog_Event* e, float dt) {
cam->look_around = TRUE;
cam->mouse_prev.x = e->pos.x;
cam->mouse_prev.y = e->pos.y;
+ if (cam->cursor != CursorType_Eye)
+ {
+ wog_setcursorImage(cam->wnd, "OrbitView.ico");
+ cam->cursor = CursorType_Eye;
+ }
}
if (!cam->move_around && e->button == WOG_MOUSE_MIDDLE) {
cam->move_around = TRUE;
cam->mouse_prev.x = e->pos.x;
cam->mouse_prev.y = e->pos.y;
+ if (cam->cursor != CursorType_Hand)
+ {
+ wog_setcursorImage(cam->wnd, "PanView.ico");
+ cam->cursor = CursorType_Hand;
+ }
}
}
else if (e->type == WOG_EMOUSEBUTTONUP) {
@@ -146,6 +163,11 @@ void camera_onevent(Camera* cam, wog_Event* e, float dt) {
cam->look_around = FALSE;
if (e->button == WOG_MOUSE_MIDDLE)
cam->move_around = FALSE;
+ if (cam->cursor != CursorType_Arrow)
+ {
+ wog_setcursor(cam->wnd, IDC_ARROW);
+ cam->cursor = CursorType_Arrow;
+ }
}
else if (e->type == WOG_EKEYDOWN) {
if (!cam->speedup && e->key == VK_SHIFT)
diff --git a/src/extern/wog.c b/src/extern/wog.c
index ad8f334..99a110a 100644
--- a/src/extern/wog.c
+++ b/src/extern/wog.c
@@ -283,7 +283,8 @@ static int registerWindowClass()
windowClass.lpfnWndProc = (WNDPROC)(WindowProc); // WindowProc Handles Messages
windowClass.hInstance = GetModuleHandle(0); // Set The Instance
windowClass.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE); // Class Background Brush Color
- windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
+ //windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
+ //windowClass.hCursor = LoadImageA(NULL, "PanView.ico", IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE);
windowClass.lpszClassName = WINDOW_CLASS; // Sets The Applications Classname
if (RegisterClassEx(&windowClass) == 0) // Did Registering The Class Fail?
@@ -676,4 +677,15 @@ void wog_sleep(int ms)
int wog_tick()
{
return GetTickCount();
-} \ No newline at end of file
+}
+
+
+void wog_setcursor(wog_Window* wnd, unsigned int cursor)
+{
+ SetCursor(LoadCursor(NULL, cursor));
+}
+
+void wog_setcursorImage(wog_Window* wnd, const char* path)
+{
+ SetCursor(LoadImageA(NULL, path, IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_CREATEDIBSECTION | LR_LOADFROMFILE));
+}
diff --git a/src/extern/wog.h b/src/extern/wog.h
index 6c5bc08..2052d07 100644
--- a/src/extern/wog.h
+++ b/src/extern/wog.h
@@ -206,4 +206,8 @@ void wog_registerQuitCallback(wog_Callback cal);
wog_Surface* wog_getsurface(wog_Window* wnd);
+void wog_setcursor(wog_Window* wnd, unsigned int cursor);
+void wog_setcursorImage(wog_Window* wnd, const char* path);
+
+
#endif \ No newline at end of file
diff --git a/src/gizmo/gizmo.c b/src/gizmo/gizmo.c
index e3eaaf1..61acdcb 100644
--- a/src/gizmo/gizmo.c
+++ b/src/gizmo/gizmo.c
@@ -5,17 +5,24 @@
struct {
bool show_grid, g_pressing;
+ bool show_axis, a_pressing;
} gizmo_state;
void gizmo_init() {
gizmo_state.show_grid = FALSE;
gizmo_state.g_pressing = FALSE;
+ gizmo_state.show_axis = FALSE;
+ gizmo_state.a_pressing = FALSE;
}
void gizmo_onevent(wog_Event* e, float dt) {
if (e == NULL) return;
if (e->type == WOG_EKEYDOWN) {
- if (e->key == VK_G && !gizmo_state.g_pressing) {
+ if (e->key == VK_A && !gizmo_state.a_pressing) {
+ gizmo_state.show_axis = !gizmo_state.show_axis;
+ gizmo_state.a_pressing = TRUE;
+ }
+ else if (e->key == VK_G && !gizmo_state.g_pressing) {
gizmo_state.show_grid = !gizmo_state.show_grid;
gizmo_state.g_pressing = TRUE;
}
@@ -23,6 +30,8 @@ void gizmo_onevent(wog_Event* e, float dt) {
else if (e->type == WOG_EKEYUP) {
if(e->key == VK_G)
gizmo_state.g_pressing = FALSE;
+ if(e->key == VK_A)
+ gizmo_state.a_pressing = FALSE;
}
}
@@ -30,8 +39,10 @@ void gizmo_onupdate(float dt) {
}
void gizmo_ondraw() {
- if (gizmo_state.show_grid)
+ if(gizmo_state.show_grid)
gizmo_grid();
+ if (gizmo_state.show_axis)
+ gizmo_axis();
}
// varying
@@ -51,6 +62,65 @@ static Program line_shader = {
};
void gizmo_grid() {
+ const int field = 1000;
+ int vCount = 80 + 4;
+ Vert verts[84] = {0};//4*field/100*2
+ int grid[84] = {0};
+ int vertCount;
+ int i = 0;
+ Color color = 0xffaaaaaa;
+ for (int y = -field; y <= field; y += 100)
+ {
+ if (y == 0 && gizmo_state.show_axis) {
+ vCount -= 2;
+ continue;
+ }
+ verts[i].index = i;
+ verts[i].position = vec3_make(-field, 0, y);
+ verts[i].normal = vec3zero;
+ verts[i].tangent = vec4zero;
+ verts[i].texcoord = vec2zero;
+ verts[i].color = color;
+ grid[i] = i++;
+ verts[i].index = i;
+ verts[i].position = vec3_make(field, 0, y);
+ verts[i].normal = vec3zero;
+ verts[i].tangent = vec4zero;
+ verts[i].texcoord = vec2zero;
+ verts[i].color = color;
+ grid[i] = i++;
+ }
+ for (int x = -field; x <= field; x += 100)
+ {
+ if (x == 0 && gizmo_state.show_axis) {
+ vCount -= 2;
+ continue;
+ }
+ verts[i].index = i;
+ verts[i].position = vec3_make(x, 0, -field);
+ verts[i].normal = vec3zero;
+ verts[i].tangent = vec4zero;
+ verts[i].texcoord = vec2zero;
+ verts[i].color = color;
+ grid[i] = i++;
+ verts[i].index = i;
+ verts[i].position = vec3_make(x, 0, field);
+ verts[i].normal = vec3zero;
+ verts[i].tangent = vec4zero;
+ verts[i].texcoord = vec2zero;
+ verts[i].color = color;
+ grid[i] = i++;
+ }
+ ssr_bindvertices(&verts, vCount, &grid, vCount/2);
+ ssr_matrixmode(MATRIX_MODEL);
+ ssr_loadidentity();
+ ssr_useprogram(&line_shader);
+ ssr_draw(PRIMITIVE_LINE);
+ ssr_unuseprogram();
+ ssr_enable(ENABLE_WRITEDEPTH);
+}
+
+void gizmo_axis() {
Vert verts[] = {
{0, {-10000, 0, 0}, vec3zero, vec4zero, vec2zero, 0xffff0000},
{1, {10000, 0, 0}, vec3zero, vec4zero, vec2zero, 0xffff0000},
@@ -66,6 +136,7 @@ void gizmo_grid() {
ssr_useprogram(&line_shader);
ssr_draw(PRIMITIVE_LINE);
ssr_unuseprogram();
+ ssr_enable(ENABLE_WRITEDEPTH);
}
void gizmo_line(Vec3 start, Vec3 end, Color32 color) {
diff --git a/src/gizmo/gizmo.h b/src/gizmo/gizmo.h
index e95880b..066099d 100644
--- a/src/gizmo/gizmo.h
+++ b/src/gizmo/gizmo.h
@@ -19,6 +19,7 @@ void gizmo_onupdate(float dt);
void gizmo_ondraw();
void gizmo_grid();
+void gizmo_axis();
void gizmo_icon2d(float x, float y, float z, GizmoIcon2d icon);
diff --git a/src/main.c b/src/main.c
index 0cb5ef1..138f064 100644
--- a/src/main.c
+++ b/src/main.c
@@ -19,14 +19,15 @@
static char* instruction =
"/***********************************************/\n"
-"/* SoftShadeRoom */\n"
-"/* chai */\n"
+"/* SoftShadeRoom */\n"
+"/* */\n"
"/***********************************************/\n"
"Instructions: \n"
" RightMouseButton+MouseMove look around \n"
" MiddleMouseButton+MouseMove move around \n"
" MouseScroll move forward\\backward\n"
" Shift+Above Operation speed up \n"
+" key-a show\\hide axis \n"
" key-g show\\hide grid \n"
" key-b bake scene and save to png file(require -b option)\n"
"Usage: \n"
diff --git a/src/shaders/pbr.c b/src/shaders/pbr.c
index 9bb051d..b6238f1 100644
--- a/src/shaders/pbr.c
+++ b/src/shaders/pbr.c
@@ -3,7 +3,6 @@
/*uniforms*/
#define _object2world UM4(0)
#define _light UV3(0)
-
#define _albedo_tex UTEX(0)
#define _noraml_tex UTEX(1)
#define _roughness_tex UTEX(2)