From 991352b0d2767e6bd1a46f554db4ac9d208c13ad Mon Sep 17 00:00:00 2001 From: aura Date: Mon, 16 Mar 2026 15:40:03 +0100 Subject: finish prop rewrite --- src/editor/editor.cpp | 1 - src/editor/properties.cpp | 171 ++++++++++++++-------------------------------- src/editor/properties.h | 76 +++++++++++++++++++-- src/game/world/map.h | 38 ++++++----- src/util/color.h | 4 +- src/util/string.h | 8 +++ src/util/vector.h | 8 ++- 7 files changed, 160 insertions(+), 146 deletions(-) diff --git a/src/editor/editor.cpp b/src/editor/editor.cpp index bc14146..ba61961 100644 --- a/src/editor/editor.cpp +++ b/src/editor/editor.cpp @@ -56,7 +56,6 @@ static U8 editor_clr_eq( const CLR& a, const CLR& b ) { static U8 editor_vertex_eq( const MAP_VERTEX& a, const MAP_VERTEX& b ) { return a.pos == b.pos - && a.normal == b.normal && a.uv == b.uv && editor_clr_eq( a.clr, b.clr ); } diff --git a/src/editor/properties.cpp b/src/editor/properties.cpp index 3b15dc8..c9eb991 100644 --- a/src/editor/properties.cpp +++ b/src/editor/properties.cpp @@ -9,36 +9,36 @@ const I32 PROPVIEW_PAD = 10; const I32 PROPVIEW_ACTION_BTN_W = 20; const I32 PROPVIEW_ACTION_BTN_GAP = 5; -static I32 propview_col_left() { +I32 propview_col_left() { return PROPVIEW_PAD; } -static I32 propview_col_right( GUI_EDITOR_PROPVIEW* view ) { +I32 propview_col_right( GUI_EDITOR_PROPVIEW* view ) { if( !view ) return PROPVIEW_PAD; return max( PROPVIEW_PAD, view->w - PROPVIEW_PAD ); } -static I32 propview_input_width( GUI_EDITOR_PROPVIEW* view ) { +I32 propview_input_width( GUI_EDITOR_PROPVIEW* view ) { return max( 120, propview_col_right( view ) - propview_col_left() ); } -static I32 propview_sub_input_x( I32 x ) { +I32 propview_sub_input_x( I32 x ) { return x + 10; } -static I32 propview_sub_input_width( GUI_EDITOR_PROPVIEW* view, I32 x ) { - I32 right = propview_col_right( view ); - return max( 100, right - propview_sub_input_x( x ) ); -} +// I32 propview_sub_input_width( GUI_EDITOR_PROPVIEW* view, I32 x ) { +// I32 right = propview_col_right( view ); +// return max( 100, right - propview_sub_input_x( x ) ); +// } -static I32 propview_action_x( GUI_EDITOR_PROPVIEW* view ) { +I32 propview_action_x( GUI_EDITOR_PROPVIEW* view ) { I32 right = propview_col_right( view ); return max( propview_col_left(), right - PROPVIEW_ACTION_BTN_W ); } -static I32 propview_action2_x( GUI_EDITOR_PROPVIEW* view ) { +I32 propview_action2_x( GUI_EDITOR_PROPVIEW* view ) { return max( propview_col_left(), propview_action_x( view ) - PROPVIEW_ACTION_BTN_W - PROPVIEW_ACTION_BTN_GAP @@ -71,18 +71,21 @@ void gui_editor_propview_select( GUI_EDITOR_PROPVIEW* view, void* what, U8 selty void gui_editor_propview_create_eobj_props( GUI_EDITOR_PROPVIEW* view, EOBJECT* e, I32* x, I32* y, I32 w ); void gui_editor_propview_create_eobj_prop( GUI_EDITOR_PROPVIEW* view, EDITOR_PROP* prop, I32* x, I32* y, I32 w, I32 space ) { - F32 step = editor->propgrid ? editor->grid : 0.25f; F32 action_x = propview_action_x( view ); I32 action2_x = propview_action2_x( view ); const char* n = prop->displayname; F32 min = prop->min; F32 max = prop->max; + F32 step; + + if( prop->step ) step = prop->step; + else step = editor->propgrid ? editor->grid : 0.25f; switch( prop->type ) { case EPROP_F32: gui_floatinput( *x, *y, w, n, (F32*)eprop_ptr( prop ), min, max, step ); *y += (space+18); break; case EPROP_VEC2: gui_vectorinput( *x, *y, w, n, (F32*)eprop_ptr( prop ), 2, min, max, step, "xy", "%.03f" ); *y += (space+18); break; - case EPROP_VEC3: gui_vectorinput( *x, *y, w, n, (F32*)eprop_ptr( prop ), 3, min, max, step, "xyz", "%.03f" ); *y += (space+18); break; - case EPROP_VEC4: gui_vectorinput( *x, *y, w, n, (F32*)eprop_ptr( prop ), 3, min, max, step, "xyzw", "%0.03f" ); *y += (space+18); break; + case EPROP_VEC3: gui_vectorinput( *x, *y, w, n, (F32*)eprop_ptr( prop ), 3, min, max, step, "xyz", "%.02f" ); *y += (space+18); break; + case EPROP_VEC4: gui_vectorinput( *x, *y, w, n, (F32*)eprop_ptr( prop ), 3, min, max, step, "xyzw", "%0.02f" ); *y += (space+18); break; case EPROP_CLR: gui_colorinput( *x, *y, w, n, (CLR*)eprop_ptr( prop ) ); *y += (space+18); break; case EPROP_MAPPROP: { MAP_PROPREF* ref = (MAP_PROPREF*)eprop_ptr( prop ); @@ -117,12 +120,43 @@ void gui_editor_propview_create_eobj_prop( GUI_EDITOR_PROPVIEW* view, EDITOR_PRO picker->cb = pfn( void* ) { gui_editor_propview_update( editor->gui.props ); }; } ); btn->extra = tex; *y += space; } break; + case EPROP_VERTEX_LIST: { + LIST* list = ( LIST* )eprop_ptr( prop ); + gui_label( *x, *y, "%s : %d", n, list->size ); *y += space; + for( U32 i = 0; i < list->size; ++i ) { + MAP_VERTEX* v = &list->data[i]; + gui_label( (*x) + 10, *y, "[%d] -> [%s]", i, to_str( v->pos ).data ); + GUI_BUTTON* btn = gui_button( action_x, *y, 20, 20, "\x1A", pfn( void* ptr ) { + GUI_BUTTON* btn = (GUI_BUTTON*)ptr; + gui_editor_propview_select( editor->gui.props, btn->extra, EDITOR_SELECT_PVERTEX ); + } ); btn->extra = v; *y += space; + } + } break; default: break; } } void gui_editor_propview_create_eobj_prop_ro( GUI_EDITOR_PROPVIEW* view, EDITOR_PROP* prop, I32* x, I32* y, I32 w, I32 space ) { - + STR str = prop->displayname; + str += " : ["; + void* ptr = eprop_ptr( prop ); + + switch( prop->type ) { + case EPROP_F32: str += to_str( *(F32*)ptr ); break; + case EPROP_VEC2: str += to_str( *(VEC2*)ptr ); break; + case EPROP_VEC3: str += to_str( *(VEC3*)ptr ); break; + case EPROP_VEC4: str += to_str( *(VEC4*)ptr ); break; + case EPROP_CLR: str += to_str( *(CLR*)ptr ); break; + case EPROP_U32: str += to_str( *(U32*)ptr ); break; + case EPROP_U64: str += to_str( *(U64*)ptr ); break; + case EPROP_I32: str += to_str( *(I32*)ptr ); break; + case EPROP_I64: str += to_str( *(I64*)ptr ); break; + case EPROP_STRING: str += to_str( *(CLR*)ptr ); break; + } + + str += "]"; + gui_label( *x, *y, str.data ); + *y += space; } void gui_editor_propview_create_eobj_props( GUI_EDITOR_PROPVIEW* view, EOBJECT* e, I32* x, I32* y, I32 w ) { @@ -137,66 +171,6 @@ void gui_editor_propview_create_eobj_props( GUI_EDITOR_PROPVIEW* view, EOBJECT* } } - -// returns the subentry height -I32 gui_editor_propview_surfprops_subentry( - GUI_EDITOR_PROPVIEW* view, - I32 x, - I32 y, - I32* propid, - SURF_PROPS* props -) { - I32 oldy = y; - I32 space = 20; - I32 action_x = propview_action_x( view ); - I32 action2_x = propview_action2_x( view ); - gui_label( x, y, "prop id: %d", *propid ); - GUI_BUTTON* newprop = gui_button( action2_x, y, 20, 20, "+", pfn( void* ptr ) { - GUI_BUTTON* btn = (GUI_BUTTON*)ptr; - SURF_PROPS props; - props.tex = 0; - props.clr = { 1.f, 1.f, 1.f, 1.f }; - - editor->map->props.push( props ); - *(U32*)(btn->extra) = editor->map->props.size - 1; - // Keep the newest prop visible in the assets panel (pixel scroll). - editor->gui.assets_scroll = ( editor->map->props.size + 1 ) * 28; - gui_editor_propview_update( editor->gui.props ); - } ); - newprop->extra = propid; - GUI_BUTTON* goprop = gui_button( action_x, y, 20, 20, "\x1A", pfn( void* ptr ) { - GUI_BUTTON* btn = (GUI_BUTTON*)ptr; - gui_editor_propview_select( editor->gui.props, btn->extra, EDITOR_SELECT_SURFPROPS ); - } ); - goprop->extra = props; - - y += space; - - if( props->tex ) - gui_label( x + 10, y, "texture: %s", props->tex->name ); - else - gui_label( x + 10, y, "texture: none" ); - - GUI_BUTTON* btn = gui_button( action_x, y, 20, 20, "\x1A", pfn( void* ptr ) { - GUI_BUTTON* btn = (GUI_BUTTON*)ptr; - GL_TEX2D** ptex = (GL_TEX2D**)btn->extra; - GUI_EDITOR_TEXTUREPICKER* picker = gui_editor_texturepicker( 200, 100, 400, 400, ptex ); - picker->cb = pfn( void* ) { gui_editor_propview_update( editor->gui.props ); }; - } ); - - btn->extra = &props->tex; - y += space; - gui_colorinput( - propview_sub_input_x( x ), - y, - propview_sub_input_width( view, x ), - "color", - &props->clr - ); y += (space+18); - - return y - oldy; -} - void gui_editor_propview_create_wallprops( GUI_EDITOR_PROPVIEW* view ) { MAP_WALL* s = (MAP_WALL*)view->curselect; WORLD_MAP* m = editor->map; @@ -215,37 +189,15 @@ void gui_editor_propview_create_wallprops( GUI_EDITOR_PROPVIEW* view ) { void gui_editor_propview_create_polyprops( GUI_EDITOR_PROPVIEW* view ) { MAP_POLYGON* p = (MAP_POLYGON*)view->curselect; WORLD_MAP* m = editor->map; - SURF_PROPS* props = polygon_get_props( m, p ); - I32 x = 10, y = 10; I32 space = 20; I32 poly_idx = m->polygons.idx_where( fn( MAP_POLYGON* mp ) { return p == mp; } ); - I32 action_x = propview_action_x( view ); gui_label( x, y, "idx: %d", poly_idx ); y += space; - y += gui_editor_propview_surfprops_subentry( view, x, y, &p->propid.id, props ); - - gui_label( x, y, "vertices: %d", p->vertices.size ); y += space; - I32 idx = 0; - p->vertices.each( fn( MAP_VERTEX* v ) { - gui_label( x + 10, y, "[%d] -> { %.02f, %.02f, %.02f }", idx, v->pos.x, v->pos.y, v->pos.z ); - GUI_BUTTON* btn = gui_button( action_x, y - 2, 20, 20, "\x1A", pfn( void* ptr ) { - GUI_EDITOR_PROPVIEW* view = editor->gui.props; - GUI_BUTTON* btn = (GUI_BUTTON*)ptr; - MAP_POLYGON* p = (MAP_POLYGON*)view->curselect; - I64 idx = (I64)btn->extra; - if( p ) // p100 - gui_editor_propview_select( view, &p->vertices[idx], EDITOR_SELECT_PVERTEX ); - } ); - - y += space; - btn->extra = (void*)( (I64)idx++ ); - } ); - gui_label( x, y, "mins: { %1.02f, %1.02f, %1.02f }", p->mins.x, p->mins.y, p->mins.z ); y += space; - gui_label( x, y, "maxs: { %1.02f, %1.02f, %1.02f }", p->maxs.x, p->maxs.y, p->maxs.z ); y += space; + return gui_editor_propview_create_eobj_props( view, p, &x, &y, propview_input_width( view ) ); } void gui_editor_propview_create_mapprops( GUI_EDITOR_PROPVIEW* view ) { @@ -296,12 +248,10 @@ void gui_editor_propview_create_pvertexprops( GUI_EDITOR_PROPVIEW* view ) { return vert_idx != -1; } ); - F32 step = editor->propgrid? editor->grid : 0.25f; I32 action_x = propview_action_x( view ); gui_label( x, y, "idx: %d", vert_idx ); y += space; gui_label( x, y, "polygon idx: %d", poly_idx ); - gui_button( action_x, y - 2, 20, 20, "\x1A", pfn( void* ) { GUI_EDITOR_PROPVIEW* view = editor->gui.props; MAP_VERTEX* v = (MAP_VERTEX*)view->curselect; @@ -313,13 +263,9 @@ void gui_editor_propview_create_pvertexprops( GUI_EDITOR_PROPVIEW* view ) { if( polygon ) gui_editor_propview_select( view, polygon, EDITOR_SELECT_POLY ); - } ); - y += space; + } ); y += space; - GUI_VECTORINPUT* posinput = gui_vectorinput( x, y, propview_input_width( view ), "position", (F32*)&v->pos, 3, -INFINITY, INFINITY, step ); y += (space+18); - posinput->cb = pfn( void* ptr ) { map_check_bounds( editor->map ); }; - gui_vectorinput( x, y, propview_input_width( view ), "texture coordinates", (F32*)&v->uv, 2, 0.f, 1.f, 0.005f, "xy", "%.03f" ); y += (space+18); - gui_colorinput( x, y, propview_input_width( view ), "color", &v->clr ); y += (space+18); + return gui_editor_propview_create_eobj_props( view, v, &x, &y, propview_input_width( view ) ); } @@ -348,22 +294,9 @@ void gui_editor_propview_create_surfprops( GUI_EDITOR_PROPVIEW* view ) { I32 i = m->props.idx_where( fn( SURF_PROPS* mp ) { return mp == p; } ); if( i == -1 ) return; - I32 action_x = propview_action_x( view ); gui_label( x, y, "prop id: %d", i ); y += space; - if( p->tex ) - gui_label( x, y, "texture: %s", assets_abspath( p->tex->name ) ); - else - gui_label( x, y, "texture: none" ); - GUI_BUTTON* btn = gui_button( action_x, y, 20, 20, "\x1A", pfn( void* ptr ) { - GUI_BUTTON* btn = (GUI_BUTTON*)ptr; - GL_TEX2D** ptex = (GL_TEX2D**)btn->extra; - GUI_EDITOR_TEXTUREPICKER* picker = gui_editor_texturepicker( 200, 100, 400, 400, ptex ); - picker->cb = pfn( void* ) { gui_editor_propview_update( editor->gui.props ); }; - } ); - btn->extra = &p->tex; - y += space; - gui_colorinput( x, y, propview_input_width( view ), "color", &p->clr ); y += (space+18); + return gui_editor_propview_create_eobj_props( view, p, &x, &y, propview_input_width( view ) ); } void gui_editor_propview_create_entprops( GUI_EDITOR_PROPVIEW* view ) { diff --git a/src/editor/properties.h b/src/editor/properties.h index 1eb51f8..d663a6b 100644 --- a/src/editor/properties.h +++ b/src/editor/properties.h @@ -8,15 +8,15 @@ #define EPROP( _type, name, value, display ) \ _type name = value; \ - EDITOR_PROP name##_prop{ &name, eprop_type<_type>(), display, this, 0 }; + EDITOR_PROP name##_prop{ &name, eprop_type<_type>(), display, this, 0 } #define EPROP_RO( _type, name, value, display ) \ _type name = value; \ - EDITOR_PROP name##_prop{ .pdata = &name, .type = eprop_type<_type>(), .displayname = display, .parent = this, .readonly = 1 }; + EDITOR_PROP name##_prop{ &name, eprop_type<_type>(), display, this, 1 } #define EPROP_RANGED( _type, name, value, display, _min, _max ) \ - _type name{ value }; \ - EDITOR_PROP{ \ + _type name = value; \ + EDITOR_PROP name##_prop{ \ &name, \ eprop_type<_type>(), \ display, \ @@ -26,6 +26,30 @@ 0 \ } +#define EPROP_STEP( _type, name, value, display, step ) \ + _type name = value; \ + EDITOR_PROP name##_prop{ \ + &name, \ + eprop_type<_type>(), \ + display, \ + step, \ + this, \ + 0 \ + } + +#define EPROP_RANGED_STEP( _type, name, value, display, min, max, step ) \ + _type name = value; \ + EDITOR_PROP name##_prop{ \ + &name, \ + eprop_type<_type>(), \ + display, \ + step, \ + this, \ + min, \ + max, \ + 0 \ + } + enum EditorPropType_t { EPROP_INVALID = 0, EPROP_U8 = 1, @@ -48,6 +72,8 @@ enum EditorPropType_t { EPROP_LIST, EPROP_TEXTURE, EPROP_TEXTURE_LIST, + EPROP_VERTEX, + EPROP_VERTEX_LIST }; struct EPROP_ENTRY { @@ -69,6 +95,7 @@ struct EDITOR_PROP { displayname = _displayname; min = -INFINITY; max = INFINITY; + step = 0; readonly = _readonly; U64 _this = (U64)this; @@ -82,12 +109,50 @@ struct EDITOR_PROP { dataoff = offset; } + EDITOR_PROP( void* _pdata, U8 _type, STR _displayname, F32 _step, struct EOBJECT* _parent, U8 _readonly = 0 ) { + type = _type; + displayname = _displayname; + min = -INFINITY; + max = INFINITY; + step = _step; + readonly = _readonly; + + U64 _this = (U64)this; + U64 pdata = (U64)_pdata; + U64 parent = (U64)_parent; + U64 offset = _this - parent; + + _parent->eprops.push( { offset } ); + + offset = _this - pdata; + dataoff = offset; + } EDITOR_PROP( void* _pdata, U8 _type, STR _displayname, struct EOBJECT* _parent, F32 _min, F32 _max, U8 _readonly = 0 ) { type = _type; displayname = _displayname; min = _min; max = _max; + step = 0; + readonly = _readonly; + + U64 _this = (U64)this; + U64 pdata = (U64)_pdata; + U64 parent = (U64)_parent; + U64 offset = _this - parent; + + _parent->eprops.push( { offset } ); + + offset = _this - pdata; + dataoff = offset; + } + + EDITOR_PROP( void* _pdata, U8 _type, STR _displayname, F32 _step, struct EOBJECT* _parent, F32 _min, F32 _max, U8 _readonly = 0 ) { + type = _type; + displayname = _displayname; + min = _min; + max = _max; + step = _step; readonly = _readonly; U64 _this = (U64)this; @@ -106,6 +171,7 @@ struct EDITOR_PROP { STR displayname; F64 min{ -INFINITY }; F64 max{ INFINITY }; + F32 step; U8 readonly; template struct __eprop_type { @@ -131,6 +197,8 @@ struct EDITOR_PROP { template <__eobject_base T> struct __eprop_type { static const U8 type = EPROP_OBJ; }; template struct __eprop_type> { static const U8 type = EPROP_LIST; }; template <> struct __eprop_type> { static const U8 type = EPROP_TEXTURE_LIST; }; + template <> struct __eprop_type { static const U8 type = EPROP_VERTEX; }; + template <> struct __eprop_type> { static const U8 type = EPROP_VERTEX_LIST; }; }; inline EDITOR_PROP* eprop_from_ref( EOBJECT* obj, EPROP_ENTRY e ) { diff --git a/src/game/world/map.h b/src/game/world/map.h index 8e6444e..21bfa1f 100644 --- a/src/game/world/map.h +++ b/src/game/world/map.h @@ -17,10 +17,11 @@ struct SURF_PROPS : public EOBJECT { }; struct MAP_VERTEX : public EOBJECT { - EPROP( VEC3, pos, {}, "position" ); - EPROP( VEC3, normal, {}, "normal" ); - EPROP( VEC2, uv, {}, "uv" ); - EPROP( CLR, clr, {}, "color" ); + EPROP( VEC3, pos, {}, "position" ); + EPROP_RANGED_STEP( VEC2, uv, {}, "uv", 0.f, 1.f, 0.025f ); + EPROP( CLR, clr, {}, "color" ); + + EPROP_RO( VEC3, normal, {}, "normal" ); }; enum MapPolygonType_t { @@ -42,8 +43,8 @@ struct MAP_POLYGON : public EOBJECT { EPROP( MAP_PROPREF, propid, {}, "prop id" ); EPROP( LIST, vertices, {}, "vertices" ); - VEC3 mins; - VEC3 maxs; + EPROP_RO( VEC3, mins, {}, "mins" ); + EPROP_RO( VEC3, maxs, {}, "maxs" ); U8 type; }; @@ -53,8 +54,8 @@ struct MAP_WALL : public EOBJECT { EPROP( VEC3, start, {}, "start pos" ); EPROP( VEC3, end, {}, "end pos" ); - EPROP( VEC2, uvstart, {}, "uv start offset" ); - EPROP( VEC2, uvend, {}, "uv end offset" ); + EPROP_RANGED_STEP( VEC2, uvstart, {}, "uv start offset", 0.f, 1.f, 0.025f ); + EPROP_RANGED_STEP( VEC2, uvend, {}, "uv end offset", 0.f, 1.f, 0.025f ); }; struct MAP_TEXTURE_ENTRY { @@ -64,10 +65,10 @@ struct MAP_TEXTURE_ENTRY { }; struct MAP_SPRITE : public EOBJECT { - EPROP( GL_TEX2D*, tex, {}, "texture" ); - EPROP( VEC3, pos, {}, "position" ); - EPROP( VEC2, size, {}, "size" ); - EPROP( CLR, clr, {}, "color" ); + EPROP( GL_TEX2D*, tex, {}, "texture" ); + EPROP( VEC3, pos, {}, "position" ); + EPROP_RANGED( VEC2, size, {}, "size", 0.25f, INFINITY ); + EPROP( CLR, clr, {}, "color" ); }; struct MAP_ENTITY : public EOBJECT { @@ -84,21 +85,22 @@ struct MAP_SKYBOX : public EOBJECT { }; struct WORLD_MAP : public EOBJECT { + EPROP_RO( STR, name, {}, "name" ); + EPROP( VEC3, startpos, {}, "spawn position" ); + EPROP( F32, startang, {}, "spawn angle" ); + EPROP( LIST , walls, {}, "walls" ); EPROP( LIST, polygons, {}, "polygons" ); EPROP( LIST , sprites, {}, "sprites" ); EPROP( LIST , entities, {}, "entities" ); EPROP( LIST , props, {}, "surface properties" ); + EPROP( MAP_SKYBOX, skybox, {}, "skybox" ); F32 w; F32 h; - VEC3 mins; - VEC3 maxs; - EPROP( STR, name, {}, "name" ); - - EPROP( VEC3, startpos, {}, "spawn position" ); - EPROP( F32, startang, {}, "spawn angle" ); + EPROP_RO( VEC3, mins, {}, "mins" ); + EPROP_RO( VEC3, maxs, {}, "maxs" ); struct BSP* bsp{}; diff --git a/src/util/color.h b/src/util/color.h index 526cddc..8b1a259 100644 --- a/src/util/color.h +++ b/src/util/color.h @@ -1,5 +1,5 @@ #pragma once -#include "typedef.h" +#include "string.h" #include struct CLR { @@ -166,3 +166,5 @@ struct CLR { return *this; } }; + +inline STR to_str( CLR c ) { return STR( "%.02f %.02f %.02f %.02f", c.r, c.g, c.b, c.a ); } diff --git a/src/util/string.h b/src/util/string.h index 7dfab69..672fb5d 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -274,3 +274,11 @@ struct __str : public LIST { using STR = __str; using WSTR = __str; + +inline STR to_str( F32 f ) { return STR( "%.02f", f ); } +inline STR to_str( F64 f ) { return STR( "%.02g", f ); } +inline STR to_str( I32 i ) { return STR( "%d", i ); } +inline STR to_str( I64 i ) { return STR( "%lld", i ); } +inline STR to_str( U32 u ) { return STR( "%u", u ); } +inline STR to_str( U64 u ) { return STR( "%llu", u ); } +inline STR to_str( void* p ) { return STR( "%llx", (U64)p ); } diff --git a/src/util/vector.h b/src/util/vector.h index 854b454..eb386ab 100644 --- a/src/util/vector.h +++ b/src/util/vector.h @@ -1,7 +1,7 @@ #pragma once #include -#include "typedef.h" +#include "string.h" static const F32 PI = 3.14159265359f; static const F32 PIRAD = 0.01745329251f; @@ -13,7 +13,6 @@ struct VEC2 { VEC2() { x = y = 0.0f; } VEC2( F32 X, F32 Y ) { x = X; y = Y; } - VEC2( const F32* v ) { x = v[0]; y = v[1]; } VEC2( const VEC2& v ) { x = v.x; y = v.y; } bool operator==( const VEC2& v ) const { return ( x == v.x && y == v.y ); } @@ -49,7 +48,6 @@ struct VEC3 { VEC3() { x = y = z = 0.0f; } VEC3( F32 X, F32 Y, F32 Z ) { x = X; y = Y; z = Z; } - VEC3( const F32* v ) { x = v[0]; y = v[1]; z = v[2]; } VEC3( const VEC3& v ) { x = v.x; y = v.y; z = v.z; } VEC3( const VEC2& v ) { x = v.x; y = v.y; z = 0.f; } @@ -250,3 +248,7 @@ inline void angle_vectors( const VEC3& angles, VEC3* forward, VEC3* right, VEC3* up->z = cr * cp; } } + +inline STR to_str( VEC2 v ) { return STR( "%.02f, %.02f", v.x, v.y ); } +inline STR to_str( VEC3 v ) { return STR( "%.02f, %.02f, %.02f", v.x, v.y, v.z ); } +inline STR to_str( VEC4 v ) { return STR( "%.02f, %.02f, %.02f, %.02f", v.x, v.y, v.z, v.w ); } -- cgit v1.2.3