Esempio n. 1
0
/* ====================================================== */
static void xmesh_tran (asy::object_inst* dest, void* param,
                        const vec3d_t* rote, const vec3d_t* move,
                        const vec3d_t* scale)
{
    sD3D9_XMSH*         mesh;
    const sD3D9_CALL*   call;

    call = (const sD3D9_CALL*)param;
    if (rote == NULL)
        call->util_make_tran2(&dest->tran, scale, NULL, 0.0f, move);
    else
        call->util_make_tran1(&dest->tran, scale, rote->x, rote->y, rote->z, move);
    if (dest->type == INST_TYPE_STATIC) {
        if (rote == NULL && scale == NULL) {
            mem_cpy(&dest->bound.aabb, &dest->base->aabb, sizeof(sAABB));
            if (move != NULL) {
                for (int idx = 0; idx < 8; idx++) {
                    dest->bound.aabb.v[idx].x += move->x;
                    dest->bound.aabb.v[idx].y += move->y;
                    dest->bound.aabb.v[idx].z += move->z;
                }
            }
        }
        else
        {
            DWORD   bpv, count;
            vec3d_t min, max, tmp, *p_v;

            // rebuild AABB box
            mesh = (sD3D9_XMSH*)dest->base->real;
            bpv = mesh->xmesh->GetNumBytesPerVertex();
            count = mesh->xmesh->GetNumVertices();
            mesh->xmesh->LockVertexBuffer(D3DLOCK_READONLY, (LPVOID*)(&p_v));
            call->util_tran_vec3d(&tmp, p_v, &dest->tran);
            p_v = (vec3d_t*)((byte_t*)p_v + bpv);
            mem_cpy(&min, &tmp, sizeof(vec3d_t));
            mem_cpy(&max, &tmp, sizeof(vec3d_t));
            for (DWORD idx = 1; idx < count; idx++) {
                call->util_tran_vec3d(&tmp, p_v, &dest->tran);
                p_v = (vec3d_t*)((byte_t*)p_v + bpv);
                if (tmp.x < min.x) min.x = tmp.x;
                if (tmp.y < min.y) min.y = tmp.y;
                if (tmp.z < min.z) min.z = tmp.z;
                if (tmp.x > max.x) max.x = tmp.x;
                if (tmp.y > max.y) max.y = tmp.y;
                if (tmp.z > max.z) max.z = tmp.z;
            }
            bound_gen_aabb(&dest->bound.aabb, &min, &max);
            mesh->xmesh->UnlockVertexBuffer();
        }
    }
    else {  // dynamic object don't support scaling
        mem_cpy(&dest->bound.ball, &dest->base->ball, sizeof(sSPHERE));
        if (move != NULL) {
            dest->bound.ball.center.x += move->x;
            dest->bound.ball.center.y += move->y;
            dest->bound.ball.center.z += move->z;
        }
    }
}
Esempio n. 2
0
/* ========================================================== */
static void wavefront_tran (asy::object_inst* dest, void* param,
                            const vec3d_t* rote, const vec3d_t* move,
                            const vec3d_t* scale)
{
    sWAVEFRONT*         mesh;
    const sD3D9_CALL*   call;

    call = (const sD3D9_CALL*)param;
    if (rote == NULL)
        call->util_make_tran2(&dest->tran, scale, NULL, 0.0f, move);
    else
        call->util_make_tran1(&dest->tran, scale, rote->x, rote->y, rote->z, move);
    if (dest->type == INST_TYPE_STATIC) {
        if (rote == NULL && scale == NULL) {
            mem_cpy(&dest->bound.aabb, &dest->base->aabb, sizeof(sAABB));
            if (move != NULL) {
                for (int idx = 0; idx < 8; idx++) {
                    dest->bound.aabb.v[idx].x += move->x;
                    dest->bound.aabb.v[idx].y += move->y;
                    dest->bound.aabb.v[idx].z += move->z;
                }
            }
        }
        else
        {
            vec3d_t min, max, tmp;

            // rebuild AABB box
            mesh = (sWAVEFRONT*)dest->base->real;
            call->util_tran_vec3d(&tmp, mesh->p_v, &dest->tran);
            mem_cpy(&min, &tmp, sizeof(vec3d_t));
            mem_cpy(&max, &tmp, sizeof(vec3d_t));
            for (leng_t idx = 1; idx < mesh->n_v; idx++) {
                call->util_tran_vec3d(&tmp, &mesh->p_v[idx], &dest->tran);
                if (tmp.x < min.x) min.x = tmp.x;
                if (tmp.y < min.y) min.y = tmp.y;
                if (tmp.z < min.z) min.z = tmp.z;
                if (tmp.x > max.x) max.x = tmp.x;
                if (tmp.y > max.y) max.y = tmp.y;
                if (tmp.z > max.z) max.z = tmp.z;
            }
            bound_gen_aabb(&dest->bound.aabb, &min, &max);
        }
    }
    else {  // dynamic object don't support scaling
        mem_cpy(&dest->bound.ball, &dest->base->ball, sizeof(sSPHERE));
        if (move != NULL) {
            dest->bound.ball.center.x += move->x;
            dest->bound.ball.center.y += move->y;
            dest->bound.ball.center.z += move->z;
        }
    }
}
Esempio n. 3
0
/* ======================================================================= */
CR_API bool create_crh3d9_base_xm (asy::object_base* base, sD3D9_XMSH* xmesh,
                create_crh3d9_attr_xm_t fattr, const asy::map_acs<asy::crh3d9_texr>* texpool,
                                    const asy::crh3d9_main* main)
{
    asy::commit_batch   cb;

    base->list.init();
    base->real = NULL;
    base->kill = NULL;
    for (DWORD idx = 0; idx < xmesh->nattr; idx++) {
        cb.attr = fattr(xmesh, idx, texpool, main);
        if (cb.attr == NULL)
            goto _failure1;
        cb.mesh = NULL;
        if (base->list.append(&cb) == NULL)
            goto _failure2;
    }
    if (base->list.size() == 0)
        goto _failure1;
    if (!base->list.no_grow())
        goto _failure1;
    base->real = xmesh;
    xmesh->xcall = (void_t*)main->get_call();
    base->type = MODEL_TYPE_X_MESH;
    base->kill = xmesh_kill;
    base->tran = xmesh_tran;
    bound_gen_aabb(&base->aabb, (vec3d_t*)(&xmesh->min),
                                (vec3d_t*)(&xmesh->max));
    base->ball.center.x = xmesh->center.x;
    base->ball.center.y = xmesh->center.y;
    base->ball.center.z = xmesh->center.z;
    base->ball.radius = xmesh->radius;
    return (true);

_failure2:
    cb.free();
_failure1:
    base->free();
    return (false);
}