www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: rushtone on December 18, 2012, 07:10:42 pm

Title: Scaling on different devices
Post by: rushtone 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.
Title: Re: Scaling on different devices
Post by: EgonOlsen on December 18, 2012, 08:37:49 pm
Title: Re: Scaling on different devices
Post by: Bryce Thorup 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.
Title: Re: Scaling on different devices
Post by: rushtone 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.
Title: Re: Scaling on different devices
Post by: EgonOlsen on December 18, 2012, 09:41:10 pm
Title: Re: Scaling on different devices
Post by: rushtone 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.
Title: Re: Scaling on different devices
Post by: EgonOlsen 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?
Title: Re: Scaling on different devices
Post by: rushtone 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. :)
Title: Re: Scaling on different devices
Post by: EgonOlsen 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... ;)
Title: Re: Scaling on different devices
Post by: rushtone 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.
Title: Re: Scaling on different devices
Post by: EgonOlsen 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....).
Title: Re: Scaling on different devices
Post by: rushtone 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.
Title: Re: Scaling on different devices
Post by: EgonOlsen 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 (http://www.jpct.net/forum2/index.php/board,6.0.html)

Stell deine Frage einfach dort nochmal kurz.