Jump to content
Eternal Lands Official Forums
Cicero

Speeding Up The Cursor Changes

Recommended Posts

Here's an optimized version. ;)

void save_scene_matrix()
{
glGetFloatv(GL_MODELVIEW_MATRIX, model);
glGetFloatv(GL_PROJECTION_MATRIX, proj);
glGetIntegerv(GL_VIEWPORT, viewport);
viewport[2]/=2;
viewport[3]/=2;
}

static void
project_ortho(GLfloat ox, GLfloat oy, GLfloat oz, GLfloat * wx, GLfloat * wy)
{
GLfloat tmp[3];

// apply modelview matrix
tmp[0] = model[0*4+0] * ox + model[1*4+0] * oy + model[2*4+0] * oz + model[3*4+0];
tmp[1] = model[0*4+1] * ox + model[1*4+1] * oy + model[2*4+1] * oz + model[3*4+1];
tmp[2] = model[0*4+2] * ox + model[1*4+2] * oy + model[2*4+2] * oz + model[3*4+2];

// apply projection matrix
ox = proj[0*4+0] * tmp[0] + proj[3*4+0];
oy = proj[1*4+1] * tmp[1] + proj[3*4+1];
oz = proj[2*4+2] * tmp[2] + proj[3*4+2];
    
 // viewport
*wx = viewport[0] + (1 + ox) * viewport[2];
*wy = viewport[1] + (1 + oy) * viewport[3];
}

int mouse_in_sphere(float x, float y, float z, float radius)
{
GLfloat  winx, winy;
int m_y = window_height - mouse_y;

project_ortho(x, y, z, &winx, &winy);

radius = proj[0*4+0]*radius+proj[3*4+0];
radius = (1.0+radius)*viewport[2];

return (mouse_x >= winx - radius  &&  mouse_x <= winx + radius  &&
 m_y     >= winy - radius  &&  m_y     <= winy + radius);
}

Share this post


Link to post
Share on other sites

I added a little more optimization to it, and I'm going to add it when I add the preliminary cal3d stuff.

 

In the meantime, if someone can figure out how to get an x,y,z and radius from actors, that would be great :)

Share this post


Link to post
Share on other sites

updated the berlion patch with umrions optimizations (coudn't test...cvs got broken for me GL_POINT_SPRITE_NV and GL_COORD_REPLACE_NV symbols not found)

Share this post


Link to post
Share on other sites

Add these in particles.c:

#define GL_POINT_SPRITE_NV                0x8861
#define GL_COORD_REPLACE_NV               0x8862

Share this post


Link to post
Share on other sites
Add these in particles.c:

#define GL_POINT_SPRITE_NV                0x8861
#define GL_COORD_REPLACE_NV               0x8862

You should never have to add any defines for GL_ items or your code may not compile or run on all the different systems. Extra coding may be needed to make sure things dont fail horribly on different machines if something like this is added.

Share this post


Link to post
Share on other sites
Add these in particles.c:

#define GL_POINT_SPRITE_NV                0x8861
#define GL_COORD_REPLACE_NV               0x8862

You should never have to add any defines for GL_ items or your code may not compile or run on all the different systems. Extra coding may be needed to make sure things dont fail horribly on different machines if something like this is added.

That was just for waldi, so that he could compile right away. For the code on CVS, I'd handle this differently.

 

tested...looks like it works :)

 

<offtopic>

um...i dropped a bag and collected it, but the animation was missing :(

</offtopic>

Point sprites or not? What happens if you switch to the other?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×