PDA

View Full Version : Tracers



Corey209
12-27-2011, 01:52 AM
I'm trying to get tracers(Lines) to go from my crosshair(middle of the screen) to the other entities ingame. This is what I've gotten so far and I can't seem to figure it out.



if(GuiIngame.tracer)
{
List players = mc.theWorld.getLoadedEntityList();
for (int k1 = 0; k1 < players.size();k1++)
{
EntityPlayer p;
if (players.get(k1) instanceof EntityPlayer)
p = (EntityPlayer) players.get(k1);
else
continue;
if (p!=mc.thePlayer &amp;&amp; p!=null)
{
double posX = p.posX - mc.thePlayer.posX;
double posY = p.posY - mc.thePlayer.posY;
double posZ = p.posZ - mc.thePlayer.posZ;
double xc = posX / posZ;
double yc = posY / posZ;
//double mx = mc.thePlayer.posX / mc.thePlayer.posZ;
//double my = mc.thePlayer.posY / mc.thePlayer.posZ;
//xc = xc-mx;
//yc = yc-my;
GL11.glBlendFunc(770, 771);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(0.0F, 1.0F, 1.0F, 1.0F);
GL11.glLineWidth(2);
GL11.glBegin(GL11.GL_LINES);
GL11.glVertex2d(0D, 0D);
GL11.glVertex2d(xc, yc);
GL11.glEnd();
GL11.glDisable(GL11.GL_BLEND);
}
else
continue;
}
}

carsten neumann
12-27-2011, 10:36 AM
I assume p.pos{X,Y,Z} and mc.thePlayer.pos{X,Y,Z} are in world coordinates? In that case you need to transform them with the modelview and projection matrices to obtain clip coordinates, then apply perspective division (gives you normalized device coords, NDC) and then apply the viewport transform to get window coordintes.
When you have window coordinates you can set a orthographic projection (glOrtho(0,0, width, height, -1, 1)). Then draw a line from the center of the screen (width/2, height/2) to the computed window coords.
gluProject (http://www.opengl.org/sdk/docs/man/xhtml/gluProject.xml) can make it easier to get window coords. GLU is often available in languages other than C as well or there may be libs that provide the same functionality.