Author Topic: Scaling on different devices  (Read 2021 times)

Offline rushtone

  • byte
  • *
  • Posts: 18
    • View Profile
Scaling on different devices
« on: December 18, 2012, 07:10:42 pm »
Hello everybody,

im new to jpct and also new in game developing as well.
but at least i have a very good java knowledge so i thought i give it a try with a 3d based game.
And actually its going on pretty well.

First off i wanna thank egon for this awesome library.

sorry for my bad english, its not my native language.

so lets go ahead to my questions.
1. is there an easy way to check if an object is visible by the camera?
or do i have to check that by my own?
for example with interact2d3d methods?

2. when i put my game to another device,
will the game look the same? or do i have to take care of scaling objects and camera positioning depending on aspect ratio and so on?

sorry if these questions are kind of dumb in a way.
i would test it, but i do not own a second android device.. :/

oh and once in a while (about each minute) my game is a little bit sluggish.. it seems to freez for a few ms..
i use pools for nearly everything to avoid garbage collection.
is this freezing normal in games? or can i get rid of it?
actualy the only points where the object allocation tracker notifies of allocations is inside the collision checks in the jpct lib.
maybe its my gameloop. i dont know. maybe someone can give me some advices.

thank you guys really much.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Scaling on different devices
« Reply #1 on: December 18, 2012, 08:37:49 pm »
  • One question is: Why would you want to? And another question is: What does "visible" actually mean? That it lies in the view frustum? That it's not hidden behind other objects?
  • jPCT-AE will adjust the vertical FOV to maintain the horizontal FOV. That means that the part of the world that you see from left to right doesn't change, but according to the aspect ratio of the screen, the visible range in vertical direction might change and that will have an influence on objects' size. However, displays don't differ that much that this will become an issue in most cases.
  • You can get rid of it by using a later Android version is possible (everything 4+ has improved GC) or creating less objects. However, some objects have to be created and some creations can't be controlled by the app (like touch events). Collision detection has to create a small amount of objects in each iteration, but it usually isn't a problem. You can try the latest version (released today), which reduces object creation in collision detection in some cases. Maybe it helps. Also keep in mind that using enhanced for loops or auto-boxing/unboxing can create a lot of implicit objects, so try to avoid using them.

Offline Bryce Thorup

  • byte
  • *
  • Posts: 3
    • View Profile
    • brycethorup.com
Re: Scaling on different devices
« Reply #2 on: December 18, 2012, 08:58:22 pm »
One way to test how the FOV changes is by allowing your app to rotate. Since the live wallpapers we have made required the possibility of landscape or portrait layout, I had to write code to handle what to  do in each instance, and also to read the screen dimensions to determine the aspect ratio. It took me a bit to get the hang of how FOV changes work, but it is manageable.
Tutorials, portfolio: http://brycethorup.com
Apps I have helped produce: http://apps.thor-media.net
The people I work with: http://thor-media.net

Offline rushtone

  • byte
  • *
  • Posts: 18
    • View Profile
Re: Scaling on different devices
« Reply #3 on: December 18, 2012, 09:20:40 pm »
thank you very much for your detailed answer. :)
1. i want to check visibility of objects visible in the frustum. iam developing a 3d based 2d game.
when i fire a bullet i wanna detach it from world an recycle it in my pool as soon as it lefts the outer bounds of my scene.
right now i use max y and x values for this.
but because of the spheric view the x coords dont match the screen bounds on the max y coords. i hope you get what i mean..
the camera is not straight top down..
i possibly could use interact2d3d methods to get the world coords with 0/0 and viewport width/height to get the proper world coords to check against to determine if an object left the camera sight.. didnt tryed yet.

2. well that sounds good. sounds like its already what i wanted. that also means if i have build my game around an fixed x/y world point. this point will stay the same in any ratio?
for example if in my scene on my phone the max y value is 10 then it is on any other phone the same?

3. i think each min is not that bad.
is there no way to provide a pool or a parameter like gettranslation(simplevector) for the collisions?

i have about 50 primites moving as background objects.. maybe there is another way to simulate movement of a vehicle without creating primitives that move in a direction to simulate that..?
i will try the new released version.
i have android 4 on my phone so i dont think this is the issue.
and i only used normal for loops on android.
i thank you very much.
//edit:
another question which come to my mind is..
does world.getobjects() creates an new enumeration object each time called or is it cached somehow? than i do not need to use my own arraylist to cycle through all my objects. i could use that one.. but i didnt want to create new objects without need.
« Last Edit: December 18, 2012, 09:30:31 pm by rushtone »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Scaling on different devices
« Reply #4 on: December 18, 2012, 09:41:10 pm »
  • jPCT-AE has a method Object3D.wasVisible(). This was broken in former releases but should work again in the latest release. With that, you can determine if an object was visible in the last frame. IMHO, this should be sufficient in this case. You'll put your objects back into the pool with one frame delay, but that shouldn't matter.
  • I'm not sure if i got the question...?
  • I really don't think that it's worth it unless you are doing a lot of collision checks which actually indicates that your problem is somewhere else...50 objects to simulate a vehicle seem a bit too much for me. Why do you need so many of them?
  • Yes, world.getObjects() creates a new enumeration each time.

Offline rushtone

  • byte
  • *
  • Posts: 18
    • View Profile
Re: Scaling on different devices
« Reply #5 on: December 18, 2012, 09:57:42 pm »
1. awesome. exactly what i was lookin for.
2. if i spawn enemys on x=10 y=10 world coords. will it be the same point on the screen on any device? or could it be that this position is out of the frustum in smaler devices. i have fix points for my game where for example x=-15 to x=15 and y=-15 and y=15 are my max values.
3. 50 objects to simulate movement.
its a space invader clone.. the 50 objects in the background represent stars. i move them in y direction to simulate the spaceship is moving.
so the background move and not the ship. is there a better way?
4. thank you for clarifiying.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Scaling on different devices
« Reply #6 on: December 18, 2012, 10:06:14 pm »
No, it won't be the same point on the screen when using different aspect ratios. But depending on the scene's layout, this might not matter unless your coordinates are very close to the upper or lower edge. Aspect ratio on current devices isn't that much different.

Ok, 50 objects to simulate stars...but why do they have to trigger collision checks?

Offline rushtone

  • byte
  • *
  • Posts: 18
    • View Profile
Re: Scaling on different devices
« Reply #7 on: December 18, 2012, 10:27:12 pm »
on same aspect rations with different sizes they are on the same point on screen? i think so, and i think it makes sense.. just to get sure i ask.
(never had the need to care of those things yet)

no they dont trigger collisions.. you misunderstood something.
i just asked for the collision cache to have absolutely no allocations beside the touch events.. ;)
but maybe i am a bit to enthusiastic with avoiding allocations in general.

i thank you for answering all my questions.
you really helped me.

thank you. :)
« Last Edit: December 18, 2012, 10:30:13 pm by rushtone »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Scaling on different devices
« Reply #8 on: December 19, 2012, 07:05:55 am »
on same aspect rations with different sizes they are on the same point on screen?
Yes.

but maybe i am a bit to enthusiastic with avoiding allocations in general.
Maybe... ;)

Offline rushtone

  • byte
  • *
  • Posts: 18
    • View Profile
Re: Scaling on different devices
« Reply #9 on: December 19, 2012, 07:13:24 pm »
Hi there,
its me again.. :)

I thought after you helped so nicely, i could ask one more question.
I wonder how i could get the coords in world space from a touch event.

I already played around with Interact2D.reproject() and Interact2D.reprojectWS()
Methods, but i do something wrong i guess.
The data i get in return doesnt match the data my object has..

for example if i touch my upper left corner this would return x=0 y=0 screen coords..
if i would want that point in worldspace visible by the camera at z location 20 how should i do this?

i tried like this:


Code: [Select]
//camera set up in init method
//set camera a little bit off axis
camera.setFOV(67);
camera.setOrientation(new SimpleVector(0,0,1), new SimpleVector(0,-1,0));
camera.setPosition(0, 0, -30);
.
.
.
//onTouchEvent..
// x,y comes from the touchevent (imagine 0/0)
SimpleVector position = Interact2D.reproject2D3D(camera, fb, x, y).normalize();
position.scalarMul(20);

where is my mistake?

When i touch on my Object, output is this:
Touch: (-7.165911,-7.2304683,17.2154)
Object: (-19.719666,-20.244387,19.565144)

Do i have to take the changed camera orientation into this calculation some how?

P.s. Egon, the Method wasVisible() now actually works like a charm.
« Last Edit: December 19, 2012, 07:17:28 pm by rushtone »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Scaling on different devices
« Reply #10 on: December 20, 2012, 08:08:51 am »
No, it won't work that way. What you want to use is the method that takes the z-value in addition to x and y.
Unfortunately, there's no variant of reproject2D3DWS that supports this. However, you can do something like this:

Code: [Select]
SimpleVector ray = reproject2D3D(camera, buffer, x, y, <your depth (20?)>, <vectorToFill>);
ray.matMul(camera.backMatrix.invert3x3(<matrixToFill>));
return ray;

What you did (except for not using the world space methods) is to cast a ray through the point (x3d, y3d, 1) and taking the coordinate at a length of 20. That's not the same thing (as you have noticed already....).

Offline rushtone

  • byte
  • *
  • Posts: 18
    • View Profile
Re: Scaling on different devices
« Reply #11 on: December 20, 2012, 06:19:14 pm »
ahh ok i see.. i was thinking it the same like a translation.. i get a direction vector. multiplying it with the distance and it should be the point where i projected my ray to. im still a bit confused i must admit.

egon as i saw you are able to speak german on other forums.. you are properply a german?
is english the desired language here or can i talk in german with you? might be easier.. at least for me.. ;)

what i tried with my attempt above was to figure out where my visible bounds are.
i wanna spawn enemys just a little distance outside the visible area.
since i move my ships equally on z and y axis..
i could take the value of the screen height divided by 2 as this z parameter.
or what kind of z does this method you suggested is expecting? z of the world coords i guess?
if i could use the half height of the screen size. im fine i think. couldnt test it yet..
my wife doesnt want me to go onto the pc today.. ;)

im honest this is my first 3d project. i guess my questions are totaly newbish. so im sorry if that is the case. i try to learn as much as i can.
« Last Edit: December 20, 2012, 06:24:34 pm by rushtone »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: Scaling on different devices
« Reply #12 on: December 21, 2012, 08:23:53 am »
There's a "german corner" for discussions in german: http://www.jpct.net/forum2/index.php/board,6.0.html

Stell deine Frage einfach dort nochmal kurz.