Skip to content

Commit

Permalink
brbarney
Browse files Browse the repository at this point in the history
  • Loading branch information
vs49688 committed Sep 27, 2024
1 parent 1c09fc9 commit c6b4ba9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
23 changes: 14 additions & 9 deletions tools/brmc/HL1Importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -178,17 +183,17 @@ 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]);
}
}
}
}

int preview(br_actor *root);
int preview(br_actor * root);

preview(root);

Expand Down
35 changes: 34 additions & 1 deletion tools/brmc/preview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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.
*/
Expand Down Expand Up @@ -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<br_camera *>(camera->type_data);

ticks_last = SDL_GetTicks64();

mx_rel = 0;
my_rel = 0;
mwheel_rel = -85.0f;

for(SDL_Event evt;;) {
float dt;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c6b4ba9

Please sign in to comment.