Get rectangle corners as triangles
This commit is contained in:
parent
c0d84bae43
commit
b95b7659c3
5 changed files with 96 additions and 60 deletions
|
|
@ -31,6 +31,7 @@ import rl "libraries/raylib"
|
|||
import ui "libraries/snths_ui"
|
||||
import "core:mem"
|
||||
import "core:fmt"
|
||||
import "core:math"
|
||||
import "core:math/linalg"
|
||||
import "core:strings"
|
||||
|
||||
|
|
@ -372,6 +373,11 @@ program_show_dialog :: proc(program: ^Program, dialog_type: ProgramDialogType, m
|
|||
program.state = .Dialog
|
||||
program.dialog_type = dialog_type
|
||||
program.dialog_message = message
|
||||
mem.set(&program.dialog_data, 0, size_of(program.dialog_data))
|
||||
for i in 0..<len(program.dialog_data.input_float_values) {
|
||||
program.dialog_data.input_float_values[i] = 0.0
|
||||
program.dialog_data.input_float_value_strings[i][0] = '0'
|
||||
}
|
||||
}
|
||||
|
||||
program_init :: proc(allocator := context.allocator) {
|
||||
|
|
@ -598,36 +604,21 @@ program_update :: proc() {
|
|||
|
||||
program_add_identity_matrix :: proc() {
|
||||
value_strings, values := matrix_pool_get_mat3()
|
||||
value_strings[0][0] = '1'
|
||||
values[0] = 1.0
|
||||
value_strings[4][0] = '1'
|
||||
values[4] = 1.0
|
||||
value_strings[8][0] = '1'
|
||||
values[8] = 1.0
|
||||
write_matrix_to_values_and_value_strings(values, value_strings, mat3(1))
|
||||
}
|
||||
|
||||
program_add_translation_matrix :: proc(x, y, z: f32) {
|
||||
value_strings, values := matrix_pool_get_mat3()
|
||||
value_strings[0][0] = '1'
|
||||
values[0] = 1.0
|
||||
value_strings[4][0] = '1'
|
||||
values[4] = 1.0
|
||||
fmt.bprint(value_strings[6][:], x)
|
||||
values[6] = x
|
||||
fmt.bprint(value_strings[7][:], y)
|
||||
values[7] = y
|
||||
fmt.bprint(value_strings[8][:], z)
|
||||
values[8] = z
|
||||
write_matrix_to_values_and_value_strings(values, value_strings, mat3 {
|
||||
1, 0, x,
|
||||
0, 1, y,
|
||||
0, 0, z,
|
||||
})
|
||||
}
|
||||
|
||||
program_add_scalar_matrix :: proc(x, y, z: f32) {
|
||||
value_strings, values := matrix_pool_get_mat3()
|
||||
fmt.bprint(value_strings[0][:], x)
|
||||
values[0] = x
|
||||
fmt.bprint(value_strings[4][:], y)
|
||||
values[4] = y
|
||||
fmt.bprint(value_strings[8][:], z)
|
||||
values[8] = z
|
||||
write_matrix_to_values_and_value_strings(values, value_strings, linalg.matrix3_scale(v3{x, y, z}))
|
||||
}
|
||||
|
||||
program_add_rotation_matrix :: proc(angle: f32) {
|
||||
|
|
@ -637,31 +628,29 @@ program_add_rotation_matrix :: proc(angle: f32) {
|
|||
case .Degrees: radians = linalg.RAD_PER_DEG * angle
|
||||
case .Radians: radians = angle
|
||||
}
|
||||
write_matrix_to_values_and_value_strings(values, value_strings, matrix3_rotate2(radians))
|
||||
}
|
||||
|
||||
a := linalg.cos(radians)
|
||||
b := linalg.sin(radians)
|
||||
fmt.bprintf(value_strings[0][:], "%.3f", a)
|
||||
values[0] = a
|
||||
fmt.bprintf(value_strings[1][:], "%.3f", -b)
|
||||
values[1] = -b
|
||||
fmt.bprintf(value_strings[3][:], "%.3f", b)
|
||||
values[3] = b
|
||||
fmt.bprintf(value_strings[4][:], "%.3f", a)
|
||||
values[4] = a
|
||||
fmt.bprint(value_strings[8][:], f32(1.0))
|
||||
values[8] = 1.0
|
||||
write_matrix_to_values_and_value_strings :: proc(values: []f32, value_strings: []InputFloatField, mat: mat3) {
|
||||
for i in 0..<9 {
|
||||
col := i % 3
|
||||
row := i / 3
|
||||
values[i] = mat[col, row]
|
||||
write_float_to_buffer(value_strings[i][:], mat[col, row])
|
||||
}
|
||||
}
|
||||
|
||||
// rotmat := linalg.matrix2_rotate_f32(angle)
|
||||
// fmt.bprint(value_strings[0][:], rotmat[0, 0])
|
||||
// values[0] = rotmat[0, 0]
|
||||
// fmt.bprint(value_strings[1][:], rotmat[0, 1])
|
||||
// values[1] = rotmat[0, 1]
|
||||
// fmt.bprint(value_strings[1][:], rotmat[1, 0])
|
||||
// values[3] = rotmat[1, 0]
|
||||
// fmt.bprint(value_strings[4][:], rotmat[1, 1])
|
||||
// values[4] = rotmat[1, 1]
|
||||
// fmt.bprint(value_strings[8][:], 1)
|
||||
// values[8] = 1.0
|
||||
write_float_to_buffer :: proc(buffer: []byte, value: f32) {
|
||||
fraction := fract(value)
|
||||
if fraction == 0.0 {
|
||||
fmt.bprintf(buffer, "%.0f", value)
|
||||
} else if math.floor(fraction * 10.0) == 1.0 {
|
||||
fmt.bprintf(buffer, "%.1f", value)
|
||||
} else if math.floor(fraction * 100.0) == 1.0 {
|
||||
fmt.bprintf(buffer, "%.2f", value)
|
||||
} else {
|
||||
fmt.bprintf(buffer, "%.3f", value)
|
||||
}
|
||||
}
|
||||
|
||||
program_build_dialog_ui :: proc(ctx: ^ui.Context, dialog_type: ProgramDialogType) -> []ui.Element {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue