Closed ghost closed 2 years ago
I'm not sure I understand the comment.
For positioning, you'd typically use AllegroFlare::Placement3D
. There's a little discussion here on allegro.cc here. The orientation and coordinate of the underlying model does not change.
Instead one can use drawing transforms to relocate a model, as long as you do not clear the depth buffer. I'll show an example: struct model_info{ ALLEGRO_VERTEX buffer = new ALLEGRO_VERTEX[8];// not gonnabother typing out the vertices for a standard cube; int indicies= new int[36] ;// not gonna bother with this either int indicie_amount = 36; ALLEGRO_BITMAP bmp; vector3 scale; vector3 rotation; vector3 position; }; struct camera_info { vector3 position; vector3 rotation; }; void draw() { ALLEGRO_TRANSFORM po; al_identity_transform(&po); al_perspective_transform(&po, -0.5f, -0.5f, 1.0f, 0.5f , 0.5f, 100.0f); al_use_projection_transform(&po); model_info model; model.position = vector3(0,0,20); model.scale = vector3(1,1,1); model.rotation = vector3(0,0,M_PI/9); camera_info camera; camera.position = vector3(0,0,0); camera.rotation = vector3(0,0,0); al_set_render_state(ALLEGRO_DEPTH_TEST, true); al_set_render_state(ALLEGRO_DEPTH_FUNCTION, ALLEGRO_RENDER_LESS_EQUAL); al_clear_depth_buffer(1); ALLEGRO_TRANSFORM transform; al_identity_transform(&transform); al_scale_transform_3d(&transform,model.scale.x,model.scale.y,model.scale.z); al_rotate_transform_3d(&transform,1,0,0,model.rotation.x); al_rotate_transform_3d(&transform,0,1,0,model.rotation.y); al_rotate_transform_3d(&transform,0,0,1,model.rotation.z); vector3 cam_offset = model.position - camera.position; // camera offset from the model al_translate_transform_3d(&transform, cam_offset.x,cam_offset.y,cam_offset.z);
// Idk how camera rotation gets done by you, so this is just a placeholder al_rotate_transform_3d(&transform,1,0,0,camera.rotation.x); al_rotate_transform_3d(&transform,0,1,0,camera.rotation.y); al_rotate_transform_3d(&transform,0,0,1,camera.rotation.z); al_use_transform(&transform); al_draw_indexed_prim(model.buffer, NULL, model.bmp, model.indicies, indicie_amount, ALLEGRO_PRIM_TRIANGLE_LIST);
model_info model2; model2.position = vector3(0,0,40); model2.scale = vector3(3,3,1); model2.rotation = vector3(0,0,M_PI/9); al_identity_transform(&transform); al_scale_transform_3d(&transform,model2.scale.x,model2.scale.y,model2.scale.z); al_rotate_transform_3d(&transform,1,0,0,model2.rotation.x); al_rotate_transform_3d(&transform,0,1,0,model2.rotation.y); al_rotate_transform_3d(&transform,0,0,1,model2.rotation.z); vector3 cam_offset = model2.position - camera.position; al_translate_transform_3d(&transform, cam_offset.x,cam_offset.y,cam_offset.z); al_rotate_transform_3d(&transform,1,0,0,camera.rotation.x); al_rotate_transform_3d(&transform,0,1,0,camera.rotation.y); al_rotate_transform_3d(&transform,0,0,1,camera.rotation.z); al_use_transform(&transform); al_draw_indexed_prim(model2.buffer, NULL, model2.bmp, model2.indicies, model2.indicie_amount, ALLEGRO_PRIM_TRIANGLE_LIST); }