Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (769)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (855)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Material.setDiffuse*Color() : copy or reference?  (Read 1284 times)
0 Members and 1 Guest are viewing this topic.
Offline Bombadil

Senior Devvie





« Posted 2004-04-01 15:59:04 »

Is it intention or accident that the Material.setXXXColor(Color3f color) methods don't copy the color object but store its reference? So you mustn't re-use the color object after having used one of the method calls...
It took me several debug sessions to detect this irregularity, which isn't documentated in the Javadoc. ;-)

This is valid for at least:
material.setAmbientColor(color)
material.setDiffuseColor(color)
material.setSpecularColor(color)
material.setEmissiveColor(color)

In other related method calls, Xith3d makes a copy of the color object, for example in:
ColoringAttributes colatt = new ColoringAttributes();
colatt.setColoringAttributes(color);

Btw, the new com.xith3d.utility.geometry.GeometryCreator does use objects by reference, too, but states so, for example in the method documentation it says
Quote
Important - all methods in this class copy vecmath objects by reference, so please do NOT reuse them for filling data.

Which is good and important to know. :-)
Offline Bombadil

Senior Devvie





« Reply #1 - Posted 2004-04-03 12:21:32 »

What could be the answer to that?
:-)
Offline orz

Senior Newbie




Java games rock!


« Reply #2 - Posted 2004-05-10 14:42:08 »

From http://xith.org/tutes/xith3d.pdf:

1.1.2 Reduced memory copies

The Xith3D scenegraph rarely copies the contents of objects when the values of a node
are set. In almost all cases where an attribute of a node is set with the value of an object,
the object reference supplied replaces the object reference that the node previously used.
So for example setting the ambient color of a material and passing it a Color3f object
does not copy the values of the object, it just assigns the pointer internally. Conversely,
if you use the method that passes in the floats, the data is copied into the underlying
object. So for example mat.setAmbientColor(float r, float g, float b, float a) will write
the data into the Color4f object inside the material.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Bombadil

Senior Devvie





« Reply #3 - Posted 2004-05-10 15:52:20 »

Quote
From http://xith.org/tutes/xith3d.pdf:

1.1.2 Reduced memory copies

Thanks for that hint. So it's intended...
And again I would like to vote to include such important information into the Javadoc of my quoted Xith methods: because it's the first place to look at usually.
Offline orz

Senior Newbie




Java games rock!


« Reply #4 - Posted 2004-05-12 10:34:04 »

I agree, the Javadoc is sparse at best Smiley

I think it's one of the areas of Xith3D that needs the most love and caring at the moment...

Terje
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1594 views)
2018-06-10 19:43:48

EgonOlsen (1663 views)
2018-06-10 19:43:44

EgonOlsen (1150 views)
2018-06-10 19:43:20

DesertCoockie (1578 views)
2018-05-13 18:23:11

nelsongames (1178 views)
2018-04-24 18:15:36

nelsongames (1669 views)
2018-04-24 18:14:32

ivj94 (2443 views)
2018-03-24 14:47:39

ivj94 (1651 views)
2018-03-24 14:46:31

ivj94 (2743 views)
2018-03-24 14:43:53

Solater (905 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!