matrices and operators */
| 589 | |
| 590 | /* matrices and operators */ |
| 591 | bv_variable lib_common_mat_constructor(bv_program* prog, bv_object* me, u8 count, bv_variable* args) |
| 592 | { |
| 593 | sd::Matrix* data = new sd::Matrix(); |
| 594 | sd::GetMatrixSizeFromName(me->type->name, &data->Columns, &data->Rows); |
| 595 | data->Type = sd::GetMatrixTypeFromName(me->type->name); |
| 596 | data->Data = glm::mat4(0.0f); |
| 597 | |
| 598 | bv_variable ret = bv_variable_create_void(); |
| 599 | me->user_data = (void*)data; |
| 600 | |
| 601 | if (count == 1) { |
| 602 | // mat(mat) |
| 603 | if (args[0].type == bv_type_object) { |
| 604 | bv_object* mat = bv_variable_get_object(args[0]); |
| 605 | sd::Matrix* copyData = (sd::Matrix*)mat->user_data; |
| 606 | |
| 607 | for (int x = 0; x < copyData->Columns && x < data->Columns; x++) |
| 608 | for (int y = 0; y < copyData->Rows && y < data->Rows; y++) |
| 609 | data->Data[x][y] = copyData->Data[x][y]; |
| 610 | } |
| 611 | // mat(scalar) |
| 612 | else { |
| 613 | float scalar = bv_variable_get_float(bv_variable_cast(data->Type, args[0])); |
| 614 | data->Data = glm::mat4(scalar); |
| 615 | } |
| 616 | |
| 617 | } |
| 618 | else if (count == data->Columns) // mat(col0, col1, ...) |
| 619 | { |
| 620 | for (u8 x = 0; x < data->Columns; x++) { |
| 621 | bv_object* vecCol = bv_variable_get_object(args[x]); |
| 622 | for (u8 y = 0; y < data->Rows && y < vecCol->type->props.name_count; y++) |
| 623 | data->Data[x][y] = bv_variable_get_float(bv_variable_cast(data->Type, vecCol->prop[y])); |
| 624 | } |
| 625 | } |
| 626 | else if (count == data->Columns * data->Rows) // mat(scalar, scalar, ...) |
| 627 | { |
| 628 | for (u8 x = 0; x < data->Columns; x++) |
| 629 | for (u8 y = 0; y < data->Rows; y++) { |
| 630 | float scalar = bv_variable_get_float(bv_variable_cast(data->Type, args[x * data->Columns + y])); |
| 631 | data->Data[x][y] = scalar; |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | return ret; |
| 636 | } |
| 637 | void lib_common_mat_destructor(bv_object* me) |
| 638 | { |
| 639 | if (me->user_data != 0) |
nothing calls this directly
no test coverage detected