Example #1
0
static inline void drawLight(vec2 * pos, float size){
	glPushMatrix();
	glTranslatef(pos->x,pos->y,0);
	backTransform();
	glTranslatef(0,0.2,0);
		Begin(GL_TRIANGLE_FAN);
			TexCoord2f (0.0f, 0.0f);
			Vertex2f(-size,-size);
			TexCoord2f (0.0f, 1.0f);
			Vertex2f(-size,size);
			TexCoord2f (1.0f, 1.0f);
			Vertex2f(size,size);
			TexCoord2f (1.0f, 0.0f);
			Vertex2f(size,-size);
		End();
	glPopMatrix();
}
Example #2
0
void drawLightsMask(){
	Color4f(1,1,1,0.95);
	setTexture(lights);
//	glEnable(GL_TEXTURE_2D);
//	glBlendFunc(GL_ONE_MINUS_SRC_ALPHA,GL_SRC_ALPHA);
	Begin(GL_TRIANGLE_FAN);
		TexCoord2f (0.01f, 0.01f);
		Vertex2f(0,0);
		TexCoord2f (0.01f, 0.99f);
		Vertex2f(0,config.options.window.height);
		TexCoord2f (0.99f, 0.99f);
		Vertex2f(config.options.window.width,config.options.window.height);
		TexCoord2f (0.99f, 0.01f);
		Vertex2f(config.options.window.width,0);
	End();
//	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
}
Example #3
0
static inline void vertex (fpoint tl, fpoint br, float x, float y,
                           fsize tex_tl, fsize tex_br, fsize tex_uv)
{
    float tx = (x - tl.x) / tex_uv.width;
    tx *= tex_br.width - tex_tl.width;

    float ty = (y - tl.y) / tex_uv.height;
    ty *= tex_br.height - tex_tl.height;

    Color4u(gl_color_current());
    TexCoord2f(tx, ty);
    Vertex2f(x, y);
}
Example #4
0
void SummonController::HotspotClick(const Vertex2i &pos, int kind)
{
    bool clicked = false;

    const Camera screenCamera(Vertex2f(0, 0), Vertex2f(1, 1), Vertex2f(0, 0));
    const Camera worldCamera = m_view->GetCamera();

    // process hotspots in screen
    if (m_screen) {
        // get all commands triggered by this click
        Vertex2i pt = m_view->WindowToScreen(pos.x, pos.y);
        Vertex2f pt2 = Vertex2f(pt.x, pt.y);
        list<Command*> cmdList = m_screen->HotspotClick(pt2, screenCamera, kind);

        // execute and free all commands triggered
        for (list<Command*>::iterator i=cmdList.begin(); i!=cmdList.end(); i++)
        {
            clicked = true;
            ExecCommand(*(*i));
            delete (*i);
        }
    }

    // process hotspots in world (only if no hotspots clicked in screen)
    if (m_world && !clicked) {
        // get all commands triggered by this click    
        Vertex2f pt = m_view->WindowToWorld(pos.x, pos.y);
        list<Command*> cmdList = m_world->HotspotClick(pt, worldCamera, kind);
        
        // execute and free all commands triggered
        for (list<Command*>::iterator i=cmdList.begin(); i!=cmdList.end(); i++)
        {
            ExecCommand(*(*i));
            delete (*i);
        }
    }
    
    
}
/*
##     ## ########  ########     ###    ######## ######## 
##     ## ##     ## ##     ##   ## ##      ##    ##       
##     ## ##     ## ##     ##  ##   ##     ##    ##       
##     ## ########  ##     ## ##     ##    ##    ######   
##     ## ##        ##     ## #########    ##    ##       
##     ## ##        ##     ## ##     ##    ##    ##       
 #######  ##        ########  ##     ##    ##    ######## 
 */
void SpaceInvadersState::Update(float dt){
	// Camera transformation
	Vertex3f trans;
	
	// Speed
	float speed = 0.005f;
	if(input->IsKey(KEY::Shift))	// Shift
		speed *= 2.f;

	// Check control and Rotation
    bool move = false;
	bool control = false;
	bool rotation = false;
	if(input->IsKey(KEY::Control)){	// Control
		control = rotation = true;
        speed *= 0.5f;
    }

	// Camera movement
	if(input->IsKey(KEY::W) || input->IsKey(KEY::Up)){	// Up
        Vertex3f vertex(0.f, speed, 0.f);
        trans += vertex;
        move = true;
	}
    
	if(input->IsKey(KEY::S) || input->IsKey(KEY::Down)){	// Down
        Vertex3f vertex(0.f, -speed, 0.f);
        trans += vertex;
        move = true;
	}
	if(input->IsKey(KEY::A) || input->IsKey(KEY::Left)){	// Left
        Vertex3f vertex(-speed, 0.f, 0.f);
		trans += vertex;
        move = true;
    }
	if(input->IsKey(KEY::D) || input->IsKey(KEY::Right)){	// Right
        Vertex3f vertex(speed, 0.f, 0.f);
		trans += vertex;
        move = true;
    }

    if(input->IsKey(KEY::Space))
    {
    	input->SetKey(KEY::Space, false);
    	if(spaceship)
    		spaceship->Fire();
    }
    
	if(input->IsKey(KEY::E)){	// Forward
        Vertex3f vertex(0.f, 0.f, -speed);
        trans += vertex;
        move = true;
    }
	if(input->IsKey(KEY::Q)){	// Backward
        Vertex3f vertex(0.f, 0.f, speed);
        trans += vertex;
        move = true;
    }

    if(move)
    {
        //renderRay = false;
        if(!rotation)
        {
            spaceship->AddMovement(Vertex2f(trans));
            //camera->Move(trans);
        }
        else
        {
            //camera->Rotate(trans);
        }
    }

    // Update the spaceship
    spaceship->Update(dt);
}
Example #6
0
namespace Summon {


const Camera g_defaultCamera(Vertex2f(0, 0), Vertex2f(1, 1), Vertex2f(0, 0));


Element *GetElementFromObject(PyObject *obj)
{
    if (PyObject_HasAttrString(obj, (char*) "ptr")) {
        PyObject* ptr = PyObject_GetAttrString(obj, (char*) "ptr");
        long addr = PyLong_AsLong(ptr);
        Py_DECREF(ptr);
        
        return Id2Element(addr); //(Element*) addr;
    } else {
        // python code
        // NOTE: I think the only element that uses this code is a color
        // construct outside any graphic
        
        // do nothing if not a tuple
        // and check that header is int
        if (!PyTuple_Check(obj) ||
            PyTuple_GET_SIZE(obj) < 1 ||
            !PyInt_Check(PyTuple_GET_ITEM(obj, 0)))
            return NULL;
        
        // build element based on header
        int elmid = (int) PyInt_AsLong(PyTuple_GET_ITEM(obj, 0));

        Element *elm = g_elementFactory.Create(elmid);
        if (elm == NULL) {
            // invalid elmid, return error
            return NULL;
        }
        
        Scm code = Py2ScmTake(PyTuple_GetSlice(obj, 1, PyTuple_GET_SIZE(obj)));
        
        if (!elm->Build(elmid, code)) {
            delete elm;
            return NULL;
        }
        
        // return the built element
        return elm;
    }
}


Element *GetElementFromObject(const Scm code)
{
    return GetElementFromObject(code.GetPy());
}


Element::Element(ElementId id) : 
    m_id(id), 
    m_visible(true),      
    m_referenced(0),
    m_model(NULL),
    m_transformParent(NULL),
    m_parent(NULL),
    m_child(NULL),
    m_next(NULL),
    m_prev(NULL)
{}
    

Element::~Element()
{
    // delete all child elements
    for (Element *elm=m_child; elm; elm=elm->m_next) {
        // clear parent pointer
        elm->m_parent = NULL;
        elm->DecRef();
        if (!elm->IsReferenced())
            delete elm;
    }
}

// recursively build child elements and if sucessful, add them as children
bool Element::Build(int header, const Scm &code)
{
    if (!ScmConsp(code))
        return true;

    Scm children = code;
    
    // process children
    for (; children.Size() > 0; children.Pop()) {
        Scm child = children.GetScm(0);
        if (!AddChild(child))
            return false;
    }
    return true;
}

Element *Element::AddChild(Scm code)
{
    Element *elm = GetElementFromObject(code);

    // if error with child, report error
    if (!elm)
        return NULL;

    // ensure elements are not added twice
    if (elm->GetParent() != NULL) {
        Error("element already has parent.");
        return NULL;
    }

    AddChild(elm);

    return elm;
}

void Element::ReplaceChild(Element *oldchild, Element *newchild)
{
    newchild->m_parent = this;
    newchild->m_next = oldchild->m_next;
    newchild->m_prev = oldchild->m_prev;
    
    if (newchild->m_next)
        newchild->m_next->m_prev = newchild;
    if (oldchild == m_child) {
        // replace first child
        m_child = newchild;

        // special case, replace single child
        if (oldchild->m_prev == oldchild)
            newchild->m_prev = newchild;
    } else
        newchild->m_prev->m_next = newchild;
    newchild->IncRef();
    
    oldchild->m_parent = NULL;
    oldchild->m_next = NULL;
    oldchild->m_prev = NULL;
    oldchild->DecRef();
}


Element *Element::ReplaceChild(Element *oldchild, Scm code) {
    Element *elm = GetElementFromObject(code);

    // if error with child, report error
    if (!elm)
        return NULL;

    // ensure elements are not added twice
    if (elm->GetParent() != NULL) {
        Error("element already has parent.");
        return NULL;
    }    
    
    ReplaceChild(oldchild, elm);
    return elm;
}

Scm Element::GetContents()
{
    return Scm_EOL;
}

void Element::FindBounding(float *top, float *bottom, 
                           float *left, float *right,
                           const TransformMatrix *matrix,
                           const Camera &camera)
{
    // loop through children of this element
    for (Element *elm=m_child; elm; elm=elm->m_next) {
        elm->FindBounding(top, bottom, left, right, matrix, camera);
    }
}

const TransformMatrix *Element::GetTransform(TransformMatrix *matrix,
                                             const Camera &camera)
{
    if (m_transformParent == NULL) {
        return &g_transformIdentity;
    } else {
        return m_transformParent->GetTransform(matrix, camera);
    }
}


void Element::Update()
{
    if (m_parent == NULL) 
        m_transformParent = NULL;
    else
        m_transformParent = m_parent->GetTransformParent();
}


Transform *Element::GetTransformParent()
{
    return m_transformParent;
}



} // namespace Summon