Exemplo n.º 1
0
void Polygon_Transform(polygon_p ret, polygon_p src, float tr[16])
{
    vertex_p ret_v, src_v;

    Mat4_vec3_rot_macro(ret->plane, tr, src->plane);
    ret_v = ret->vertices;
    src_v = src->vertices;
    for(uint16_t i = 0; i < src->vertex_count; i++, ret_v++, src_v++)
    {
        Mat4_vec3_mul_macro(ret_v->position, tr, src_v->position);
        Mat4_vec3_rot_macro(ret_v->normal, tr, src_v->normal);
    }

    ret->plane[3] = -vec3_dot(ret->plane, ret->vertices[0].position);
}
Exemplo n.º 2
0
void Polygon_TransformSelf(polygon_p p, float tr[16])
{
    float v[3];
    vertex_p vp;

    Mat4_vec3_rot_macro(v, tr, p->plane);
    vec3_copy(p->plane, v);
    vp = p->vertices;
    for(uint16_t i = 0; i < p->vertex_count; i++, vp++)
    {
        Mat4_vec3_mul_macro(v, tr, vp->position);
        vec3_copy(vp->position, v);
        Mat4_vec3_rot_macro(v, tr, vp->normal);
        vec3_copy(vp->normal, v);
    }

    p->plane[3] = -vec3_dot(p->plane, p->vertices[0].position);
}
Exemplo n.º 3
0
int StateControl_Wolf(struct entity_s *ent, struct ss_animation_s *ss_anim)
{
    character_command_p cmd = &ent->character->cmd;
    character_state_p state = &ent->character->state;
    uint16_t current_state = Anim_GetCurrentState(ss_anim);

    ent->character->rotate_speed_mult = 1.0f;
    ent->dir_flag = ENT_STAY;
    ss_anim->anim_frame_flags = ANIM_NORMAL_CONTROL;

    state->sprint = 0x00;
    state->crouch = 0x00;
    state->attack = 0x00;
    state->can_attack = 0x00;

    if(!state->dead && (ent->character->target_id != ENTITY_ID_NONE))
    {
        entity_p target = World_GetEntityByID(ent->character->target_id);
        if(target && Room_IsInNearRoomsList(ent->self->room, target->self->room))
        {
            float pos[3], *v = ent->bf->bone_tags[ent->character->bone_head].current_transform + 12;
            Mat4_vec3_mul_macro(pos, ent->transform.M4x4, v);
            pos[0] -= target->obb->centre[0];
            pos[1] -= target->obb->centre[1];
            pos[2] -= target->obb->centre[2];
            if((pos[2] > -target->obb->extent[2]) && (pos[2] < target->obb->extent[2]) &&
               (pos[0] * pos[0] + pos[1] * pos[1] < 400.0f * 400.0f))
            {
                state->can_attack = 0x01;
            }
        }
    }

    switch(current_state)
    {
        case TR_STATE_WOLF_STAY:// 1    // -> 2 -> 7 -> 8 -> 9
            cmd->rot[0] = 0;
            if(state->dead)
            {
                Entity_SetAnimation(ent, ANIM_TYPE_BASE, TR_ANIMATION_WOLF_DEAD1, 0, NULL);
            }
            else if(cmd->move[0] > 0)
            {
                ss_anim->target_state = TR_STATE_WOLF_WALK;
                ent->dir_flag = ENT_MOVE_FORWARD;
            }
            else if(cmd->shift)
            {
                ss_anim->target_state = TR_STATE_WOLF_STAY_CROUCH;
            }
            else if(cmd->action)
            {
                ss_anim->target_state = TR_STATE_WOLF_WOOOO;
            }
            else if(cmd->move[0] < 0)
            {
                ss_anim->target_state = TR_STATE_WOLF_IDLE;
            }
            else
            {
                ent->dir_flag = ENT_MOVE_FORWARD;
            }
            break;

        case TR_STATE_WOLF_STAY_CROUCH:// 9 // -> 1 -> 3 -> 5 -> 7 -> 12
            if(state->dead)
            {
                Entity_SetAnimation(ent, ANIM_TYPE_BASE, TR_ANIMATION_WOLF_DEAD1, 0, NULL);
            }
            else if(cmd->move[0] > 0)
            {
                ent->dir_flag = ENT_MOVE_FORWARD;
                ss_anim->target_state = (cmd->shift) ? (TR_STATE_WOLF_CROUCH) : (TR_STATE_WOLF_RUN);
            }
            else if(cmd->action)
            {
                cmd->rot[0] = 0;
                ss_anim->target_state = TR_STATE_WOLF_STAY_ATTACK;
            }
            else if(cmd->jump)
            {
                cmd->rot[0] = 0;
                ss_anim->target_state = TR_STATE_WOLF_WOOOO;
            }
            else if(cmd->shift)
            {
                ss_anim->target_state = TR_STATE_WOLF_STAY_CROUCH;
            }
            else
            {
                ent->dir_flag = ENT_MOVE_FORWARD;
                ss_anim->target_state = TR_STATE_WOLF_STAY;
            }
            break;

        case TR_STATE_WOLF_WALK:// 2    // -> 1 -> 5
            if(state->dead)
            {
                Entity_SetAnimation(ent, ANIM_TYPE_BASE, TR_ANIMATION_WOLF_DEAD1, 0, NULL);
            }
            else if(cmd->move[0] > 0)
            {
                ent->dir_flag = ENT_MOVE_FORWARD;
                ss_anim->target_state = (cmd->shift) ? (TR_STATE_WOLF_WALK) : (TR_STATE_WOLF_CROUCH);
            }
            else
            {
                ent->dir_flag = ENT_MOVE_FORWARD;
                ss_anim->target_state = TR_STATE_WOLF_STAY;
            }
            break;

        case TR_STATE_WOLF_RUN:// 3     // -> 6 -> 9 -> 10
            if(state->dead)
            {
                Entity_SetAnimation(ent, ANIM_TYPE_BASE, TR_ANIMATION_WOLF_DEAD1, 0, NULL);
            }
            else if(cmd->action)
            {
                ss_anim->target_state = TR_STATE_WOLF_JUMP_ATTACK;
            }
            else if(cmd->move[0] > 0)
            {
                ent->dir_flag = ENT_MOVE_FORWARD;
                ss_anim->target_state = (cmd->shift) ? (TR_STATE_WOLF_RUN) : (TR_STATE_WOLF_CROUCH);
            }
            else if(cmd->roll)
            {
                ent->dir_flag = ENT_MOVE_FORWARD;
                ss_anim->target_state = TR_STATE_WOLF_RUN_RIGHT;
            }
            else
            {
                ent->dir_flag = ENT_MOVE_FORWARD;
                ss_anim->target_state = TR_STATE_WOLF_STAY_CROUCH;
            }
            break;

        case TR_STATE_WOLF_CROUCH:// 5  // -> 3 -> 9 -> 12
            if(state->dead)
            {
                Entity_SetAnimation(ent, ANIM_TYPE_BASE, TR_ANIMATION_WOLF_DEAD1, 0, NULL);
            }
            else if(cmd->action)
            {
                cmd->rot[0] = 0;
                ent->dir_flag = ENT_MOVE_FORWARD;
                ss_anim->target_state = TR_STATE_WOLF_JUMP_ATTACK;
            }
            else if(cmd->move[0] > 0)
            {
                ent->dir_flag = ENT_MOVE_FORWARD;
                ss_anim->target_state = (cmd->shift) ? (TR_STATE_WOLF_CROUCH) : (TR_STATE_WOLF_RUN);
            }
            else
            {
                cmd->rot[0] = 0;
                ent->dir_flag = ENT_MOVE_FORWARD;
                ss_anim->target_state = TR_STATE_WOLF_STAY_CROUCH;
            }
            break;

        case TR_STATE_WOLF_STAY_ATTACK:// 12
            state->attack = 0x01;
            break;

        case TR_STATE_WOLF_JUMP_ATTACK:// 6   // -> 3
            ent->dir_flag = ENT_MOVE_FORWARD;
            state->attack = 0x01;
            if(state->dead)
            {
                Entity_SetAnimation(ent, ANIM_TYPE_BASE, TR_ANIMATION_WOLF_DEAD3, 0, NULL);
            }
            else if(cmd->action)
            {
                ss_anim->target_state = TR_STATE_WOLF_JUMP_ATTACK;
            }
            else
            {
                ss_anim->target_state = TR_STATE_WOLF_RUN;
            }
            break;

        case TR_STATE_WOLF_WOOOO:// 7
            cmd->rot[0] = 0;
            break;

        case TR_STATE_WOLF_IDLE:// 8    // -> 1
            cmd->rot[0] = 0;
            ent->no_move = 0x01;
            if(state->dead)
            {
                Entity_SetAnimation(ent, ANIM_TYPE_BASE, TR_ANIMATION_WOLF_DEAD1, 0, NULL);
            }
            else if(cmd->move[0] > 0)
            {
                ent->dir_flag = ENT_MOVE_FORWARD;
                ss_anim->target_state = TR_STATE_WOLF_STAY;
            }
            else
            {
                ss_anim->target_state = TR_STATE_WOLF_IDLE;
            }
            break;

        case TR_STATE_WOLF_RUN_RIGHT:// 10
            if(state->dead)
            {
                Entity_SetAnimation(ent, ANIM_TYPE_BASE, TR_ANIMATION_WOLF_DEAD2, 0, NULL);
            }
            else
            {
                cmd->rot[0] = -1;
                ent->dir_flag = ENT_MOVE_FORWARD;
            }
            break;

        case TR_STATE_WOLF_DEAD:// 11
            state->dead = 0x01;
            if(ss_anim->model->animations[ss_anim->current_animation].max_frame <= ss_anim->current_frame + 1)
            {
                state->dead = 0x02;
                state->ragdoll = 0x01;
            }
            break;

        default:
            cmd->rot[0] = 0;
            break;
    };

    return 0;
}
Exemplo n.º 4
0
void CDynamicBSP::AddNewPolygonList(struct polygon_s *p, float transform[16], struct frustum_s *f)
{
    for( ; p && (!m_realloc_state); p = p->next)
    {
        m_temp_allocated = 0;
        polygon_p np = this->CreatePolygon(p->vertex_count);
        bool visible = (f == NULL);
        vertex_p src_v, dst_v;

        np->anim_id = p->anim_id;
        np->frame_offset = p->frame_offset;
        np->double_side  = p->double_side;

        np->transparency = p->transparency;

        Mat4_vec3_rot_macro(np->plane, transform, p->plane);
        for(uint16_t i = 0; i < p->vertex_count; i++)
        {
            src_v = p->vertices + i;
            dst_v = np->vertices + i;
            Mat4_vec3_mul_macro(dst_v->position, transform, src_v->position);
        }
        np->plane[3] = -vec3_dot(np->plane, np->vertices[0].position);

        for(frustum_p ff = f; (!visible) && ff; ff = ff->next)
        {
            if(Frustum_IsPolyVisible(np, ff, false))
            {
                visible = true;
                break;
            }
        }

        if(visible)
        {
            if(p->anim_id > 0)
            {
                anim_seq_p seq = m_anim_seq + p->anim_id - 1;
                uint16_t frame = (seq->current_frame + p->frame_offset) % seq->frames_count;
                tex_frame_p tf = seq->frames + frame;
                np->texture_index = tf->texture_index;

                for(uint16_t i = 0; i < p->vertex_count; i++)
                {
                    src_v = p->vertices + i;
                    dst_v = np->vertices + i;
                    Mat4_vec3_rot_macro(dst_v->normal, transform, src_v->normal);
                    vec4_copy(dst_v->color, src_v->color);
                    ApplyAnimTextureTransformation(dst_v->tex_coord, src_v->tex_coord, tf);
                }
            }
            else
            {
                np->texture_index = p->texture_index;
                for(uint16_t i = 0; i < p->vertex_count; i++)
                {
                    src_v = p->vertices + i;
                    dst_v = np->vertices + i;
                    Mat4_vec3_rot_macro(dst_v->normal, transform, src_v->normal);
                    vec4_copy(dst_v->color, src_v->color);
                    dst_v->tex_coord[0] = src_v->tex_coord[0];
                    dst_v->tex_coord[1] = src_v->tex_coord[1];
                }
            }
            m_input_polygons++;
            this->AddPolygon(m_root, np);
        }
    }
}