~jb55/polyadvent

ref: ace61e7aac04b5e424087b938f7bd8300d92f905 polyadvent/src/scene.c -rw-r--r-- 2.5 KiB
ace61e7aWilliam Casarin increase max ents 1 year, 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "game.h"
#include "model.h"
#include "procmesh.h"
#include "debug.h"
#include "vec3.h"
#include <assert.h>

void reset_scene(struct game *game) {
    struct entity *terrain_ent = get_terrain_entity(&game->terrain);
    struct entity *player_ent = get_player(&game->test_resources);

    destroy_entities();

    // hide terrain and player by default
    terrain_ent->flags |= ENT_INVISIBLE;
    player_ent->flags |= ENT_INVISIBLE;
}

void default_scene(struct game *game) {
    struct terrain *terrain = &game->terrain;
    struct entity *terrain_ent = get_terrain_entity(terrain);
    struct entity *player = get_player(&game->test_resources);

    // show terrain
    terrain_ent->flags &= ~ENT_INVISIBLE;

    // show player
    player->flags &= ~ENT_INVISIBLE;

    struct entity *tower = new_entity(NULL);
    struct node *tnode = get_node(&tower->node_id);

    assert(tnode);
    tower->model_id = get_static_model(model_tower, NULL);
    node_set_label(tnode, "tower");
    node_attach(&tower->node_id, &player->node_id);
    node_translate(tnode, V3(0.0, 50.0, 0.0));
    node_recalc(tnode);
    float z = terrain->fn(terrain, tnode->mat[M_X], tnode->mat[M_Y]);
    /* node_detach(tnode, pnode); */
    tnode->mat[M_Z] = z;
    // END ENTITIES


}



void entity_test_scene(struct game *game)
{
    struct terrain *terrain  = &game->terrain;

    model_id rock_model;
    init_id(&rock_model);

    /* model_id rock_model = get_static_model(model_tower, NULL); */
    struct model *pmodel  = new_model(&rock_model); assert(pmodel);
    struct geometry *geom = get_geometry(&pmodel->geom_id); assert(geom);
    proc_sphere(geom);

    for (int i = 0; i < 5; i++) {
        struct entity *ent = new_entity(NULL);
        struct node *node  = get_node(&ent->node_id);

        ent->model_id = rock_model;

        double x = rand_0to1() * terrain->size;
        double y = rand_0to1() * terrain->size;
        double z = terrain->fn(terrain, x, y);

        node_scale(node, pow(15.0, rand_0to1()));
        node_rotate(node, V3(rand_0to1(),rand_0to1(),rand_0to1()));
        node_translate(node, V3(x, y, z));
        node_set_label(node, "rock");

        node_recalc(node);
    }

}

void pbr_scene(struct game *game)
{
    struct entity *ent = new_entity(NULL);
    struct node *node  = get_node(&ent->node_id); assert(node);
    struct entity *player = get_player(&game->test_resources);

    ent->model_id = get_static_model(model_icosphere, NULL);
    node_set_label(node, "sphere");
}