AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Static Variables? and Lights on Textured Objects?

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> 3D Graphics API's for Java
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Sat Dec 09, 2006 7:41 pm    Post subject: Static Variables? and Lights on Textured Objects? Reply with quote



two problems.... the first is my main one, as my lecturer doesnt have a
solution for this and is annoying him also.


the problem is i have a java3d scene, 4 polygon walls, put a texture on
them. add a single light. but the walls appear as if they are lit up,
bright as day.

i looked it up and found out about "lighting normals", in a quadarray,
but im having the same problem with a textured box. anyway know how to
set up a texture to be affected by light also?

example wall code:

Color3f ambient = new Color3f(0.0f, 0.0f, 0.0f);
Color3f emissive = new Color3f(0.0f, 0.0f, 0.0f);
Color3f diffuse = new Color3f(0.0f, 0.0f, 0.0f);
Color3f specular = new Color3f(0.0f, 0.0f, 0.0f);
float shininess = 0.1f;
Material wallmat = new Material(ambient, emissive, diffuse,
specular, shininess);

Vector3f polygonxnormal = new Vector3f(1f,0f,0f);
Vector3f polygonynormal = new Vector3f(0f,1f,0f);
Vector3f polygonznormal = new Vector3f(0f,0f,1f);

Appearance wallAppearance = new Appearance();
wallAppearance.setTexture(texwall);
wallAppearance.setMaterial(wallmat);

QuadArray westwall = new QuadArray (4,QuadArray.COORDINATES |
QuadArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2);
westwall.setCoordinate (0, new Point3f (0f, 0f, 0f));
westwall.setCoordinate (1, new Point3f (0f, 0f, -200f));
westwall.setCoordinate (2, new Point3f (0f, 6f, -200f));
westwall.setCoordinate (3, new Point3f (0f, 6f, 0f));

westwall.setTextureCoordinate (0, new Point2f(0f,0f));
westwall.setTextureCoordinate (1, new Point2f(50f,0f));
westwall.setTextureCoordinate (2, new Point2f(50f,1f));
westwall.setTextureCoordinate (3, new Point2f(0f,1f));


westwall.setNormal(0,polygonxnormal);
westwall.setNormal(1,polygonxnormal);
westwall.setNormal(2,polygonxnormal);
westwall.setNormal(3,polygonxnormal);


example box code:

Appearance boxapp = new Appearance();
texbox.setBoundaryModeS(Texture.CLAMP);
texbox.setBoundaryModeT(Texture.CLAMP);
boxapp.setTexture(texbox);

ambient = new Color3f(0.0f, 0.0f, 1f);
emissive = new Color3f(0.0f, 0.0f, 0.0f);
diffuse = new Color3f(0f, 0f, 0f);
specular = new Color3f(0f, 0f, 0f);
shininess = 0f;

Material boxmat = new Material(ambient, emissive, diffuse,
specular, shininess);

boxapp.setMaterial(boxmat);


for (int i=0; i<numberofobstacles; i++) {
obstacles.addChild(createObstacles(boxapp));
}






the second problem im having is probably much easier.
im driving the viewpoint around, using a keylistener i wrote. each box
has a collision detector (created in RunGame and added to the box) that
can print to the console, like "box hit by viewpoint".
but what i want to do, is update a "score" variable in RunGame (i.e
RunGame.score++) in a thread that keeps checking the varaible to see if
its changed, and if it has, updatea a JTextArea.
but since RunGame created Collision, Collision cant call a method in
RunGame.

i realise this is a static problem, but i dont understand them too
well. how could i access the "score" variable from Collision.java AND
RunGame.java.

thanks for any help in advance,
duncan
Back to top
dunctait
Guest





PostPosted: Sun Dec 10, 2006 2:56 am    Post subject: Re: Static Variables? and Lights on Textured Objects? Reply with quote



got the static variable workin thanks... but the java3d problem is
still a problem..

thanks


dunctait (AT) hotmail (DOT) com wrote:
Quote:
two problems.... the first is my main one, as my lecturer doesnt have a
solution for this and is annoying him also.


the problem is i have a java3d scene, 4 polygon walls, put a texture on
them. add a single light. but the walls appear as if they are lit up,
bright as day.

i looked it up and found out about "lighting normals", in a quadarray,
but im having the same problem with a textured box. anyway know how to
set up a texture to be affected by light also?

example wall code:

Color3f ambient = new Color3f(0.0f, 0.0f, 0.0f);
Color3f emissive = new Color3f(0.0f, 0.0f, 0.0f);
Color3f diffuse = new Color3f(0.0f, 0.0f, 0.0f);
Color3f specular = new Color3f(0.0f, 0.0f, 0.0f);
float shininess = 0.1f;
Material wallmat = new Material(ambient, emissive, diffuse,
specular, shininess);

Vector3f polygonxnormal = new Vector3f(1f,0f,0f);
Vector3f polygonynormal = new Vector3f(0f,1f,0f);
Vector3f polygonznormal = new Vector3f(0f,0f,1f);

Appearance wallAppearance = new Appearance();
wallAppearance.setTexture(texwall);
wallAppearance.setMaterial(wallmat);

QuadArray westwall = new QuadArray (4,QuadArray.COORDINATES |
QuadArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2);
westwall.setCoordinate (0, new Point3f (0f, 0f, 0f));
westwall.setCoordinate (1, new Point3f (0f, 0f, -200f));
westwall.setCoordinate (2, new Point3f (0f, 6f, -200f));
westwall.setCoordinate (3, new Point3f (0f, 6f, 0f));

westwall.setTextureCoordinate (0, new Point2f(0f,0f));
westwall.setTextureCoordinate (1, new Point2f(50f,0f));
westwall.setTextureCoordinate (2, new Point2f(50f,1f));
westwall.setTextureCoordinate (3, new Point2f(0f,1f));


westwall.setNormal(0,polygonxnormal);
westwall.setNormal(1,polygonxnormal);
westwall.setNormal(2,polygonxnormal);
westwall.setNormal(3,polygonxnormal);


example box code:

Appearance boxapp = new Appearance();
texbox.setBoundaryModeS(Texture.CLAMP);
texbox.setBoundaryModeT(Texture.CLAMP);
boxapp.setTexture(texbox);

ambient = new Color3f(0.0f, 0.0f, 1f);
emissive = new Color3f(0.0f, 0.0f, 0.0f);
diffuse = new Color3f(0f, 0f, 0f);
specular = new Color3f(0f, 0f, 0f);
shininess = 0f;

Material boxmat = new Material(ambient, emissive, diffuse,
specular, shininess);

boxapp.setMaterial(boxmat);


for (int i=0; i<numberofobstacles; i++) {
obstacles.addChild(createObstacles(boxapp));
}






the second problem im having is probably much easier.
im driving the viewpoint around, using a keylistener i wrote. each box
has a collision detector (created in RunGame and added to the box) that
can print to the console, like "box hit by viewpoint".
but what i want to do, is update a "score" variable in RunGame (i.e
RunGame.score++) in a thread that keeps checking the varaible to see if
its changed, and if it has, updatea a JTextArea.
but since RunGame created Collision, Collision cant call a method in
RunGame.

i realise this is a static problem, but i dont understand them too
well. how could i access the "score" variable from Collision.java AND
RunGame.java.

thanks for any help in advance,
duncan
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> 3D Graphics API's for Java All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.