Can I display a Sprite3D object at 2 places in the world?

FW: http://developer.sonyericsson.com/thread.jspa?threadID=30521&tstart=180


Permlink Replies: 6 - Pages: 1 - Last Post: Jul 29, 2006 10:18 AM by: Xmas Threads: [ Previous | Next ]
arbixy

Posts: 33
Registered: 7/21/06
 Can I display a Sprite3D object at 2 places in the world? :S
Posted: Jul 25, 2006 11:14 AM
 
 Click to reply to this thread Reply

Hello again!

Still looking for ways to save memory :) I'm sorry to post two threads at once, but the two subjects are definitely different and cant be joined in one thread only.
So mister moderator, please excuse me, it wont happen again :)

Back to my question:

I am displaying Sprite3D elements under the text of my menu in a 3D rendered scene.

Lets imagine I have 5 choices in my main menu: 4 of them are not currently selected, one is.
I'd like to display one special Sprite3D behind these 4 choices, and another one behind the choice currently selected.

Do I have to load 4 different Sprite3D objects to diplay the same image 4 times? Thats what I'm doing at the moment. It sure works, but it looks like a lot of memory wasted here.

So my question is pretty simple: can i create a Sprite3D object, and diplay it at 2 (at least :p) different places in my world space?

I tried already but a Sprite3D object can have one parent node only.
I also tried to use the duplicate() method to avoid re-creating my Sprite3D object, but wouldnt it be exacty the same as the System migt create the duplicate objects in memory?

punkedge  


Posts: 162
Registered: 11/15/04
 Re: Can I display a Sprite3D object at 2 places in the world? :S
Posted: Jul 26, 2006 2:04 AM   in response to: arbixy
Helpful
 Click to reply to this thread Reply

its easy to do tht
say u hav a sprite3d sp use the render command

g3d.render(sp,transform);
g3d.render(sp,transform2);

also the duplicate method is the same thing ...its jus keeps the same object wid separate transforms so there are no separate objects created in memory.
so u can use both the ways to do wht u want to.

cheers !

Xmas

Posts: 47
Registered: 2/21/06
 Re: Can I display a Sprite3D object at 2 places in the world? :S
Posted: Jul 26, 2006 6:09 AM   in response to: punkedge
Very Helpful
 Click to reply to this thread Reply

> also the duplicate method is the same thing ...its
> jus keeps the same object wid separate transforms so
> there are no separate objects created in memory.
> so u can use both the ways to do wht u want to.

Not true, the duplicate method will create a completely new object with most of the fields set to the same data (except for some of those belonging to Node). It is not possible to just keep the same object with separate transforms.


Trying to save memory is a good thing, however I would recommend to not overdo it. If it is easy to save an object or two somewhere and doesn't impact readability of your code, by all means, do it. But you should only optimize where it really makes a difference (and only optimize once the code is running). It just doesn't pay off to chase every last byte, even on very limited mobile devices.

The minimum amount of memory used for a Sprite3D object should be around 176 bytes (12 for Object3D, 104 for Transformable, 32 for Node, 28 for Sprite3D). An implementation might of course use more than that internally, however this is still not excessively large if you only have five of them. In all likelyhood it is still much less memory than the Image2D for the sprites needs.

arbixy

Posts: 33
Registered: 7/21/06
 Re: Can I display a Sprite3D object at 2 places in the world? :S
Posted: Jul 28, 2006 7:18 AM   in response to: Xmas
 
 Click to reply to this thread Reply

Well okay, there's no way to do it by sticking to retained mode. I'm gonna have to mix retained and immediate mode if i wanna use only one Sprite3D object instead of, actually, 6.

On the other hand, what Xmas says is quite true, I'm not sure I wanna get my code complicated that much to save a few bytes. I might give it a try though.

Thanx for answering guyz, and for being that clear. ;)

venkat512

Posts: 9
Registered: 3/16/06
 Re: Can I display a Sprite3D object at 2 places in the world? :S
Posted: Jul 28, 2006 11:55 PM   in response to: punkedge
 
 Click to reply to this thread Reply

Hi,
A small question......

g3d.render(sp,transform);
g3d.render(sp,transform1);

how to declare transform here.....when i want to place 50 trees...i have to geive 50 transforms here....The transform is a 4*4 identity matrix.So it wil take more memory than the Sprite3D objects..i think......It's correct are not....

tel me how to declare trnasforms here....

Thank's in advance...

arbixy

Posts: 33
Registered: 7/21/06
 Re: Can I display a Sprite3D object at 2 places in the world? :S
Posted: Jul 29, 2006 3:33 AM   in response to: venkat512
 
 Click to reply to this thread Reply

This is a very interesting question u have here.

The way I do it is the following:

//this is a global (an attribute) used everywhere
Transform rmp = new Transform();

//when i need a transform:
tmp.setIdentity();
tmp.postTranslate( ... );
tmp.postScale( ... );
...
g3d.render( sp1, tmp );
//then do it again for the next sprite
tmp.setIdentity();
tmp.postTranslate( ... );
tmp.postScale( ... );
...
g3d.render( sp2, tmp );


I'm suddenly wondering if it's the right way to do it. I'm gonna check the JSR184 doc to see if a call to render copies the Transform object or just makes a reference to it. In the latter, I think I'm screwed and gonna have to change some pieces of code.

Thx for making me focus on that anyway! Gonna check this and get back to this thread.

Cheers!

Xmas

Posts: 47
Registered: 2/21/06
 Re: Can I display a Sprite3D object at 2 places in the world? :S
Posted: Jul 29, 2006 10:18 AM   in response to: arbixy
 
 Click to reply to this thread Reply

> w to declare transform here.....when i want to place
> 50 trees...i have to geive 50 transforms here....The
> transform is a 4*4 identity matrix.So it wil take
> more memory than the Sprite3D objects..i
> think......It's correct are not....
The 50 Transforms together will need more memory than one Sprite3D, but a Sprite3D object requires more memory than a Transform, since it's a subclass of Transformable.


> I'm suddenly wondering if it's the right way to do
> it. I'm gonna check the JSR184 doc to see if a call
> to render copies the Transform object or just makes a
> reference to it. In the latter, I think I'm screwed
> and gonna have to change some pieces of code.
Don't worry. A call to render will always act as using the Transform object in its state at the point of the method call, regardless of whether it performs the actual rendering immediately or not.
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值