From 42e03ddc3b28c41b81fb5410feb72750530ffa13 Mon Sep 17 00:00:00 2001 From: Frederico Linhares Date: Mon, 22 Aug 2022 17:26:43 -0300 Subject: feat Make camera and model instance more abstract * src/camera.cpp src/camera.hpp: Remove the camera as Vector3D and Rotation3D are going to replace it. * src/model.cpp: Add draw command as instances do not exist anymore. * src/model/instance.cpp src/model/instance.hpp: Remove the instance as Vector3D and Rotation3D are going to replace it. --- src/model/instance.cpp | 98 -------------------------------------------------- 1 file changed, 98 deletions(-) delete mode 100644 src/model/instance.cpp (limited to 'src/model/instance.cpp') diff --git a/src/model/instance.cpp b/src/model/instance.cpp deleted file mode 100644 index 83a93c2..0000000 --- a/src/model/instance.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2022 Frederico de Oliveira Linhares - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "instance.hpp" - -#include "../model.hpp" -#include "../vk/model_instance.hpp" - -// This variable works as a constant -static mrb_sym id_at_model; - -void -cg_free_model_instance(mrb_state *mrb, void* obj) -{ - auto ptr = static_cast(obj); - - mrb_free(mrb, ptr); -} - -const struct mrb_data_type cg_model_instance_type = { - "CG_Model_Instance", cg_free_model_instance }; - -static mrb_value -cg_cModel_cInstance_initialize(mrb_state *mrb, mrb_value self) -{ - mrb_float position_x, position_y, position_z, - rotation_x, rotation_y, rotation_z; - mrb_value model; - VK::ModelInstance *ptr; - - mrb_get_args( - mrb, "offffff", - &model, - &position_x, &position_y, &position_z, - &rotation_x, &rotation_y, &rotation_z); - ptr = (VK::ModelInstance*)DATA_PTR(self); - if(ptr) mrb_free(mrb, ptr); - ptr = (VK::ModelInstance*)mrb_malloc(mrb, sizeof(VK::ModelInstance)); - - mrb_iv_set(mrb, self, id_at_model, model); - ptr->position = glm::vec3(position_x, position_y, position_z); - ptr->rotation = glm::vec3(rotation_x, rotation_y, rotation_z); - - mrb_data_init(self, ptr, &cg_model_instance_type); - return self; -} - -static mrb_value -cg_cModel_cInstance_draw(mrb_state *mrb, mrb_value self) -{ - mrb_value model_v; - - VK::ModelInstance *ptr; - std::shared_ptr *model_ptr; - - model_v = mrb_iv_get(mrb, self, id_at_model); - ptr = (VK::ModelInstance*)DATA_PTR(self); - model_ptr = (std::shared_ptr*) DATA_PTR(model_v); - - auto &instances = - cg_core.vk_graphics_pipeline->models_to_draw[ - cg_core.vk_graphics_pipeline->current_frame][*model_ptr]; - instances.push_back(*ptr); - - return self; -} - -void -cg_model_instance_init(mrb_state *mrb) -{ - struct RClass *cg_m, *cg_cModel, *cg_cInstance; - - id_at_model = mrb_intern_cstr(mrb, "@model"); - - cg_m = mrb_module_get(mrb, "CandyGear"); - cg_cModel = mrb_class_get_under(mrb, cg_m, "Model"); - cg_cInstance = mrb_define_class_under( - mrb, cg_cModel, "Instance", mrb->object_class); - MRB_SET_INSTANCE_TT(cg_cInstance, MRB_TT_DATA); - mrb_define_method( - mrb, cg_cInstance, "initialize", cg_cModel_cInstance_initialize, - MRB_ARGS_REQ(7)); - mrb_define_method( - mrb, cg_cInstance, "draw", cg_cModel_cInstance_draw, MRB_ARGS_NONE()); -} -- cgit v1.2.3