dark-hammer / include / engine / components / cmp-trigger.h

/***********************************************************************************
 * Copyright (c) 2013, Sepehr Taghdisian
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice, 
 *   this list of conditions and the following disclaimer.
 * - Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation 
 *   and/or other materials provided with the distribution.
 *
 ***********************************************************************************/

#ifndef __CMPTRIGGER_H__
#define __CMPTRIGGER_H__

#include "core/vec-math.h"
#include "../cmp-types.h"
#include "../phx-types.h"

/* types */
typedef void (*pfn_cmp_trigger_callback)(struct cmp_obj* trigger_obj, struct cmp_obj* other_obj,
    enum phx_trigger_state state, void* param);

/* */
struct cmp_trigger
{
    /* interface */
    struct vec3f box;
    struct vec3f local_pos;
    struct quat4f local_rot;
    bool_t is_static;
    uint32 collision_filter;

    /* internal */
    phx_obj rbody;
    uint32 px_sceneid;  /* owner scene */
    bool_t triggered; 
    pfn_cmp_trigger_callback trigger_fn;
    void* param;
};

#ifdef __cplusplus
extern "C" {
#endif

ENGINE_API result_t cmp_trigger_modifybox(struct cmp_obj* obj, struct allocator* alloc,
    struct allocator* tmp_alloc, void* data, cmphandle_t cur_hdl);
ENGINE_API result_t cmp_trigger_modifylocalpos(struct cmp_obj* obj, struct allocator* alloc,
    struct allocator* tmp_alloc, void* data, cmphandle_t cur_hdl);
ENGINE_API result_t cmp_trigger_modifylocalrot(struct cmp_obj* obj, struct allocator* alloc,
    struct allocator* tmp_alloc, void* data, cmphandle_t cur_hdl);
ENGINE_API result_t cmp_trigger_modifystatic(struct cmp_obj* obj, struct allocator* alloc,
    struct allocator* tmp_alloc, void* data, cmphandle_t cur_hdl);
ENGINE_API result_t cmp_trigger_modifycolfilter(struct cmp_obj* obj, struct allocator* alloc,
    struct allocator* tmp_alloc, void* data, cmphandle_t cur_hdl);

/* descriptors */
static const struct cmp_value cmp_trigger_values[] = {
    {"box", CMP_VALUE_FLOAT3, offsetof(struct cmp_trigger, box), sizeof(struct vec3f), 1,
    cmp_trigger_modifybox, ""},
    {"local_pos", CMP_VALUE_FLOAT3, offsetof(struct cmp_trigger, local_pos), sizeof(struct vec3f), 
    1, cmp_trigger_modifylocalpos, ""},
    {"local_rot", CMP_VALUE_FLOAT4, offsetof(struct cmp_trigger, local_rot), sizeof(struct quat4f), 
    1, cmp_trigger_modifylocalrot, ""},
    {"static", CMP_VALUE_BOOL, offsetof(struct cmp_trigger, is_static), sizeof(bool_t), 1,
    cmp_trigger_modifystatic, ""},
    {"collision_filter", CMP_VALUE_UINT, offsetof(struct cmp_trigger, collision_filter), 
    sizeof(uint32), 1, cmp_trigger_modifycolfilter, ""}
};
static const uint32 cmp_trigger_valuecnt = 5;
static const uint16 cmp_trigger_type = 0x6dcb;

/* */
result_t cmp_trigger_register(struct allocator* alloc);

/* proxy for trigger events */
void cmp_trigger_register_callback(cmphandle_t trigger_cmp, pfn_cmp_trigger_callback trigger_fn,
    void* param);
void cmp_trigger_unregister_callback(cmphandle_t trigger_cmp);

#ifdef __cplusplus
}
#endif


#endif /* __CMPTRIGGER_H__ */
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.