Пример #1
0
void mouse_get_3d_ray(Vec3D *position,Vec3D *vector)
{
  Vec3D cam,pos1,pos2,rotation;
  GraphicsView view;
  
  graphics_get_view(&view);
  camera_get_position(&cam);
  
  gluUnProject(__mouse.x, __mouse.y, 0.99f, view.modelView, view.projectionX, view.viewPort, &pos1.x, &pos1.y, &pos1.z);
  gluUnProject(__mouse.x, __mouse.y, 1, view.modelView, view.projectionX, view.viewPort, &pos2.x, &pos2.y, &pos2.z);

  pos2.y *= -1;
  pos1.y *= -1;
  vec3d_add(pos1,cam,pos1);
  vec3d_add(pos2,cam,pos2);
  
  if (position)
  {
    vec3d_cpy((*position),pos1);
  }
  if (vector)
  {
    vec3d_sub((*vector),pos2,pos1);
    vec3d_normalize(vector);
    camera_get_rotation(&rotation);
    vec3d_rotate_about_x(vector,rotation.x);
    vec3d_rotate_about_y(vector,rotation.y);
    vec3d_rotate_about_z(vector,rotation.z);
  }
}
Пример #2
0
Entity *newCube(Vec3D position,const char *name)
{
    Entity * ent;
    char buffer[255];
    int i;
    ent = entity_new();
    if (!ent)
    {
        return NULL;
    }
    /*for (i = 0; i < 24;i++)
    {
        //sprintf(buffer,"models/robot/walk_bot_%06i.obj",i + 1);
        ent->objAnimation[i] = obj_load(buffer);
    }*/
    ent->objModel = obj_load("models/cube.obj");//ent->objAnimation[0];
	if( !ent->objModel )
		slog( "test" );
    ent->texture = LoadSprite("models/cube_text.png",1024,1024); //LoadSprite("models/robot/robot.png",1024,1024);
    vec3d_cpy(ent->body.position,position);
	vec3d_set(ent->scale,1,1,1);
	vec3d_set(ent->rotation,0,0,0);
	vec4d_set(ent->color,1,1,1,1);
    cube_set(ent->body.bounds,-1,-1,-1,2,2,2);
    ent->rotation.x = 90;
    sprintf(ent->name,"%s",name);
    ent->think = think;
    ent->state = 0;
    mgl_callback_set(&ent->body.touch,touch_callback,ent);
    return ent;
}
Пример #3
0
static void space_body_update(Space *space,Body *body)
{
    GList *it;
    Cube a,b;
    Body *other;
    Vec3D stepVector;
    Vec3D stepOffVector;
    
    if ((!body) || (body->_done))return;
    
    vec3d_scale(stepVector,body->velocity,space->stepFactor);
    vec3d_negate(stepOffVector,stepVector);
    
    vec3d_add(body->position,body->position,stepVector);
    
    a.x = body->position.x + body->bounds.x;
    a.y = body->position.y + body->bounds.y;
    a.z = body->position.z + body->bounds.z;
    a.w = body->bounds.w;
    a.h = body->bounds.h;
    a.d = body->bounds.d;
    
    for (it = space->bodylist;it != NULL;it = g_list_next(it))
    {
        if (!it->data)continue;
        if (it->data == body)continue;
        //check for collision
        other = (Body *)it->data;
        vec3d_cpy(b,other->position);
        b.w = other->bounds.w;
        b.h = other->bounds.h;
        b.d = other->bounds.d;
        vec3d_add(b,b,other->bounds);
        if (cube_cube_intersection(a,b))
        {
            //call touch functions
            //back the f**k off
            vec3d_cpy(body->_stepOffVector,stepOffVector);
            body->_done = 1;
            body->_needsBackoff = 1;
            if (body->touch.function)
            {
                body->touch.function(body->touch.data,other);
            }
        }
    }
}
Пример #4
0
Entity *newCube(Vec3D position,const char *name)
{
    Entity * ent;
    ent = entity_new();
    if (!ent)
    {
        return NULL;
    }
    ent->objModel = obj_load("models/cube.obj");
    ent->texture = LoadSprite("models/cube_text.png",1024,1024);
    vec3d_cpy(ent->body.position,position);
    cube_set(ent->body.bounds,-1,-1,-1,2,2,2);
    sprintf(ent->name,"%s",name);
    mgl_callback_set(&ent->body.touch,touch_callback,ent);
	ent->body.id = -3;
    return ent;
}
Пример #5
0
Component *button_new(
    Uint32        id,
    Word        name,
    RectFloat   rect,
    RectFloat        bounds,
    char         * buttonText,
    Uint32        fontSize,
    Uint32        buttonType,
    int         buttonHotkey,
    Uint32        buttonHotkeymod,
    int        center,
    int         justify,
    char         * buttonFileUp,
    char         * buttonFileHigh,
    char         * buttonFileDown,
    Vec3D       backgroundColor,
    float       backgroundAlpha,
    Vec3D       highlightColor,
    Vec3D       pressColor
)
{
    int i;
    ComponentButton *button = NULL;
    Component *component = NULL;
    component = component_new();
    if (!component)return NULL;
    component_make_button(
        component,
        buttonText,
        justify,
        buttonType,
        buttonHotkey,
        buttonHotkeymod,
        buttonFileUp,
        buttonFileHigh,
        buttonFileDown,
        backgroundColor,
        backgroundAlpha,
        highlightColor,
        pressColor,
        fontSize
    );
    rect_copy(&component->rect,rect);
    button = component_get_button_data(component);
    if (button == NULL)
    {
        component_free(&component);
        return NULL;
    }
    button->centered = center;
    component->id = id;
    strncpy(component->name,name,WORDLEN);
    component->type = ButtonComponent;
    component->data_move = button_move;
    for (i = 0; i < ButtonStateMax; i++)
    {
        vec3d_cpy(button->textColor[i],__component_button_color[i]);
    }
    button_move(component,bounds);
    component_button_set_activation(component,
                                    __component_button_release_active,
                                    __component_button_press_active,
                                    __component_button_hold_active);
    return component;
}
Пример #6
0
void component_make_button(
    Component		*component,
    char			*buttonText,
    Uint32	justify,
    Uint32	buttonType,
    int				buttonHotkey,
    Uint32	buttonHotkeymod,
    Line			buttonUpFile,
    Line			buttonHighFile,
    Line			buttonDownFile,
    Vec3D			backgroundColor,
    float			backgroundAlpha,
    Vec3D			highlightColor,
    Vec3D			pressColor,
    Uint32	fontSize
)
{
    ComponentButton * button = NULL;
    if (!component)return;
    component_button_new(component);

    button = component_get_button_data(component);
    if (button == NULL)
    {
        return;
    }
    button->alpha = 1;
    button->fontSize = fontSize;
    button->input = buttonHotkey;
    button->hotkeymod = buttonHotkeymod;

    strncpy(button->buttonText,buttonText,LINELEN);
    button->buttonType = buttonType;
    component->data_update = component_button_update;
    component->data_free = component_button_free;
    component->data_draw = component_button_draw;
    button->justify = justify;
    switch(buttonType)
    {
    case ButtonCustom:
        button->button[ButtonIdle] = sprite_load(buttonUpFile,-1,-1);
        button->button[ButtonHighlight] = sprite_load(buttonHighFile,-1,-1);
        button->button[ButtonPressed] = sprite_load(buttonDownFile,-1,-1);
        if (button->justify == JustifyNone)
        {
            button->justify = JustifyCenter;
        }
        break;
    case ButtonText:
        button->button[ButtonIdle] = NULL;
        button->button[ButtonHighlight] = NULL;
        button->button[ButtonPressed] = NULL;
        if (button->justify == JustifyNone)
        {
            button->justify = JustifyLeft;
        }
        break;
    case ButtonStock:
        button->button[ButtonIdle] = __component_stock_button[ButtonIdle];
        button->button[ButtonHighlight] = __component_stock_button[ButtonHighlight];
        button->button[ButtonPressed] = __component_stock_button[ButtonPressed];
        if (button->justify == JustifyNone)
        {
            button->justify = JustifyCenter;
        }
        break;
    case ButtonRect:
        component->data_draw = component_button_draw_rect;
        vec3d_cpy(button->backgroundColor,backgroundColor);
        button->backgroundAlpha = backgroundAlpha;
        if (button->justify == JustifyNone)
        {
            button->justify = JustifyLeft;
        }
        vec3d_cpy(button->highlightColor,highlightColor);
        vec3d_cpy(button->pressColor,pressColor);
        break;
    }
}