Author Topic: Problems with pixels~!!  (Read 6394 times)

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
Problems with pixels~!!
« on: July 27, 2006, 02:12:55 am »
Oh my goddess~!! I have been sooo out of programming, and eventhough its been a while since I last worked on a project that uses JPCT, I still have not given up~!!! Anyway, I am going to have a problem with pixels! If you can remember my project, (if not, then go here: http://www.cs.uno.edu/~tvle/hotaru/New%20Text%20Document.htm) I wanted to make 2D sprites that exist in a 3D world and have them do whatever...

My problem is that in 2D games, if I wanted a player to jump, I would say something like move a certain number of pixels up and then after a certain amount of time, I would say go down until the player touched the floor. I wanted to know how I can translate the player by an amount of pixels of the player.

Even if I got tired and decided not to bother with accuracy, I still need to be able to do something like that because I need to do collision boxes~!! Again, the boxes would need to be based on some sort of specified size while using the player's sprite size as a reference. What I mean is that I want the collision box to be a certain amount of pixels based on the pixel size of the player. I hope that I do not come off as confusing!! Its like... I do not want to use Interact2D because sometimes the camera may pan or zoom thus messing up the size of collision boxes. My player is based on a 1 x 1 polygon and the textures are 256 x 256 size.

For anyone who dares to try out the URL, you will need Java 1.5 Runtime. up, down, left, and right works, Z = punch, X = kick, Z+X = float upwards, w = wireframe. Thanks in advance~!!!


Another question as well... I have been looking at a source code for Continuous Level Of Detail terrains and also Clothes Flowing algorithms... Just incase, clods are nice to have because you can have a lot of small maps that blend together seamlessly like in Grand Theft Auto or Oblivion. They can also appear lower in detail if you are far away from the target. The clothes algorithm, I think that many people can get the idea of it easily without an explanation... I wanted to know if JPCT would give me enough power to implement such features.. If so, I would be really happy!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Problems with pixels~!!
« Reply #1 on: July 27, 2006, 05:08:25 pm »
If i understand you correctly, you want to get the size of the character on screen, right? If so, maybe this will work for you: Get the corners of your 1*1-plane in world space by using the PolygonManager (upper left and lower left should be sufficient as the plane is parallel to the screen) and feed those into the project3D2D-method in Interact2D. That should give you the screen coords for these vertices. I hope this is, what you have in mind.

About the clod...a real clod should be doable somehow but the affords needed to do it will most likely kill its benefits. r.a.f.t once did something like this for Karga...maybe he can help here. Clothing simulation should be possible as it is possible to get access to the raw vertex data of a mesh by using an IVertexController (like this deformed plane shows it: http://www.jpct.net/pics/vertexcontrol.jpg).

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
Problems with pixels~!!
« Reply #2 on: July 27, 2006, 05:47:32 pm »
I suck at explaining things but maybe you did answer the question and I am too dumb to understand it (for now).

Say for instance, I am trying to create some box-like collision boxes. The box is specified by two coordinates; one for the upper left corner and the other for the lower right corner. The problem is that I textured the 1 by 1 polygon in such a way that the texture is centered in the middle of the polygon. Its kinda like the polygon has its own axis for the sprite. I want to somehow convert a coordinate into a point that will be somewhere inside a polygon I guess (?)

Eventually, I also wanted to make the player move a specificed amount. The problem is that the player has to move in accordance to that weird sprite coordinate system and not by a SimpleVector alone.

If I am still not quite explaining things good enough, you can always tell me so~! It seems that every post that I have made so far has to have pictures... Pictures are good~~~

Quote
Clothing simulation should be possible as it is possible to get access to the raw vertex data of a mesh by using an IVertexController (like this deformed plane shows it: http://www.jpct.net/pics/vertexcontrol.jpg).

Oh my goddess~! How did you do that? I would love to try to get started with clothing simulation~!! Too bad that I am not at a place to be game programming...  :cry:

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Problems with pixels~!!
« Reply #3 on: July 27, 2006, 05:53:52 pm »
Yes, maybe a picture illustrating the problem would help. I'm not sure if i was talking about your problem or about the exact opposite.

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
Problems with pixels~!!
« Reply #4 on: July 27, 2006, 06:22:09 pm »
Before JPCT, I used to attempt making 2D side scrollers. So maybe my problem is that I am still thinking too much 2D...



Anyway! This picture is an example of the textured polygon.. The sprite has a transparent background of purple, and it has been shifted so that the sprite is slightly above the green dot (kinda hard to see, but its a dot between the heels) The white background also transparent as well since there is no color data there.

The important thing about the picture is the green little dot because defines the coordinate (0,0) inside this particular polygon plane. I can specify collision boxes (shown in blue) by using that green dot, and say something like... upper left corner at (blah,blah) and lower right corner at (blah, blah)... The green dot is also important for moving because when I would want the player to move in a 2D side scroller, I would say something like... move whatever pixels to whatever direction.


The problem is trying to convert the inner coordinate system to the world coordinate system. So in this picture, if I wanted the player to move 3 x units to the right, the player has to move 3 green dots to the right. I hope that helps~!!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Problems with pixels~!!
« Reply #5 on: July 27, 2006, 07:28:49 pm »
Ok, at first you have to get the screen coordinate of that green dot, right? In your example pic, the green dot seems to be the (geometrical) center of the plane, so a call to Interact2D.projectCenter3D2D(...) should give you that coordinate. If it's not the center of the plane, determine where it is then on the plane (by using some linear math or by try and error...) and use Interact2D.project3D2D(...) instead.
Anyway...for your movement, you have to transform the 2D sprite coordinate system back into world space. I haven't tested, if this method works, but it may:

1.) Get the z-coordinate of the plane that is used to display the sprite in camera space. This is the "depth" of the plane, which basically is the length of the vector between the camera and the plane, i.e. (depth=plane.getTransformedCenter().calcSub(camera.getPosition).length()).

2.) Feed that into Interact2D.reproject2D3D(...,newX,newY, depth), where newX and -Y are the coordinates of the target point in 2D. The result is the coordinate of the target point in 3D and in camera space.

3.) Convert that point from camera space back into world space by doing something like this:
Code: [Select]
 
      SimpleVector p3d=<your point in camera space>;
      SimpleVector pos=camera.getPosition();
      Matrix m=camera.getBack().invert3x3();
      p3d.calcSub(pos).matMul(m);
      p3d.add(pos);


p3d should now contain the new target coordinates in world space for your sprite, so just translate it by the vector calculated by p3d=p3d.calcSub(plane.getTransformedCenter()).

That should do the trick. Any other 2D-3D-transformation should work similar to this.

Disclaimer: I haven't tested this...:wink:

But why do you actually want to think in pixels when doing this? Why isn't the current kind of movement based on the SimpleVector alone sufficient?

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
Problems with pixels~!!
« Reply #6 on: July 27, 2006, 08:55:40 pm »
As usual, you always save the day~! It sounds like a good idea and I will try it out!!

Quote
But why do you actually want to think in pixels when doing this? Why isn't the current kind of movement based on the SimpleVector alone sufficient?


Since "I suck" probably does not make a good explanation, it is because I used to do characters for a fighting game engine called M.U.G.E.N. The engine is based on finite state machines. Since the engine died out (the author seems to have fallen off the face of the virtual world (Hah! And scientists said that the world is not flat.... :wink: ) ), I wanted to try to write something that is similar to the engine so that it will be easy to port over some data without too much editting. Anyway, to make the story short, most of the states involve the location and movement of pixels!!

I am really enjoying JPCT a lot...

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Problems with pixels~!!
« Reply #7 on: August 08, 2006, 03:32:43 pm »
hey, it's a nice applet Mizuki, the player's movements are so smooth :)

Quote from: "EgonOlsen"
About the clod...a real clod should be doable somehow but the affords needed to do it will most likely kill its benefits. r.a.f.t once did something like this for Karga...maybe he can help here. Clothing simulation should be possible as it is possible to get access to the raw vertex data of a mesh by using an IVertexController (like this deformed plane shows it: http://www.jpct.net/pics/vertexcontrol.jpg).


i'm afraid what i did wasnt actually a cloth simulation. i mean i never used IVertexController for that purpose. i just seperated some parts of the body (like hair) and recorded all animations of body for also those seperated parts. then  in karga added the part as a child to body to move it with body and applied the same animation to that part. currently all mesh based avatar variations (only hair indeed, it sounds cool if i say so ;)) use this technique

Code: [Select]
r a f t