[Tutorial] Tracers

Posts 15 of 5 · Page 1 of 1
[Tutorial] Tracers
First:
Code:
    public void TracerLine() {
        try {
            GL11.glBlendFunc(770, 771);
      GL11.glLineWidth(3.0F);
      GL11.glDisable(2929 /*GL_DEPTH_TEST*/);
      GL11.glDepthMask(false);

            double size = 0.45;
            double ytSize = 0.35;
            GL11.glBegin(GL11.GL_LINES);
            GL11.glColor3f(0, 0, 255);
            for(int x = 0; x < ac.theWorld.playerEntities.size(); x ++) {
                Entity entity = (Entity) ac.theWorld.playerEntities.get(x);
                double X = entity.posX;
                double Y = entity.posY;
                double Z = entity.posZ;
                double mX = ac.thePlayer.posX;
                double mY = ac.thePlayer.posY;
                double mZ = ac.thePlayer.posZ;
                double dX = (mX - X);
                double dY = (mY - Y);
                double dZ = (mZ - Z);

                if(X != mX && Y != mY && Z != mZ) {        
                    GL11.glVertex3d(0, 0, 0);
                    GL11.glVertex3d((-dX + size) - 0.5, (ytSize - dY) + 1.0, (-dZ - size) + 0.5);
                }
            }

            GL11.glEnd();    
      GL11.glDepthMask(true);
      GL11.glEnable(2929 /*GL_DEPTH_TEST*/); 
        } catch (Exception e) {}
    }
Put it in RenderGlobal.java and call it under :
Code:
public void renderEntities(Vec3D vec3d, ICamera icamera, float f)

Now to explain the code:
Code:
    public void TracerLine() {
        try { // This attempts the code.
            GL11.glBlendFunc(770, 771); // I'm actually not sure what this is, it was in nametags so I took it
      GL11.glLineWidth(3.0F); // This sets the line width to 3 pixels thick
      GL11.glDisable(2929 /*GL_DEPTH_TEST*/); // Disables depth rendering, allowing it to show through walls
      GL11.glDepthMask(false); // Disables depth masking, allowing it to show through walls

            double size = 0.45; // This sets the box size to 0.45 on both sides
            double ytSize = 0.35; // This sets the height of the box to 0.35 on both sides
            GL11.glBegin(GL11.GL_LINES); // This begins OpenGL's drawing of lines
            GL11.glColor3f(0, 0, 255); // This sets the color of the OpenGL lines to blue (Red, Green, Blue);
            for(int x = 0; x < ac.theWorld.playerEntities.size(); x  ++) { // This loops through all PLAYER ENTITIES that are loaded
                Entity entity = (Entity)  ac.theWorld.playerEntities.get(x); // This set the variable 'entity' to  the following (Shortcut)
                double X = entity.posX; // Sets the variable 'X' to their posX (Shortcut)
                double Y = entity.posY; // Sets the variable 'Y' to their posY (Shortcut)
                double Z = entity.posZ; // Sets the variable 'Z' to their posZ (Shortcut)
                double mX = ac.thePlayer.posX; // Sets the variable 'mX' to your posX (Shortcut)
                double mY = ac.thePlayer.posY; // Sets the variable 'mY' to your posY (Shortcut)
                double mZ = ac.thePlayer.posZ; // Sets the variable 'mZ' to your posZ (Shortcut)
                double dX = (mX - X); // Sets the variable 'dX' to 'mX - X' (Shortcut)
                double dY = (mY - Y); // Sets the variable 'dY' to 'mY - Y' (Shortcut)
                double dZ = (mZ - Z); // Sets the variable 'dZ' to 'mZ - Z' (Shortcut)

                if(X != mX && Y != mY && Z != mZ) { // Checks if their not right on top of you
                    GL11.glVertex2d(0, 0); // Starts drawing the line on your cursor (Middle of the Screen)
                    GL11.glVertex3d((-dX + size) - 0.5, (ytSize - dY) +  1.0, (-dZ - size) + 0.5); // Draws the line to the other player
                }
            }

            GL11.glEnd(); // Ends the line
      GL11.glDepthMask(true); // Enables depth masking to not mess up other rendering entities
      GL11.glEnable(2929 /*GL_DEPTH_TEST*/);  // Enables depth rendering to not mess up other rendered entities
        } catch (Exception e) {} // If there is an error, it does what is inside of the {}, in which case is nothing.
    }

Screenshot:

http://img210.imageshack.us/img210/2...0317231617.png
Quote Originally Posted by EwwItsThomas View Post
First:
Code:
    public void TracerLine() {
        try {
            GL11.glBlendFunc(770, 771);
      GL11.glLineWidth(3.0F);
      GL11.glDisable(2929 /*GL_DEPTH_TEST*/);
      GL11.glDepthMask(false);

            double size = 0.45;
            double ytSize = 0.35;
            GL11.glBegin(GL11.GL_LINES);
            GL11.glColor3f(0, 0, 255);
            for(int x = 0; x < ac.theWorld.playerEntities.size(); x ++) {
                Entity entity = (Entity) ac.theWorld.playerEntities.get(x);
                double X = entity.posX;
                double Y = entity.posY;
                double Z = entity.posZ;
                double mX = ac.thePlayer.posX;
                double mY = ac.thePlayer.posY;
                double mZ = ac.thePlayer.posZ;
                double dX = (mX - X);
                double dY = (mY - Y);
                double dZ = (mZ - Z);

                if(X != mX && Y != mY && Z != mZ) {        
                    GL11.glVertex3d(0, 0, 0);
                    GL11.glVertex3d((-dX + size) - 0.5, (ytSize - dY) + 1.0, (-dZ - size) + 0.5);
                }
            }

            GL11.glEnd();    
      GL11.glDepthMask(true);
      GL11.glEnable(2929 /*GL_DEPTH_TEST*/); 
        } catch (Exception e) {}
    }
Put it in RenderGlobal.java and call it under :
Code:
public void renderEntities(Vec3D vec3d, ICamera icamera, float f)

Now to explain the code:
Code:
    public void TracerLine() {
        try { // This attempts the code.
            GL11.glBlendFunc(770, 771); // I'm actually not sure what this is, it was in nametags so I took it
      GL11.glLineWidth(3.0F); // This sets the line width to 3 pixels thick
      GL11.glDisable(2929 /*GL_DEPTH_TEST*/); // Disables depth rendering, allowing it to show through walls
      GL11.glDepthMask(false); // Disables depth masking, allowing it to show through walls

            double size = 0.45; // This sets the box size to 0.45 on both sides
            double ytSize = 0.35; // This sets the height of the box to 0.35 on both sides
            GL11.glBegin(GL11.GL_LINES); // This begins OpenGL's drawing of lines
            GL11.glColor3f(0, 0, 255); // This sets the color of the OpenGL lines to blue (Red, Green, Blue);
            for(int x = 0; x < ac.theWorld.playerEntities.size(); x  ++) { // This loops through all PLAYER ENTITIES that are loaded
                Entity entity = (Entity)  ac.theWorld.playerEntities.get(x); // This set the variable 'entity' to  the following (Shortcut)
                double X = entity.posX; // Sets the variable 'X' to their posX (Shortcut)
                double Y = entity.posY; // Sets the variable 'Y' to their posY (Shortcut)
                double Z = entity.posZ; // Sets the variable 'Z' to their posZ (Shortcut)
                double mX = ac.thePlayer.posX; // Sets the variable 'mX' to your posX (Shortcut)
                double mY = ac.thePlayer.posY; // Sets the variable 'mY' to your posY (Shortcut)
                double mZ = ac.thePlayer.posZ; // Sets the variable 'mZ' to your posZ (Shortcut)
                double dX = (mX - X); // Sets the variable 'dX' to 'mX - X' (Shortcut)
                double dY = (mY - Y); // Sets the variable 'dY' to 'mY - Y' (Shortcut)
                double dZ = (mZ - Z); // Sets the variable 'dZ' to 'mZ - Z' (Shortcut)

                if(X != mX && Y != mY && Z != mZ) { // Checks if their not right on top of you
                    GL11.glVertex2d(0, 0); // Starts drawing the line on your cursor (Middle of the Screen)
                    GL11.glVertex3d((-dX + size) - 0.5, (ytSize - dY) +  1.0, (-dZ - size) + 0.5); // Draws the line to the other player
                }
            }

            GL11.glEnd(); // Ends the line
      GL11.glDepthMask(true); // Enables depth masking to not mess up other rendering entities
      GL11.glEnable(2929 /*GL_DEPTH_TEST*/);  // Enables depth rendering to not mess up other rendered entities
        } catch (Exception e) {} // If there is an error, it does what is inside of the {}, in which case is nothing.
    }

Screenshot:

http://img210.imageshack.us/img210/2...0317231617.png
Nice tutorial but.... i had a problem at first line ive been trying most things and nothing work.It says:
Multiple errors at this line:
- Syntax error on token "void", @ expected
- Syntax error, insert "EnumBody" to complete block statement
- Syntax Error, instert "enum identifier" to complete EnumHeaderName

Would appreciate help
Quote Originally Posted by xMystic View Post
Nice tutorial but.... i had a problem at first line ive been trying most things and nothing work.It says:
Multiple errors at this line:
- Syntax error on token "void", @ expected
- Syntax error, insert "EnumBody" to complete block statement
- Syntax Error, instert "enum identifier" to complete EnumHeaderName

Would appreciate help
Remove the public blahblahblah line (the first line of the code you pasted) and the last line of the code you pasted (})
Please learn to use better smaller methords and not skid copy paste.
This sir is spoonfeeding the skids ^^
Posts 15 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?