Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 11th Mar 2019 18:08
Wait, that's the one that you always have to set to off at the top of every project right?

Kidding

I don't really know of an equivalent command built in.

I wrap all of my media loading through custom loader functions though anyway, so i would just update the camera to point to the new object as it loads in that function.

Otherwise, if you're not already toting all object loading through a common custom function,
everytime you load an object you'll also need to point the camera on the next line.
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 11th Mar 2019 18:17
Pointing the camera at the object is the easy part.
The tricky bit is setting the camera to a suitable distance from the object so that it almost fills the screen regardless of the size of the object.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 11th Mar 2019 18:23
Quote: "The tricky bit is setting the camera to a suitable distance from the object so that it almost fills the screen regardless of the size of the object."

Agreed scaling and setting the distance is all relative, not sure if you have any of the asset packs but the AppGameKit asset viewer does this quite well.
The question is how they do it , must be some kind of simplish algorithm that does it nicely
fubar
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 11th Mar 2019 19:25
I've done it in the landscape editor, but it's crude and done through iteration. Place the camera in the centre of the object, move it back along the z axis a fixed amount, check if the extremities if the object are in the screen bounds. Repeat until they are. It's quick enough, but you wouldn't want to do it every single frame.
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 11th Mar 2019 19:26
I'm also sure you could do it with some fancy maths, taking the min to max difference of the objects mesh, then working out based on the veiwing angle how far back the camera would need to move, but im rubbish at maths. Lol.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 11th Mar 2019 20:48
I have experimented with that.
What i did was this;
1. I get the min/max size of the object (GetObjectSizeMaxX/Y/Z)
2. I put a cube at those points
3. I attached the cubes to the object (This works no matter where the object has been moved to/rotated/scaled)
4. Then i make the camera look at the object
5. Then move the camera to the objects position
6. Then move the camera along the -z axis until GetObjectInScreen() is true for all the cubes

Like santman says. I wouldn't do it every frame but what you could do is, once you've figured the distance, attach a cube to that point and use it to position your camera from then on
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 12th Mar 2019 10:50
I like that, it could be useful. Thanks.
I wouldn't need it every frame but I would need it to be as fast as possible, so if someone can come up with a mathematical solution that would be awesome.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 12th Mar 2019 10:57
@Scraggle I had a play with blinks concept and it worked well for centering on an object I selected and moving an amount on z axis
with the 3D placement editor I made a while back. I found it was quite fast and quite suitable for that
fubar
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 12th Mar 2019 12:02
Do we need the cubes? It Mau be faster to convert the 3d points if the extremities to 2d screen coords, then just do a simple test on them, saves the object creation/attaching, multiple checking etc, that's more what I meant.

I'm curious now to see which is faster. In fairness I use it for thumbnails of objects, and originally generated 12 of them with different rotation angles, which I set as a sprite.....it worked quite fast, but without the sprite animation there's no noticeable delay at all. I think the key is how quickly you move backward, I.e. how many iterations you need to do before the object is on screen.

As mentioned, could you do it once, store the distance for each object, then just jump to that? There would be no delay in that case.
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 12th Mar 2019 12:59 Edited at: 12th Mar 2019 13:00
I have here a modified version of the DBPro function. Maybe you want to have a look at it?

With (r#*3.0) you can change the distance.
< short distance > larger distance.

Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 12th Mar 2019 16:39
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 12th Mar 2019 21:29
That is a nice piece of code MadBit
I think GetObjectSizeX/Y/Z will always return the values at the objects original scale. So if the object is scaled up it may have issues
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 13th Mar 2019 09:36
I think it does too, unless you use setobjectscalepermanant
MadBit
VIP Member
Gold Codemaster
14
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 13th Mar 2019 10:36
Yeah, you're right. I wrote it quickly and chose the wrong entries from the autocomplete.
Share your knowledge. It\'s a way to achieve immortality. (Tenzin Gyatso)
Santman
12
Years of Service
User Offline
Joined: 15th Sep 2011
Location: Inverness
Posted: 13th Mar 2019 12:01
Still though......it's a brilliant but of code......not adapting mine now at all! Lol
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 13th Mar 2019 20:55
Quote: "Still though......it's a brilliant but of code"

I wholeheartedly concur!
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 21st Mar 2019 04:55
I did some experimenting with this.
The min/max values remain the same when the object is rotated or scaled (Not scaled permanent)
So the min/max values will be as if you had just loaded the object always

The thing with attaching the boxes is: Not matter where the object is, no matter what the scale and rotation, if you create the boxes, move them to the min/max values and attach them to the object, they will always be at the extremities of the object.
This means that you do not need to have the boxes permanently attached to the object. Only when you want to calculate the bounding box.

I made some code to show the technique of attaching objects to the min/max values and calculating the bounding box.



Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 21st Mar 2019 12:48 Edited at: 21st Mar 2019 12:54
That's good code for getting an object aligned bounding box but it's still not doing what Autocam() used to do in DBP.
However, I have taken blinkok's code and adapted it so that it now does the final bit of scaling necessary for Autocam behavior.

In DBP you would set Autocam on and then any objects loaded after that would move the camera accordingly. Here we load an object and then call the Autocam() function passing the objects ID. It will scale the object so that it fills half of the screen which I think is about right. That way if the object is a character with the offset at its feet we will still get all of it on screen.

Thanks blink

NOTE: For any non-DBP users or anyone unfamiliar with the Autocam function - the only purpose it serves is as a quick and dirty object viewer. It ensures the object is large enough to be seen properly without exceeding the screens edges.



You will (obviously) need to change the object loading line for one of your own.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 21st Mar 2019 19:48 Edited at: 21st Mar 2019 22:37
If you take my numbers, extract the 3D min/max/x/y/z rather than the 2d min/max/x/y and plug them into madbit's code then it will work
plus if you use planes rather than boxes it will be less poly heavy

Looking at MadBits code it moves the camera back and amount relative to the volume of the shape (I think)

I think you could get a really accurate framing using the cameras field of view GetCameraFOV().
The doco says the default FOV is 70 degrees. So a 70 degree angle between the right and left edge of the screen.

I don't know the math (Didn't pay attention at school) but you have 2 angles and the length of an edge of a right angle triangle like so


I dunno the math but if you calculate the edge of the triangle for each plane of view and set the distance to the longest one it should frame the object right?

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-04-19 12:36:58
Your offset time is: 2024-04-19 12:36:58