Trying to implement effect of lazer shooting using 2D sprite in OpenGl with gluOrtho2D(0, width, height, 0).
What i want to have:
draw wide texture (128x26) between points A and B within 1 sec,
the coordinates of the points A and B are changed during this seccond. The texture must be dynamically scaled by weight(depends on the distance between A and B), but height must be constant(in my case 16 pixels)
The main purpose is to keep algorithm as simple as possible:
for example i want to avoid to use glRotatef function, because i have to calculate angle between A and B within game loop. I believe that exist some simple resolution of my problem. What i want is to draw wide texture between two points.
My last approach is following:
x, y - coordinate of point A
xt, yt - coordinate of point B
h - desired texture height
def draw_tex_inRect((x, y), (xt, yt), h, tex): glBindTexture(GL_TEXTURE_2D, tex) # Send four vertices to draw a quad glBegin(GL_QUADS) glTexCoord2f(0, 0); glVertex2f(x - h/2, y - h/2) glTexCoord2f(1, 0); glVertex2f(xt + h/2, yt - h/2) glTexCoord2f(1, 1); glVertex2f(xt + h/2, yt + h/2) glTexCoord2f(0, 1); glVertex2f(x - h/2, y + h/2) glEnd()
But disadvantage of this method is: when angle between A and B is aimed to 90 or 270 then texture height is aimed to 0. This problem is illustrated on the picture below
Good variant:
http://i47.tinypic.com/1z7w1z.jpg
As u may see here angle is aimed to 0
Bad variant:
http://i46.tinypic.com/21cwmb.jpg
As u may see here angle is aimed to 90(270), and that is why texture height is decreasing(effect that i want to avoid)
def resize(width, height): glViewport(0,0,width, height) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluOrtho2D(0, width, height, 0) glDisable(GL_DEPTH_TEST) glMatrixMode(GL_MODELVIEW) glLoadIdentity()
Maybe someone have any idea how to implement this correctly?
Many thanks in advance
[Edited by - diverlin on July 6, 2010 12:53:54 PM]