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 / INSTANCE OBJECT - something wrong isn't right

Author
Message
Starshyne Emir
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location: Porto Alegre, southern Brazil
Posted: 19th May 2018 16:22
Well, the problem is the following: I want to produce several copies of an object and rotate them all at once. Since I don't want to blow my CPU out with tons of looped object rotations, I decided to do the following:

I made an object, textured it and then instanced it.
The idea was to rotate the limb 0 of the 1st object and see if the limb 0 of the instanced object would be rotated together. It worked, but strangely the rotation isn't synchronous, both objects seem to turn at different speeds and I don't know why.

Other oddity of this code is that the texture of the instanced object is mirrored, instead of being alligned exactly like the original one.

This is a piece of code to illustrate the problem:




Why this is happening?
[size=+2]Forever and one[/size]
gamehazer
5
Years of Service
User Offline
Joined: 2nd May 2018
Location:
Posted: 19th May 2018 19:45
Sounds like to me both limbs have different rotation positions at first launch.

Try to print each limbs y position before the rotation happens to see where they are.
Starshyne Emir
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location: Porto Alegre, southern Brazil
Posted: 19th May 2018 20:07
Hahaha, my fault. I should have printed the LIMB ANGLE Y of both objects before doing anything else. Thank you for reminding me about the basics of programming.. And I'm not being sarcastic, you taught me an important lesson: print the values that are working strangely before annoying true developers at the forums.

(a few minutes later...)



I added the limb angles of both objects plus the absolute angles of them and... Whoa!

That doesn't make any sense! First: limb angle of 2nd object doesn't change when the first one does. In fact it changes, but the second object keeps saying that its limb angle is 0. Object angle y of 2nd object is 180 degrees, though it wasn't rotated. I guess it is some kind of bug, because there is nothing wrong with the code, at least as far as I can see.

[size=+2]Forever and one[/size]
gamehazer
5
Years of Service
User Offline
Joined: 2nd May 2018
Location:
Posted: 19th May 2018 20:28
rotate limb 2,0,0,wrapvalue(limb angle y(1,0)+1),0

I dont see you rotating the second objects limb?

Are they both not rotating?

Now I'm confused.
Starshyne Emir
7
Years of Service
User Offline
Joined: 27th Nov 2016
Location: Porto Alegre, southern Brazil
Posted: 19th May 2018 20:49
Object 1, limb 0 is rotated. What is expected: instanced object 2, limb 0 should be rotated equally. It doesn't happen.

Object rotation is not shared between original and instance, but limb rotation is - I was trying to come up with a way to rotate many objects at once like the rings in Sonic, for example, but now that I found this bug, I guess I'll need to find another way to solve the problem I created.

Sorry if I confused you. Maybe my poor English is to blame, maybe my code is too dull.
Sorry for wasting your time, mate.
[size=+2]Forever and one[/size]
gamehazer
5
Years of Service
User Offline
Joined: 2nd May 2018
Location:
Posted: 19th May 2018 20:51
I know

When you instance anything it copies information and this created a delay

you will have to rotate both limbs to get the same rotation with no delay, unless there is another way.
gamehazer
5
Years of Service
User Offline
Joined: 2nd May 2018
Location:
Posted: 19th May 2018 20:58 Edited at: 19th May 2018 21:04
do this

for all= 1 to 2

rotate limb all,0,0,wrapvalue(limb angle y(1,0)+1),0

next all

edit

sorry, forgot to add the "all" at the end as all of them rotate around there own angle.

for all= 1 to 2

rotate limb all,0,0,wrapvalue(limb angle y(all,0)+1),0

next all
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 20th May 2018 16:02
Starshyne Emir: Limb rotation on instanced objects works as it should. It is the spacial separation that it appears not synchronized. If you are creating a 2D game and are just wanting to add 3D aspects, you can set the camera projection to orthographic. Dmitry K has a function to do this here.
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 20th May 2018 16:47 Edited at: 20th May 2018 16:49
The mirrored texture is due to the fact that a plane is created with the normal's pointed in the opposite direction. This is the reason the object is rotated on the Y axis 180 degrees. Try using the Make Object Planes optional orientation flag.
gamehazer
5
Years of Service
User Offline
Joined: 2nd May 2018
Location:
Posted: 20th May 2018 21:53 Edited at: 20th May 2018 21:54
I took the time to run the code and made some changes

I cloned the object, this way we can use it the same way. Then I just rotate the objects and not any limbs.

I simplified it with no textures to for the example.

gamehazer
5
Years of Service
User Offline
Joined: 2nd May 2018
Location:
Posted: 20th May 2018 22:13
And here it is changed with textures

Sorry, just showing how you dont need to instance or rotate limbs

WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 22nd May 2018 02:46 Edited at: 22nd May 2018 02:51
Sorry about that. Seems Dmitry K's function needs a little work. Would have been easy if Matrix1Utils had a Set Projection Matrix4 function. This is what I'm talking about, if you run the executable. Here is the source code. Sorry, it uses some functions from my DBPro build.

Attachments

Login to view attachments
Derek Darkly
12
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 23rd May 2018 18:40

Using Starshyne's original code, I simply rotated the first object to 180 and did a FIX OBJECT PIVOT before instancing.
After that the objects weren't mirrored:

Send your parents to noisy sprite demo hell... enter the D-Zone
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 24th May 2018 02:03
By rotating the plane 180 degrees on the y axis, you are setting the angle to what it already is. Fix Object Pivot or just setting the yrotation to zero will work.

Try this. Create two plane objects side by side, one with the orientation flag set, one without and rotate the objects on the y axis. Make sure the object light and culling flags are set. Notice the object with the orientation flag set is brighter when visible. Without the orientation flag set a plane simply has the normals pointed in the opposite direction then they should be. Again this is the reason the plane is rotated on the y axis 180 degree.
Derek Darkly
12
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 24th May 2018 04:43

Ah! So you are saying using the orientation flag is the only necessary step?
Or not?! Sorry.. i just lost 50 points on chess.com. my comprehension and self-esteem have bottomed out... for now. =P

Wait, this isn't even my thread...
Send your parents to noisy sprite demo hell... enter the D-Zone
gamehazer
5
Years of Service
User Offline
Joined: 2nd May 2018
Location:
Posted: 25th May 2018 13:33
I'm not sure why its being done this way in the first place.

There is no real reason i see to rotate limbs in the fashion for planes.

Like I posted already rotating the objects together works better, faster and also there is no confusion.

WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 26th May 2018 00:55
gamehazer; That works fine with two planes. Try 100 or 1000, then tell me it's faster.
gamehazer
5
Years of Service
User Offline
Joined: 2nd May 2018
Location:
Posted: 26th May 2018 01:01
I have and am now my friend,

And it is faster as there is no calculations for limb numbers or positions.
WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 26th May 2018 03:25 Edited at: 26th May 2018 03:26
I don't know how you arrived at that conclusion. The performance timer shows rotating the limb of one object to be faster then rotating 100 objects.
gamehazer
5
Years of Service
User Offline
Joined: 2nd May 2018
Location:
Posted: 26th May 2018 03:59
When you are rotating one limb you are also rotating 99 other limbs at the same time.

I see no difference other then there objects and there is no other calculation's.

Am I wrong?

WickedX
15
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 26th May 2018 04:36
A instanced object shares most of the properties as the original object. Each instanced object shares the same mesh data, limb rotation data is shared as well. Internally the calculations are performed regardless. Think about it, what would be faster. Simply adding a value or checking if the value needs to be added and if so adding the values, each iteration.

In addition, you are only using one function, not 100+
chafari
Valued Member
17
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 26th May 2018 10:32
Hi there
I think we're getting away from the purpose of the INSTANCE command .
Quote: " I want to produce several copies of an object and rotate them all at once. Since I don't want to blow my CPU out with tons of looped object ..."


That's the real purpose of INSTANCE command, to make tons of objects...trying to lose the minimum performance with instanced objects .
Quote: "I'm not sure why its being done this way in the first place."


As WickedX commented That works fine with two planes.

@gamehazer
Try this piece of code and change instance by clone and see the perfomance FPS in both cases .

I'm not a grumpy grandpa
gamehazer
5
Years of Service
User Offline
Joined: 2nd May 2018
Location:
Posted: 26th May 2018 18:25
chafari hi,

Wow, I changed the command to clone object and my fps dropped to 88 frames per second. Then tried instance and it jumped to 124.

You are correct,

gamehazer
5
Years of Service
User Offline
Joined: 2nd May 2018
Location:
Posted: 26th May 2018 18:28
WickedX, that sounds right, there is more to instance then I knew.

I will need to use this myself, thank you.

Login to post a reply

Server time is: 2024-04-20 01:03:59
Your offset time is: 2024-04-20 01:03:59