diff --git a/tools/brmc/HL1Importer.cpp b/tools/brmc/HL1Importer.cpp index b1c68db5..9da1a096 100644 --- a/tools/brmc/HL1Importer.cpp +++ b/tools/brmc/HL1Importer.cpp @@ -34,11 +34,16 @@ br_material *HL1Importer::ConvertMaterial(const aiMaterial *mat, size_t skin_ind if(identifier != nullptr) mp->identifier = BrResStrDup(mp, identifier); + /* + * Texutres are flipped, account for it. + */ + BrMatrix23Scale(&mp->map_transform, BR_SCALAR(1.0f), BR_SCALAR(-1.0f)); + /* * Now figure out the flags. */ mp->mode = BR_MATM_DEPTH_TEST_LE | BR_MATM_MAP_WIDTH_LIMIT_WRAP | BR_MATM_MAP_HEIGHT_LIMIT_WRAP; - mp->flags = BR_MATF_LIGHT; + mp->flags = BR_MATF_LIGHT | BR_MATF_MAP_INTERPOLATION | BR_MATF_MIP_INTERPOLATION; /* * Shading mode. @@ -61,7 +66,7 @@ br_material *HL1Importer::ConvertMaterial(const aiMaterial *mat, size_t skin_ind /* * Alpha testing/colour-keying. */ - int texture_flags = 0xFFFF; + int texture_flags = 0; mat->Get(AI_MATKEY_TEXFLAGS_DIFFUSE(skin_index), texture_flags); if(texture_flags & aiTextureFlags_UseAlpha) { @@ -164,10 +169,10 @@ void HL1Importer::Import(const aiScene *scene) noexcept mdl.model->identifier = BrResSprintf(mdl.model, "%s_%zu", model->mName.C_Str(), k); if(mdl.count == 1) { -// if(mdl.actors[0]->identifier != nullptr) -// BrResFree(mdl.actors[0]->identifier); + // if(mdl.actors[0]->identifier != nullptr) + // BrResFree(mdl.actors[0]->identifier); - //mdl.actors[0]->identifier + // mdl.actors[0]->identifier BrActorAdd(brap, mdl.actors[0]); continue; @@ -178,9 +183,9 @@ void HL1Importer::Import(const aiScene *scene) noexcept group->t.type = BR_TRANSFORM_IDENTITY; for(size_t w = 0; w < mdl.count; ++w) { -// if(mdl.actors[w]->identifier != nullptr) -// BrResFree(mdl.actors[w]->identifier); -// mdl.actors[w]->identifier = BrResSprintf(); + // if(mdl.actors[w]->identifier != nullptr) + // BrResFree(mdl.actors[w]->identifier); + // mdl.actors[w]->identifier = BrResSprintf(); BrActorAdd(group, mdl.actors[w]); } @@ -188,7 +193,7 @@ void HL1Importer::Import(const aiScene *scene) noexcept } } - int preview(br_actor *root); + int preview(br_actor * root); preview(root); diff --git a/tools/brmc/preview.cpp b/tools/brmc/preview.cpp index 01ef7b23..83ca6010 100644 --- a/tools/brmc/preview.cpp +++ b/tools/brmc/preview.cpp @@ -34,7 +34,6 @@ static void create_scene(br_pixelmap *screen, br_actor **_world, br_actor **_cam BrMatrix34Translate(&camera->t.t.mat, BR_SCALAR(0), BR_SCALAR(0), BR_SCALAR(100)); - *_world = world; *_camera = camera; @@ -59,10 +58,14 @@ int preview(br_actor *root) int ret = -1; br_error r; br_actor *world = NULL, *camera = NULL, *cube = NULL; + br_camera *camdata; br_uint_64 ticks_last, ticks_now; br_boolean is_fullscreen = BR_FALSE; SDL_Window *window; + br_int_32 mx_rel, my_rel; + br_scalar mwheel_rel; + /* * QoL for those poor X11 users. */ @@ -105,9 +108,14 @@ int preview(br_actor *root) BrRendererBegin(colour_buffer, NULL, NULL, primitive_heap, sizeof(primitive_heap)); create_scene(screen, &world, &camera, root); + camdata = static_cast(camera->type_data); ticks_last = SDL_GetTicks64(); + mx_rel = 0; + my_rel = 0; + mwheel_rel = -85.0f; + for(SDL_Event evt;;) { float dt; @@ -160,11 +168,36 @@ int preview(br_actor *root) is_fullscreen = !is_fullscreen; break; } + + if(evt.key.keysym.sym == SDLK_SPACE) { + mx_rel = 0; + my_rel = 0; + mwheel_rel = 85.0f; + } break; } + case SDL_MOUSEMOTION: + mx_rel += evt.motion.xrel; + my_rel += evt.motion.yrel; + break; + case SDL_MOUSEWHEEL: + mwheel_rel += evt.wheel.preciseY; + break; } } + br_scalar xdiff = BR_DIV(BR_SCALAR(mx_rel), BR_SCALAR(screen->width)); + br_scalar ydiff = BR_DIV(BR_SCALAR(my_rel), BR_SCALAR(screen->height)); + if(-mwheel_rel < 1.0f) + mwheel_rel = -1.0f; + + fprintf(stderr, "%d, %d, %f\n", mx_rel, my_rel, mwheel_rel); + BrMatrix34Identity(&camera->t.t.mat); + + BrMatrix34PostTranslate(&camera->t.t.mat, 0, 0, -mwheel_rel); + BrMatrix34PostRotateY(&camera->t.t.mat, BR_ANGLE_DEG(fmodf(-xdiff * 1000, 360))); + BrMatrix34PostRotateX(&camera->t.t.mat, BR_ANGLE_DEG(fmodf(-ydiff * 1000, 360))); + BrRendererFrameBegin(); BrPixelmapFill(colour_buffer, BR_COLOUR_RGB(66, 66, 66)); BrPixelmapFill(depth_buffer, 0xFFFFFFFF);