tweaks to distance beta app
This commit is contained in:
1 parent
209c3b9262
commit
4c6d449553
2 files changed
+36
-33
No files matched your search
@@ -2,44 +2,46 @@ import('math','_euclidean','_manhattan','_round');
|
|||||||
|
|
||||||
__config()->{
|
__config()->{
|
||||||
'commands'->{
|
'commands'->{
|
||||||
'from <start_pos>'->'set_start',
|
'from <start>'->'set_start',
|
||||||
'from <start_pos> to <end_pos>'->'_calculate',
|
'from <start> to <end>'->'_calculate',
|
||||||
'to <end_pos>'->_(end_pos)->(_calculate(null,end_pos)),
|
'to <end>'->_(end_pos)->(_calculate(null,end_pos)),
|
||||||
'toggle_line'->'_toggle_line'
|
'toggle_line'->'_toggle_line'
|
||||||
},
|
},
|
||||||
'scope'->'player'
|
'arguments' -> {
|
||||||
|
'start' -> {'type' -> 'location'},
|
||||||
|
'end' -> {'type' -> 'location'}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
global_position=null;
|
global_start=null;
|
||||||
global_end_position=null;
|
global_end=null;
|
||||||
|
|
||||||
global_show_line=false;
|
global_show_line=false;
|
||||||
|
|
||||||
global_line = {
|
__mktp(pos) -> str('!/tp %.6f %.6f %.6f', pos);
|
||||||
'start_pos'->global_position,
|
|
||||||
'end_pos'->global_end_position
|
|
||||||
};
|
|
||||||
|
|
||||||
set_start(pos)->(
|
set_start(pos)->(
|
||||||
global_position= pos;
|
global_start = pos;
|
||||||
print(player(),format('gi Initial point set to: ', 'g '+pos,'?/tp '+(str(pos)-','-'['-']')))
|
global_end = null;
|
||||||
|
print(player(),format('gi Initial point set to: ', 'g '+pos, __mktp(pos)))
|
||||||
);
|
);
|
||||||
|
|
||||||
_toggle_line()->(
|
_toggle_line()->(
|
||||||
global_show_line= !global_show_line;
|
global_show_line= !global_show_line;
|
||||||
if(global_show_line,
|
if(global_show_line,
|
||||||
print('Toggled lines on');
|
print('Toggled lines on');
|
||||||
if(global_end_position,_draw_line()),//making sure that there is a start an end pos, and Ive made it so there is no end pos without start pos
|
_draw_line()
|
||||||
|
, // else
|
||||||
print('Toggled lines off')
|
print('Toggled lines off')
|
||||||
);
|
);
|
||||||
null
|
|
||||||
);
|
);
|
||||||
|
|
||||||
_calculate(start_pos, end_pos)->(
|
_calculate(start_pos, end_pos)->(
|
||||||
if(start_pos!=null,
|
if(start_pos!=null,
|
||||||
set_start(start_pos);
|
set_start(start_pos);
|
||||||
calculate(end_pos),
|
calculate(end_pos)
|
||||||
if(global_position,
|
, // else
|
||||||
|
if(global_start,
|
||||||
calculate(end_pos),
|
calculate(end_pos),
|
||||||
print(player(),format('r There was no initial point for '+player()));
|
print(player(),format('r There was no initial point for '+player()));
|
||||||
set_start(end_pos)
|
set_start(end_pos)
|
||||||
@@ -47,42 +49,43 @@ _calculate(start_pos, end_pos)->(
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
__on_player_right_clicks_block(player, item_tuple, hand, block, face, hitvec) ->(
|
__on_player_places_block(player, item_tuple, hand, block) ->(
|
||||||
pos = pos_offset(block,face);//for clicking against the wall.
|
|
||||||
if(block=='brown_carpet' && system_info('world_carpet_rules'):'carpets'=='true',
|
if(block=='brown_carpet' && system_info('world_carpet_rules'):'carpets'=='true',
|
||||||
if(global_position==null||player~'sneaking',//wont complain for first carpet
|
effective_pos = pos(block)+[0.5, 0, 0.5];
|
||||||
set_start(pos),
|
if(global_start==null||player~'sneaking',//wont complain for first carpet
|
||||||
_calculate(null,pos)
|
set_start(effective_pos),
|
||||||
|
_calculate(null, effective_pos)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
calculate(end_pos)->(
|
calculate(end_pos)->(
|
||||||
start_pos = global_position;
|
global_end = end_pos;
|
||||||
[dx,dy,dz] = map(start_pos-end_pos,abs(_));
|
manhattan = _round(_manhattan(global_start, global_end),0.001);//rounding to nearest 0.01 for precision, but not ridiculous decimal places
|
||||||
|
spherical = _round(_euclidean(global_start, global_end), 0.001);
|
||||||
|
//useful for chunk distances etc.
|
||||||
|
cylindrical = _round(_euclidean(global_start, [global_end:0, global_start:1, global_end:2]), 0.001);
|
||||||
|
|
||||||
manhattan = _round(_manhattan([dx, dy, dz],[0,0,0]),100);//rounding to nearest 0.01 for precision, but not ridiculous decimal places
|
|
||||||
spherical = _round(_euclidean([dx, dy, dz],[0,0,0]),100);
|
|
||||||
cylindrical = _round(_euclidean([dx, 0, dz],[0,0,0]),100);//useful for chunk distances etc.
|
|
||||||
|
|
||||||
print(player(),format(
|
print(player(),format(
|
||||||
'w Distance between ',
|
'w Distance between ',
|
||||||
'c '+start_pos,'?/tp '+(str(start_pos)-','-'['-']'), 'w and ',
|
'c '+str('[%.1f, %.1f, %.1f]', global_start), __mktp(global_start),
|
||||||
'c '+end_pos,'?/tp '+(str(end_pos)-','-'['-']'), 'w :\n',
|
'w and ',
|
||||||
|
'c '+str('[%.1f, %.1f, %.1f]', global_end), __mktp(global_end), 'w :\n',
|
||||||
'w - Spherical: ', 'wb '+spherical+'\n',
|
'w - Spherical: ', 'wb '+spherical+'\n',
|
||||||
'w - Cylindrical: ', 'wb '+cylindrical+'\n',
|
'w - Cylindrical: ', 'wb '+cylindrical+'\n',
|
||||||
'w - Manhattan: ', 'wb '+manhattan
|
'w - Manhattan: ', 'wb '+manhattan
|
||||||
));
|
));
|
||||||
|
|
||||||
global_end_position = end_pos;
|
|
||||||
|
|
||||||
schedule(0,'_draw_line');
|
schedule(0,'_draw_line');
|
||||||
);
|
);
|
||||||
|
|
||||||
_draw_line()->(
|
_draw_line()->(
|
||||||
if(global_show_line,//It will always draw from the global positions, so it will turn on if there is a line
|
if(global_show_line,//It will always draw from the global positions, so it will turn on if there is a line
|
||||||
draw_shape('line',20,'from',global_position,'to',global_end_position, 'player',player(),'color',0x000000FF);
|
if ( global_start && global_end,
|
||||||
draw_shape('label',20,'pos',global_end_position,'text',_round(_euclidean(global_position,global_end_position),100),'color',0x000000FF);
|
draw_shape('line',20,'from',global_start,'to',global_end, 'player',player());
|
||||||
|
draw_shape('label',20,'pos',global_end,'text',_round(_euclidean(global_start,global_end),0.001));
|
||||||
|
);
|
||||||
schedule(20,'_draw_line')
|
schedule(20,'_draw_line')
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@@ -2,4 +2,4 @@ _euclidean_sq(vec1, vec2) -> reduce(vec1 - vec2, _a + _*_, 0);
|
|||||||
_euclidean(vec1, vec2) -> sqrt(reduce(vec1 - vec2, _a + _*_, 0));
|
_euclidean(vec1, vec2) -> sqrt(reduce(vec1 - vec2, _a + _*_, 0));
|
||||||
_manhattan(vec1, vec2) -> reduce(vec1-vec2,_a+abs(_),0);
|
_manhattan(vec1, vec2) -> reduce(vec1-vec2,_a+abs(_),0);
|
||||||
_vec_length(vec) -> sqrt(reduce(vec, _a + _*_, 0));
|
_vec_length(vec) -> sqrt(reduce(vec, _a + _*_, 0));
|
||||||
_round(num,precision) -> round(num*precision)/precision;
|
_round(num,precision) -> round(num/precision)*precision;
|
||||||
Reference in new issue
Block a user