Author Topic: needing some concept help~!  (Read 6550 times)

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
needing some concept help~!
« on: June 07, 2006, 05:49:20 pm »
Hihi~! I am trying to make a 2d/3d game like Castlevania: Symphony of the Night and Strider 2.

For my first approach on such a task, I tried to simply load the textures onto JPCT and blit the sprite over a drawn world. However those plans were quickly placed onto a halt because I do not know how to flip an image horizontally as well as scaling the sprite. Blitting also gave the sprites too much screen priority which was not favorable. A possible solution for flipping images was to load the sprites onto the TextureManager twice; one for facing left and one for right. That however does not seem like a good approach at all...

So my second attempt was to make a plane and have that moving about in the world. Object3D has transparencies and I can always use backculling on the plane, so that was fine. Everything went well until I noticed that both renderers applied the sprite onto the plane differently. One of them tiled the image onto the plane while the other just scaled. I also do not know how to place the sprite at a certain point on a plane. (some sprites will need some sort of offset to get the images aligned so that the animation looks nice)

Does anyone have any better solutions? Thank you in advance~!!!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: needing some concept help~!
« Reply #1 on: June 07, 2006, 06:49:18 pm »
Quote from: "Mizuki Takase"
Everything went well until I noticed that both renderers applied the sprite onto the plane differently. One of them tiled the image onto the plane while the other just scaled.
I don't understand what you are talking about here. Which renderer does what (maybe you've some screen shots to illustrate this) and what is the behaviour that you want to have?

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
needing some concept help~!
« Reply #2 on: June 07, 2006, 07:40:07 pm »
Major apologies for not having those screencaptures~! I also wanted to say thanks for the fast response~!

First off, here is a picture of the plane with no texture....


Then, here is a picture of the plane with the software renderer...


Here is the picture of the plane with the OpenGL renderer


Lastly, this is what I am trying to do~! As you can see, Strider 2 has 2d spirtes all over a 3d world... Its an interesting sight to see~!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
needing some concept help~!
« Reply #3 on: June 07, 2006, 07:47:24 pm »
What the OpenGL renderer does seems to be the correct behaviour. The software renderer may require a call to build() here and there more than the OpenGL renderer. It's mandatory, but the OpenGL renderer may work without it, so...please try to call build() on the plane after assigning the texture to see if the software renderer behaves correct after that.

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
needing some concept help~!
« Reply #4 on: June 07, 2006, 08:12:24 pm »
If only I had your brains~~! The build() command works. I had forgotten to build() after assigning the texture. So here is another question~! I would like to have some control over the texture in such as way that I have can have multiple frames to animate. Each frame has a center axis in which it is okay to perform rotations on. I wanted to know how can I get that aligned with the Object3D's getCenter(). Thanks again~!!!

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
needing some concept help~!
« Reply #5 on: June 08, 2006, 09:34:49 am »
Ha ha ha~! I feel dumb now... I can now shift the textures by implementing my own ITextureEffect... It simply shifted the image by whatever x and y offset I tell it to.. Thanks again Egon Olsen for all of your help~! I really really want to make something with the engine despite my stupidity... I hope that something good happens soon!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
needing some concept help~!
« Reply #6 on: June 08, 2006, 05:14:53 pm »
Using an ITextureEffect at startup to shift the textures in the correct position is fine, but using it at runtime is questionable. In that case, you may consider to set new texture coordinates with the PolygonManager instead, which can be obtained from any Object3D and allows to modify the texture coordinates by setting a new TextureInfo.

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
needing some concept help~!
« Reply #7 on: June 09, 2006, 07:24:17 am »
Thanks a lot Egon Olsen again! I am using the ITextureEffects on load just as you said and its great! As usual, another issue came up... From the JPCT api, I know that Object3D.invert() is a very costly function but I think that I must have to use it.

As a recap, I basically wanted to use JPCT to make a sidescroller. I was planning to represent the player and enemies as a single polygon textured with a sprite and have them exist in a 3D world.

The problem with the idea is when I wanted to display a horizontally flipped image. I thought that it would have been easier to rotate the plane horizontally while having culling disabled. That resulted in the lighting being different on both sides. I then tried to use Object3D.invert, the end result is good however, for an extremely short period of time, the lighting will be bad.

Since I know that I suck at explaining things, I decided to upload the project. It can be downloaded at http://www.cs.uno.edu/~tvle/spritetest.zip for a very short time. When you first start the SpriteTest, you will have to move either all the right so that you can see the player. To experience the problem firsthand, after you can see the player, simply just press left and right a couple of times.... Oh, just to make sure, you will need Java 1.5 for it since I used generics all over...

A better solution is always appreciated~!!! Lastly, so sorry that the project is a modified car example from the JPCT... I suck at programming...

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
needing some concept help~!
« Reply #8 on: June 09, 2006, 11:32:15 am »
Oh dear~!! After making my previous post, I read your comments and I felt that your solution for shifting and possibly flipping horizontally an image is awesome. I then took a look at the Object3D.getPolygonManager() and I did see the getTextureUV(int polyID, int vertexNumber) inside it...

I do not know why, but its kinda scary... Because I am using Primitives.getPlane(int quads, float scale), I know that I have two triangles to deal with therefore making polyID an integer between 0 and 1... I also know that I can get three SimpleVectors from it by specificing the vertexNumber in getTextureUV... The part that I find to be scary is that I guess that I do not understand how can I get all of that information to flip a texture horizontally based on the Object3D.getCenter().

For now, I am not worried about the shifting of textures, and am placing priority on flipping images horizontally...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
needing some concept help~!
« Reply #9 on: June 09, 2006, 06:06:15 pm »
I'm not sure what to are trying to do with getCenter() in that case...if i understand you correctly, what you want is, that the sprite faces right when moving to the right and left when moving to the left? If so, the PolygonManager makes this very easy. The texture coords for such a quad/plane are for example (i'm not sure about the actual mapping without looking at it, but the principle stays the same):

(0,0) for the upper left corner,
(1,0) for the upper right,
(0,1) for the lower left and
(1,1) for the lower right

All you have to do now is to assign new coordinates for each polygon by using the methods in the PolygonManager, i.e. to do a flip, just do:

(1,0) for the upper left corner,
(0,0) for the upper right,
(1,1) for the lower left and
(0,1) for the lower right

and you are done. As said, i'm not sure if the upper left corner is really at (0,0) like in this example. Could very well be (1,1) instead, but that doesn't really matter and you can use a little bit of try and error to find out (or use the getTextureUV()-call, that you've mentioned).