www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: AGP on July 13, 2009, 08:59:45 pm

Title: Draw distance seems to shrink every time I draw an Overlay
Post by: AGP on July 13, 2009, 08:59:45 pm
And the Overlay itself doesn't show. The first lines are how I initialized the Overlay, the second are in my collision(CollisionEvent) method.

Code: [Select]
explosionPlane = new Overlay(theWorld, buffer, "explosion2.gif");
explosionPlane.setVisibility(false);

Code: [Select]
explosionPlane.setSourceCoordinates((int)point.x-explosion.getWidth()/2, (int)point.y-explosion.getHeight()/2, (int)(point.x+explosion.getWidth()/2), (int)(point.y+explosion.getHeight()/2));
explosionPlane.setVisibility(true);
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: EgonOlsen on July 13, 2009, 10:25:00 pm
There is no code related to viewing distance in Overlay. What an Overlay actually is, is a wrapped Object3D with some magic added to it in the update-method. However, i'm not sure if you are using setSourceCoordinates correctly. It's for giving the Overlay new texture coordinates, not screen coordinates. If you want to do that, you have to use setNewCoordinates instead. If you are creating an overlay in the way that you do, it'll cover the whole screen. Maybe that is what causes the impression that it has something to do with draw distance!?
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: AGP on July 14, 2009, 03:19:59 am
Actually, I was calling setDepth, if that's what you mean. Sorry I copy it. Anyway, you were right but the result with setNewCoordinates is that I don't see anything.
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: EgonOlsen on July 14, 2009, 08:48:12 am
I'm not sure if an Overlay is actually what you want to use to render an explosion's bitmap...maybe a simple, bill boarded quad would be the better choice.
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: AGP on July 16, 2009, 12:25:59 am
I used a billboarded plane instead, and I wrote a quick GifTexture class that switches the Texture instance of the object when a next frame method is called. All the Texture instances are pre-initialized and added to the TextureManager, but the plane, most of the time, is rendered without any texture because I don't think jPCT updates the texture references on the fly. Is there an Object3D.update method I'm missing (I've even tried rebuild())? If not, how could I go about doing that (replacing the texture on the fly)?
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: EgonOlsen on July 16, 2009, 08:08:15 am
I don't think jPCT updates the texture references on the fly.
No, it actually does that. I don't know what's wrong here, but it shouldn't be the texture assignment. It's not the most efficient way though, but for drawing some explosions, it should be fine.
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: AGP on July 16, 2009, 10:04:37 pm
Yeah, I made it work after tinkering it. Now here's a question about transparency: what exactly does Object3D.setTransparency(100) do? I've been using it in a lot of different programs and objects to erase the black areas in a texture, but I just came across an example where it doesn't work (the area that's supposed to be displayed appears in black while the black areas to disappear). The odd thing about this perfectly conventional texture is that if I don't call setTransparency the entire object comes off as black. And it is being lit. So I guess that's two questions (what does setTransparency do and why is this perfectly conventional texture appear as black). :-)
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: EgonOlsen on July 16, 2009, 11:12:23 pm
There's a clear answer to this: It depends... ;D 100 is a pretty high value for transparency. If you are using a texture without an alpha channel of its own, jPCT will create one by setting all black (or almost black) areas to 100% transparent and all other parts to opaque. However, when setting the transparency value, it affects the whole texture so that even opaque parts become transparent while the black parts stay invisible. With a value of 100, the opaque parts are almost opaque even when using transparency and the black parts remain transparent.
If you load a texture with an alpha channel of it own, the theory is the same but you may have all kinds of transparency in the texture because the values are not just 0 and 255 but all values between 0 and 255 are possible.
I don't know about the other texture...maybe it has an alpha channel of its own. But that wouldn't explain the blackness, i think. Maybe you can send me that texture for a closer look?
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: AGP on July 17, 2009, 07:17:24 pm
I was hoping the answer would be that clear, hahah. Anyway, the texture was being exposed to light but no light was affecting it for some reason. I created a light just for the plane it solved it. Now I'm running into a very weird problem. I'm writing a starship fighting game and originally I tested it with a single enemy ship. I have since changed the single variable to an array of a class names Enemy which holds both the Object3D and handles the ship's behavior (processed in the game loop). It worked fine for a single ship. The odd thing is that now that I have an array of ships (initialized really early on in the constructor), some of the collision tests are still being called for index 0 only (as opposed to a loop testing all the ships) and I'm getting not a NullPointerException but an ArrayIndexOutOfBoundsException on collision(CollisionEvent) when I try to shoot at the ship (or when it's time for it to turn because it hit the sky).

On run():
Code: [Select]
      if (!enemies[0].turning)
enemies[0].tieGuide.checkForCollisionSpherical(enemies[0].translation, 800f);
      if (enemies[0].turning)
enemies[0].turnAround();
      else enemies[0].perform();
On collision(CollisionEvent):
Code: [Select]
if (!enemies[0].turning && e.getSource() == enemies[0].tieGuide && e.getTargets()[0]==worldSphere && System.currentTimeMillis() > enemies[0].lastTurn+1000)
      enemies[0].turnAround();
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: EgonOlsen on July 17, 2009, 07:25:50 pm
And you get this exception on the enemies-array or the one returned by getTargets()?
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: AGP on July 17, 2009, 07:33:18 pm
My lines are out of sync with the compiler's, but a println call on collision reveals my two-ship array to be of length 2 and getTargets() to be of length 1.
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: EgonOlsen on July 17, 2009, 07:41:47 pm
My lines are out of sync with the compiler's, but a println call on collision reveals my two-ship array to be of length 2 and getTargets() to be of length 1.
It highly unlikely that the line in your code doesn't match the line were the exception happens. Or in other words: If the exception says that it happened in line xxx of your code, you can be pretty damn sure that it did. So either you are looking in the wrong place or the code you execute isn't the one that you compile.
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: AGP on July 17, 2009, 08:21:57 pm
Dos this change your mind?

(http://www.agpgames.com/agpstuff/Compiler.jpg)
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: EgonOlsen on July 17, 2009, 09:12:20 pm
Not really. I've never seen such thing in over 10 years of Java development except when the code i was running wasn't the code i was seeing in the editor. Please do me a favor and add a

Code: [Select]
new Exception().printStackTrace();

in line 246, run the code and report the output.
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: AGP on July 17, 2009, 09:15:44 pm
I've seen it many times myself. It is the actual code, and there are sometimes ascii characters that the text area doesn't interpret as a line which the compiler does. If I remember correctly, the area needs 10 and 26 (break and new line). The compiler probably just interprets 10.
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: AGP on July 17, 2009, 09:18:32 pm
Here it is:

(http://www.agpgames.com/agpstuff/Compiler2.jpg)
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: EgonOlsen on July 17, 2009, 09:25:35 pm
Strange editor that is. It's pretty hard to debug that way. Have you considered using Eclipse instead?
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: EgonOlsen on July 17, 2009, 09:29:01 pm
Is it save to assume that the line number's delta is constant at least within a method? In that case, line 258 seems to cause the problem, but that line isn't visible in the screen shots. If that isn't save either, get an editor whose line numbers match the ones from the compiler.
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: AGP on July 17, 2009, 09:33:34 pm
In keeping with the Star Wars theme, you phrased it well, hahah. And no, I hate other people's editors. I wrote mine to be as unobtrusive as possible. Probably my old professors' faults for making us write code with simple editors (what was the name of that popular notepad-like one for Linux--nedit, maybe?).

How'd you get 258? And here it is (don't tell me it's a visibility thing): SimpleVector point = Interact2D.project3D2D(camera, buffer, tieCenter).

PS: I took it out (didn't need it anymore), recompiled, re-ran it, and got the same ArrayIndexOutOfBoundsException. Line 281 this time. So after your formula...?
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: EgonOlsen on July 17, 2009, 09:38:39 pm
I just subtracted 246 from 267, which is 21. I subtracted that from 279 and got 258. However, due to the added line 246, it should now be at 259...i forgot to add that one line too. However, maybe you don't have to use another editor for every day work, but at least for debugging things like this, its needed IMHO. Get Notepad++ for example. It's free. OR fix your own editor to count the lines correctly. You are making your life harder than it has to be.
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: AGP on July 17, 2009, 10:02:24 pm
I agree, but it's just that when I spend too much time working on my editor I start feeling like I should be using it instead. :-) And a month ago I tried setting up a project on Netbeans for an applet. 40 minutes into it I still couldn't get it working. And I could tell from all the tabs that I was going to get annoyed with it even if I could. Anyway, the entire laser-collision condition:

Code: [Select]
else if ((e.getSource() == laser1 || e.getSource() == laser2)) {
      for (int i = 0; i < enemies.length; i++) {//IS IT ANY OF THE ENEMY SHIPS?
if (e.getTargets()[i] == enemies[i].tieFighter && System.currentTimeMillis() > timeSinceDestruction+1500) {

      SimpleVector tieCenter = enemies[i].tieFighter.getTransformedCenter();
//       SimpleVector point = Interact2D.project3D2D(camera, buffer, tieCenter);
      iGotOne = true;

      explosionPlane.setVisibility(true);
      moveTo(explosionPlane, tieCenter);

      thePlayer.numberOfKills++;
      enemies[i].enabled = false;
      theWorld.removeObject(enemies[i].tieFighter);
      if (Math.random() > .75)
theForce.play();
      timeSinceDestruction = System.currentTimeMillis();


}
      }
}
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: EgonOlsen on July 17, 2009, 10:07:22 pm
Ok, then this part will most likely cause it:

Code: [Select]
e.getTargets()[i]

You are iterating over the enemies, but are assuming that the array of targets is at least as long as the one that stores the enemies, which is pretty unlikely.

If there's only one target, that should be something like

Code: [Select]
e.getTargets()[0]

instead. Or if its larger, you should iterate over it with a second variable, but not with i.
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: AGP on July 17, 2009, 10:11:04 pm
Jesus, I meant it to be 0. What an idiot I can be. Thanks a lot, pal.
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: AGP on July 17, 2009, 10:18:31 pm
I sometimes lack the ability (physically, really) to fine-comb my own code. Now here's a brand-new question (!): what's the more efficient way to draw an animation on a plane than the one I'm doing (replacing the Texture instances on the fly)?
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: EgonOlsen on July 17, 2009, 10:24:23 pm
Another solution is to stick all animation phases in one texture and use the PolygonManager and adjust the u/v coordinates. I'm doing this in Robombs for the explosions. It CAN be more efficient. But on compiled objects for example, it will be less efficient. Just stick with your approach. It should be doing fine.
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: AGP on July 18, 2009, 07:41:30 am
Cool, thank you. Here's a question about compiled objects: why do they use lightMul at 1.0 when the default lightMul is 10? Is there a reason for this decision (was it a decision or a necessity)? Because every time we choose to compile the objects (and I just ran into a performance issue that compile() solves nicely) we'll have to reconfigure all of our lights.
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: AGP on July 18, 2009, 07:52:34 am
And yet another question (you're a very patient man!): World.getSize() is returning 14, but a loop that calls getObject(index) is returning every single reference as null (and jPCT prints out "Can't retrieve object #" for each). How come?
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: paulscode on July 18, 2009, 01:56:15 pm
Not related to your current question, but about your editor's line-counting abilities.  I've had some experience writing editors before, so I thought I would add my two-cents' worth.

If I remember correctly, the area needs 10 and 26 (break and new line).
The ASCII values for newline are 13 (carriage return \r) and 10 (line feed \n).  Microsoft saves ASCII files with both a charrage return and a line feed \r\n everywhere you create a new line.  Macintosh uses only a carriage return \r, and Linux uses only a line feed \n.

So if the whole "carriage return, line feed" issue is the source of confusion, then to make your editor count the lines correctly, I would recommend splitting first on "\r\n", then on "\r", then on "\n".  If you handle all three cases in that order, your editor should count the same number of lines as the compiler does (unless the compiler is just stupid and interprets "\r\n" as two lines, in which case, you could just "dumb down" your editor to do the same).

The other problem I had with line-counting is word-wrap.  Just from the screenshots, I don't know if your editor does this or not.  If so, make sure your code is taking this into acount when counting the lines (since the compiler does not word-wrap, of course).
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: AGP on July 18, 2009, 06:22:30 pm
Yeah, I knew I didn't remember the Ascii perfectly. Thanks for your suggestion, I will do that.

Egon, the follow-up to my unanswered question: would it be possible to make a Object3D.compile(float lightMul)?
Title: Re: Draw distance seems to shrink every time I draw an Overlay
Post by: EgonOlsen on July 18, 2009, 11:17:01 pm
lightMul=1 for compiled objects can't be changed. It's how the OpenGL pipeline works. I'm setting it to 1 for all objects when using a compiled one to get consistent lighting between normal and compiled objects. The default pipeline does a multiplication for the light values which the compiled one can't do.
If you want to preserve another lightMul for uncompiled objects, you can reset the lightMul to any value after calling compile on all your objects. It's not possible to use this value on compiled ones though for the reasons mentioned above.

About that count-getObject()-thing: The count in World doesn't match the objects' ids. The id is an internal ID that each object carries. It has nothing do to with the world's size. In fact, i consider this method to be pretty pointless in most situations. If you need access to a World's objects, use getObjects() instead.