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.

DarkBASIC Professional Discussion / 2D Details from a 3D object

Author
Message
A r e n a s
18
Years of Service
User Offline
Joined: 9th Jun 2008
Location:
Posted: 11th Jul 2011 01:10
Hi everyone, I'm wondering if I can get a bit of help with the problem described in the title. It's in aid of my game, here is a link.

I was wondering how I would get a 2D co-ordinate for an object, where I dont want the object centre, but rather its top left element on the screen and bottom left element.

I know there is a 'get screen x' command which I've been told before. The issue is that I dont then know the visible corners of the object... And depending upon camera angle and rotation, I cant compensate for each objects centre by subtracting x and y units from the co-ordinates given...

A

29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 12th Jul 2011 00:04
Try this, it draws a 2D bounding box around a 3D object but you should be able to modify it to suit your needs.






Nice looking game, by the way.
A r e n a s
18
Years of Service
User Offline
Joined: 9th Jun 2008
Location:
Posted: 12th Jul 2011 01:29 Edited at: 13th Jul 2011 01:32
Thanks, and thanks for the code as well! Exactly what I was looking for, it will definitely prove a massive help with the game. Should have it integrated in a day or twos time (other integrations are taking place) and then screens will be up on my thread for everyone to see. I'll credit your name also for the help.

A

29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 13th Jul 2011 00:51 Edited at: 13th Jul 2011 01:03
Glad it was what you were after.

I just had a thought, though. I wrote the code I posted assuming the object was going to follow the FVF format that is used for the inbuilt DBPro primitives, which is unhelpfully different from the format described in the help files.

Inbuilt DBPro objects : FVF format = 274 and vertex element size = 32

Format as described in the help files : FVF format = 338 and vertex element size = 36

The inbuilt objects don't have any diffuse data.

If you have problems using the code I posted with you objects, it's probably going to be this.

I've also had problems in DBC using the "object screen x()" and "object screen y()" commands in the if the object is directly behind the camera it will still register a screen x and y coordinate. In the case of the code I posted, if the 3D box is directly behind the camera the 2D box is still drawn to the screen.

Below is a slightly modified version of the code above, where it extracts the vertex size from the memblock (see line 50) and then uses this when getting the vertex coordinate data. I've also added an if statement to only draw a 2D box is the 3D object is on the screen.





I might just be pre-empting a problem you may not be having but I thought I'd mention it.

If you're still having problems getting the memblock info, then post one of the models you're using and I'll have a look at it for you.
A r e n a s
18
Years of Service
User Offline
Joined: 9th Jun 2008
Location:
Posted: 13th Jul 2011 01:37
I am getting a bit for a strange error with the code you've given me. I thought that the new code may fix that as you describe something which could potentially distort the box as is currently happening. For some reason, the code is only working on one of the three current object I am using in my game.

The image below illustrated what is happening. For some reason the boxes generated are of peculiar shapes. There has been no scaling occurring of the models in the code, there are no erroneous vertices left lying about in the model and all three models are the same format, so I am slightly confused as to where the problem lies.



If you could tell me once you have a copy of the attached model (power station) could you tell me so that I can delete it from this post. I don't particularly want it lying about for people to take.

A

29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 13th Jul 2011 02:02
I've downloaded the model and it loads up.

I'll have a look at it tomorrow and get back to you.
A r e n a s
18
Years of Service
User Offline
Joined: 9th Jun 2008
Location:
Posted: 13th Jul 2011 02:11
Thanks, I've run your code with this model replacing model number 1, and I'm getting the same problems. I guess that means that at its basic level there's an issue with;

a) Your code
b) Random Models (unlikely)
c) The format
d) The method through which these models are loaded

A

29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 13th Jul 2011 03:59
When I said I'd look at this tomorrow, what I meant to say is that I was going to stay up late and try and figure this out

I had a look at the model you sent me and the model that is shown on the screen is rotated 90 degrees from the information in the memblock.

Run this program and you'll see what I mean. This currently loads up the "powerplant.x" model, see the "LOAD_OBJECTS" sub-routine.



The wireframe model is your model, the ghosted red object is created by taking the vertex data from the memblock and then contructs the model from triangle primitives. You can see that the ghost object is rotated 90 degree from the actual model.

This problem was cured when I loaded your model into blender and re-exported it as a .x file.

I also created some other models in blender but couldn't replicate the same issue that I was seeing with your model.

Is the email address you have in your profile current? If so I can email you the model I created and you can see if this works.
A r e n a s
18
Years of Service
User Offline
Joined: 9th Jun 2008
Location:
Posted: 13th Jul 2011 04:11 Edited at: 13th Jul 2011 14:35
Thats still my current email address yes. If you email me we can sort this whole mess out, and hopefully I will be able to fix these issues myself in the future and not need any help if you can show me what to do. Thanks again massively for all the help you've given me!!

EDIT

I cant seem to find a 'direct x' plugin, could you direct me to where you got yours or the version in which I can find it?

A

29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 13th Jul 2011 22:21
I've emailed you the model I exported, it has the subject title "from 29 Games - model".

The direct x exporter I use can be found here:

http://forum.thegamecreators.com/?m=forum_view&t=166987&b=3

I'm currently using Blender 2.49b.

For non-animated models I've never had a problem with the inbuilt direct x exporter, but then I am still a little new to blender and this style of 3D modeling so I've not really done anything too complicated yet.

One thing I mentioned in my email is that you should check to make sure the model can still be textured, hopefully it will.

If it doesn't then this could all become a lot of work and I'd hate for this problem to distract you from getting on with your game.

One thing I've not asked is: why do you need to know the 2D screen coordinates? Are you trying to draw a box around the model or are you trying to do something else. I only ask as there may be another way to what you need to do.

I don't know if you've played ESF by Ermes:

http://forum.thegamecreators.com/?m=forum_view&t=181249&b=5

He managed to get boxes and health bars drawn around and near his spaceships and it looks really good. He was also kind enough to put the code in with the download so you might be able to pick up some tips from that. I'm sure if you asked him nicely he wouldn't mind you borrowing some ideas.
A r e n a s
18
Years of Service
User Offline
Joined: 9th Jun 2008
Location:
Posted: 14th Jul 2011 00:42
The box is unnecessary, its the co-ordinates which I need so I can place health and rank information above the objects. Using the object centre would do it, it would just look a bit messy so I'm not going to mess about with that. This method is much better looking, and I'm there now with the implementation.

Now I have to modify the code to increase its efficiency and fix a couple of issues with the code I've written. I also have a very minor error with the tank... It's driving backwards... The model obviously just needs to be rotated, but I'm having a nightmare trying to rotate it precisely 180 degrees around the y axis! Why is it so difficult with blender?

Heres a screen of the working code;



A

29 games
20
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 14th Jul 2011 00:50 Edited at: 14th Jul 2011 00:51
Quote: "I'm having a nightmare trying to rotate it precisely 180 degrees around the y axis! Why is it so difficult with blender?"


In object mode, select the object, press r (to rotate), press z (to rotate about the z axis), type "180" (to rotate 180 degrees), press enter.

Or

In object mode, select the object, press n to bring up the tranform properties window, click on the RotZ value, delete what's there and type in the angle you want, press enter.

That's how it works in 2.49, I imagine it can't be much different in 2.5 but I could be wrong.

Nice screen shot and I'm glad everything's working out.
A r e n a s
18
Years of Service
User Offline
Joined: 9th Jun 2008
Location:
Posted: 14th Jul 2011 01:07
Thanks for the tips, I've sorted out the problem now using your first method. Just going to finish the rest of the modifications then I'll bring in some new feature such as pathfinding or resolution compensation.

Thanks massively for your help 29 games! I hope this thread will in turn help anyone else with a similar problem!

A

Login to post a reply

Server time is: 2026-07-10 21:41:50
Your offset time is: 2026-07-10 21:41:50