Virtual Solar System in Jave3D and Swing

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

32 Replies - 15422 Views - Last Post: 02 March 2015 - 04:35 PM

#16 PGR  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 59
  • Joined: 10-January 11

Re: Virtual Solar System in Jave3D and Swing

Posted 03 July 2013 - 09:12 PM

View Postmacosxnerd101, on 03 July 2013 - 09:03 PM, said:

Just an FYI- ArrayLists are generic. You should really be using generics with them, if for no other reason than to avoid the nasty deprecation warnings.

I trying to guess how big to make arrays. Lists let me add what I want as much as I want. Any ideas on setting the length of an array?
Was This Post Helpful? 0
  • +
  • -

#17 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12134
  • View blog
  • Posts: 45,117
  • Joined: 27-December 08

Re: Virtual Solar System in Jave3D and Swing

Posted 03 July 2013 - 09:14 PM

I'm not saying don't use ArrayLists. They're great for dynamic storage. The syntax ArrayList list = new ArrayList(); is deprecated though. ArrayLists support types, similar to arrays. For example, if you wanted to store ints in your List, you would use ArrayList<Integer> list = new ArrayList<Integer>();.

Arrays are statically sized. You can declare the size upfront:
int[] array = new int[some_length];


Was This Post Helpful? 0
  • +
  • -

#18 jon.kiparsky  Icon User is online

  • Screw Trump (before he screws you)
  • member icon


Reputation: 10625
  • View blog
  • Posts: 18,181
  • Joined: 19-March 11

Re: Virtual Solar System in Jave3D and Swing

Posted 03 July 2013 - 09:17 PM

View PostPGR, on 03 July 2013 - 11:12 PM, said:

View Postmacosxnerd101, on 03 July 2013 - 09:03 PM, said:

Just an FYI- ArrayLists are generic. You should really be using generics with them, if for no other reason than to avoid the nasty deprecation warnings.

I trying to guess how big to make arrays. Lists let me add what I want as much as I want. Any ideas on setting the length of an array?


This starts to sound like you're just guessing. Why would you want an array? Whay would you want a list? Each of these is a good structure for some purpose: what is the purpose, and what structure matches that purpose?

Arrays are described in this tutorial - read it and work the exercises, and you'll understand arrays pretty well.
Was This Post Helpful? 1
  • +
  • -

#19 PGR  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 59
  • Joined: 10-January 11

Re: Virtual Solar System in Jave3D and Swing

Posted 06 July 2013 - 12:01 PM

How do you point to mulitple jar files?
j3d used 3 jar files. I'm trying to pack them up into one jar file because the HTML ARCHIVE tag seems to only use one file. I've tried the archivelist file with all the file names - separated by commas, I've tried putting them into a lib folder, I've jared them but, it can only find one at a time.
Was This Post Helpful? 0
  • +
  • -

#20 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12134
  • View blog
  • Posts: 45,117
  • Joined: 27-December 08

Re: Virtual Solar System in Jave3D and Swing

Posted 07 July 2013 - 11:15 AM

You just add them to your project. It should be pretty straight-forward with an IDE.
Was This Post Helpful? 0
  • +
  • -

#21 PGR  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 59
  • Joined: 10-January 11

Re: Virtual Solar System in Jave3D and Swing

Posted 08 July 2013 - 10:49 AM

View Postmacosxnerd101, on 07 July 2013 - 11:15 AM, said:

You just add them to your project. It should be pretty straight-forward with an IDE.

Ok. Thanks. I'm trying to get it to run from an HTML page and it seems to take only one library. So, I had to un-jar the libraries and jar them into only one.

Also, I changed my ArrayList signatures to include a type tag. (for those who don't know what that is...)
ArrayList<Mass3D> myMass = new Mass3D<Mass3D>();
Was This Post Helpful? 0
  • +
  • -

#22 PGR  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 59
  • Joined: 10-January 11

Re: Virtual Solar System in Jave3D and Swing

Posted 09 July 2013 - 10:39 PM

I hate the java documentation!!!
I have a runtime security exception and am trying to give myself "modifyThreadGroup" permission. I think it has something to do with the runtime security manager. I added "modifyThreadGroup" to my java.policy file and it didn't work.
Can I do it with code?
I've tried all combinations below and can't figure out how to give myself that permission.

	PermissionCollection pc;
	RuntimePermission rp;
	SecurityManager sm;
	ThreadGroup tg;
	Object con;
		
	//java.permissions.allpermissions
	sm = System.getSecurityManager();
	sm.getSecurityContext();
	con = sm.getSecurityContext();
	tg = sm.getThreadGroup();
	System.out.println("tg=" + tg);

	pc = Permission.newPermissionCollection();
	setProperties(java.permission.allpermissions);
	RuntimePermission(Security.setProperty(java.permissions.allpermissions));
	rp = new RuntimePermission(System.getSecurityManager().java.permissions.allpermissions);
	rp = new RuntimePermission(java.permissions.allpermissions);//doesn't exist



Two lines of code is all I'm asking for (from java docs).
SecurityManager sm = System.SecurityManager();
sm.setPermission("modifyThreadGroup");//this doesn't work.

Can I do this programatically?
Was This Post Helpful? 0
  • +
  • -

#23 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 2386
  • View blog
  • Posts: 5,008
  • Joined: 11-December 07

Re: Virtual Solar System in Jave3D and Swing

Posted 22 July 2013 - 08:02 AM

Is this running in an applet? You're probably onto a loser trying to change security permissions. They are there to stop you from doing certain things.

Why do you think you need the thread group permission? Thread groups are not something I have ever used.
Was This Post Helpful? 0
  • +
  • -

#24 PGR  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 59
  • Joined: 10-January 11

Re: Virtual Solar System in Jave3D and Swing

Posted 22 July 2013 - 12:41 PM

The Java3D lib uses modifyThreadGroup to split the thread so it can multi-task. My program runs as an application or applet (with an applet tucked into a JFrame). I'm trying to put it on the web so my niece can see it and help me with the 3D nav. I see now that I can't programatically set security settings. I need to go to my java.policy file and set things up there. That is not working yet either.
I think I found the trick to 3D nav here.
http://www.javaworld...-3d.html?page=6
Was This Post Helpful? 0
  • +
  • -

#25 PGR  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 59
  • Joined: 10-January 11

Re: Virtual Solar System in Jave3D and Swing

Posted 05 August 2013 - 10:47 PM

I was using arrays track all the elements of my solar system. All the planets, ship, cameras get added to the list and then it gets added to the combobox for selection. I didn't want to count all the objects each time I ran the program, so I just set it to 10 elements - and had blank spaces in the dropdown box. Now, I add to a list and then copy the items to an array of the correct size. No extra spaces. I will look at the Array link, though.

I added a java.policy file with the correct permissions in my build\classes folder. Now I don't get the exceptions. I'm almost ready to put it up so you(s) can see it. The navigation is still messed up. Pressing forwards goes backwards and the rolls still don't work like I want them to.

That said, has anyone used PointLight? It just plain has no effect. I have Materials but, get no light from it. I have a DirectionalLight that lights it up but, I'm trying to use PointLight to shine from one spot like the sun. I've tried moving it closer to the Earth and no effect.

Here is the light.
	public void addLight(BranchGroup group){
		PointLight pointLight;
		BoundingSphere bounds = new BoundingSphere(new Point3d(0f, 0f, 0f), Float.MAX_VALUE);//location, radius
		//7000000f, 0f, -149590000000f
		pointLight = new PointLight(new Color3f(1f, 1f, 1f), new Point3f(0f, 0f, -149500000000f), new Point3f(1f, 1f, 1f));//color, location, attun
		//pointLight = new PointLight(new Color3f(1f, 1f, 1f), new Point3f(0f, 0f, 0f), new Point3f(1f, 1f, 1f));//color, location, attun
		//pointLight = new PointLight(new Color3f(1f, 1f, 1f), new Point3f(-300000000f, 300000000f, -149590000000f), new Point3f(1f, 1f, 1f));//color, location, attun
		//pointLight = new PointLight(new Color3f(1f, 1f, 1f), new Point3f(0f, 0f, -149590000000f), new Point3f(1f, 1f, 1f));//color, location, attun
		pointLight.setEnable(true);
		//pointLight.setInfluencingBounds(bounds);
		group.addChild(pointLight);
	}
	



Here is the planet.
public Mass3D getEarth(int i){
		Mass3D tGroup;// = new Mass3D();
		//Controllable tCont = new Controllable();
		TransformGroup tGroup2, tGroup3;
		Transform3D tTrans, tTrans2, tTrans3;
		//double[]	v = new double[16];
		double x, y, z;
		double xv, yv, zv;
		double xr, yr, zr;
		double xvr, yvr, zvr;
		float tRadius, tRadius2, tMass;
		//Vector3d	trot;
		String		tName;
		Appearance tApp, tApp2;
		ColoringAttributes ca, ca2;
		PolygonAttributes pa, pa2;
		//RotationInterpolator rotator;
		View			tV;

			//decode the mass array string data
		x  = Double.valueOf((String)myBody[i][ 3]);//x
		y  = Double.valueOf((String)myBody[i][ 4]);//y
		z  = Double.valueOf((String)myBody[i][ 5]);//z

		xr = Double.valueOf((String)myBody[i][ 9]);//xr
		yr = Double.valueOf((String)myBody[i][10]);//yr
		zr = Double.valueOf((String)myBody[i][11]);//zr

		tName = (String)myBody[i][0];
		tMass =   Float.valueOf((String)myBody[i][1]);
		tRadius = Float.valueOf((String)myBody[i][2]);//radius

		//loc, rot, vel, rotvel
		tGroup = new Mass3D(tName, tMass, tRadius, new Vector3d(x, y, z), new Vector3d(0, 0, 0), new Vector3d(xr, yr, zr), new Vector3d(0, 0, 0));
		tGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		tGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

		tGroup.updateTransform(1);

		//set up Earth
		tApp = new Appearance();
		tApp.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
		tApp.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
		ca = new ColoringAttributes();
		ca.setColor(new Color3f(0.25f, 1f, 0.25f));//green
		tApp.setColoringAttributes(ca);

		pa = new PolygonAttributes();
		pa.setPolygonMode(PolygonAttributes.POLYGON_FILL);
		tApp.setPolygonAttributes(pa);

		Material mat = new Material();
		//mat.setEmissiveColor(new Color3f(0.2f, 0.25f, 0.2f));
		mat.setAmbientColor (new Color3f(0.5f, 0.5f, 0.5f));
		mat.setDiffuseColor (new Color3f(0.5f, 0.5f, 0.5f));
		mat.setSpecularColor(new Color3f(0.5f, 0.5f, 0.5f));
		mat.setShininess(64f);
		mat.setLightingEnable(true);
		tApp.setMaterial(mat);
		tGroup.addChild(new Sphere(tRadius, Primitive.GENERATE_NORMALS, tApp));
		
		//add atmosphere
		tApp2 = new Appearance();
		ca = new ColoringAttributes();
		ca.setColor(new Color3f(0.6f, 0.8f, 1f));//light blue
		tApp2.setColoringAttributes(ca);
		//Material mat2 = new Material();
		//mat2.getDiffuseColor(new Color3f(0.6f, 0.8f, 1f));
		//tApp2.setMaterial(mat2);
		pa2 = new PolygonAttributes();//setup inside out atmosphere
		pa2.setBackFaceNormalFlip(true);//show the inside
		pa2.setCullFace(PolygonAttributes.CULL_FRONT);//show the inside
		tApp2.setPolygonAttributes(pa2);
		tGroup.addChild(new Sphere(tRadius + 450, tApp2));

		//add earth polar camera
		tGroup2 = new TransformGroup();
		tTrans2 = new Transform3D();
		tTrans2.setEuler(new Vector3d(Math.toRadians(270), Math.toRadians(0), Math.toRadians(0)));//input (xr, yr, zr), output angle and amount of rotation
		tTrans2.setTranslation(new Vector3d(0d, 25000000, 0d));//earth cam
		//tTrans2.setEuler(new Vector3d(Math.toRadians(0), Math.toRadians(270), Math.toRadians(0)));//input (xr, yr, zr), output angle and amount of rotation
		//tTrans2.setTranslation(new Vector3d(-25000000d, 0d, 0d));//earth cam
		tGroup2.setTransform(tTrans2);
		//add camera
		tV = getNewCamera(tGroup, new String("Earth polar cam"));//make camera and monitor
		monitor.add(tV.getCanvas3D(0));//add them to a panel when GUI is created
		tGroup2.addChild(tV.getViewPlatform());//add camera
		tGroup.addChild(tGroup2);//add ship

		addMass(tGroup, tName);//add to array for radar

		System.out.println("Make " + tName + " at (" + x + "," + y + "," + z + ") (r=" + tRadius + ")");
		return(tGroup);
	}


Was This Post Helpful? 0
  • +
  • -

#26 PGR  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 59
  • Joined: 10-January 11

Re: Virtual Solar System in Jave3D and Swing

Posted 29 January 2015 - 12:34 PM

So, to pick this up again...
for a = G(m2)/(x2 + y2 + z2) (2 are powers, they did not get raised when I pasted them here.) I can get some variables set.
I get to accelerate(Mass3D mass) from (below) so i only have to do one calculation for each pair of masses.
	for (int j = 0;j < mass.size();j++)
	{
		for (int i = j;i < mass.size();i++)//skip previously done masses
		{
			mass.get(j).accelerate(mass.get(i), fps);//for each other mass
	}
}


Then I want to do this
double a = 0;
double r = 0;
r = Math.sqrt((m1.location.x * m1.location.x) + (m1.location.y * m1.location.y) + (m1.location.z * m1.location.z));//a different from what you have above
a = G * m2.mass/r;

a.x = (G * this.mass * m2.mass) / Math.pow(this.location.x - m2.location.x, 2);
a.y = (G * this.mass * m2.mass) / Math.pow(this.location.x - m2.location.y, 2);
a.z = (G * this.mass * m2.mass) / Math.pow(this.location.x - m2.location.z, 2);
//add half the force to each object
this.location.add(a.div(2));
m2.location.sub(a.div(2));




On another site, someone suggested getting a dot product of the vectors, but they didn't say what do do with it.
double d = this.location.dot(m2.location);


Was This Post Helpful? 0
  • +
  • -

#27 cfoley  Icon User is offline

  • Cabbage
  • member icon

Reputation: 2386
  • View blog
  • Posts: 5,008
  • Joined: 11-December 07

Re: Virtual Solar System in Jave3D and Swing

Posted 29 January 2015 - 01:08 PM

The variable a is a double but is also trying to be a 3D coordinate.
You have at least two different things that look almost like your accelaration equation.
It looks like you're trying to add and subtract accelerations to a location which doesn't make sense to me.

The code has confused me so much that I'm not really sure what you want that snippet to do. Could you explain a bit more?
Was This Post Helpful? 0
  • +
  • -

#28 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12134
  • View blog
  • Posts: 45,117
  • Joined: 27-December 08

Re: Virtual Solar System in Jave3D and Swing

Posted 29 January 2015 - 01:15 PM

It's been a year and a half since you last posted here. Surely in that time you have learned some basic physics. It really isn't clear what you want to do or what equations you have been pointed to. If you don't understand the physics though, it's a good bet that you'll struggle with the code. It's a good assumption that we (as a coding forum) are not physics experts. :)
Was This Post Helpful? 0
  • +
  • -

#29 PGR  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 59
  • Joined: 10-January 11

Re: Virtual Solar System in Jave3D and Swing

Posted 29 January 2015 - 07:40 PM

First of all, thanks for looking at it.
It's actually very easy (though I may have written it wrong. Ack! I did. I should have added a to the velocity).
It seems the physics people (on wiki, i.e.) don't do coding (and the coding people don't do physics) :( or ;)
x = x + xv;//moves location by masses velocity.
ax = (get the force of gravity on the x dimension)
xv += ax;//effect the velocity by the force of gravity


Then to put it in three dimensions, I use vectors to hold all the 3-part variables (Tuple3ds)
Vector3d location, velocity, rotation, rotVel, acceleration;//all init-ed to some number
//then add the velocities
location.add(velocity);
rotation.add(rotVel);


It looks like this
//in main's run()
for (int j = 0;j < mass.size();j++)
{
	for (int i = j;i < mass.size();i++)//skip previously done masses
	{
		mass.get(j).accelerate(mass.get(i));//for this mass, get effect on and of other masses 
	}
}
for (int i = 0;i < mass.size();i++)
{
	mass.get(i).move(fps);
}

public void accelerate(Mass3D m2)
{
	acceleration.x = (effect of gravity on x dimension)
	acceleration.y = (effect of gravity on y dimension)
	acceleration.z = (effect of gravity on z dimension)

	velocity.add(acceleration);
}
public void move(double fps)
{
	//divide velocity and rotVel by fps if not zero
	//I should divide the total force between each mass
	rotation.add(rotVel);
	location.add(velocity);
}


It's an experiment in physics. Can I make a solar system with planets that orbit the sun? Can a ship orbit the earth? - without tables or forcing the numbers. The Earth orbiting the sun just floats with a small effect of the gravity of the Sun at every moment. Everything has a velocity in 3D and gravity effects the velocity. I've seen people doing the n-body simulation that track hundreds of objects - I'll look into what they do again and talk to them as well.
There is another module in my project, with spreadsheet where you can play with all the formulas - force of gravity, rotational velocity, what happens if you change the mass or speed or gravity, etc...
I hope this helps.
Was This Post Helpful? 0
  • +
  • -

#30 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12134
  • View blog
  • Posts: 45,117
  • Joined: 27-December 08

Re: Virtual Solar System in Jave3D and Swing

Posted 29 January 2015 - 09:34 PM

Quote

It's actually very easy (though I may have written it wrong. Ack! I did. I should have added a to the velocity).
It seems the physics people (on wiki, i.e.) don't do coding (and the coding people don't do physics)

I might add that we're probably not the best people to be guessing at equations here. If you have some equations and clearly describe them, we can help. Or if you can point to sources that explain them, we can probably help. But we're probably not the best people to guess where the physics people meant for you to apply the dot product and result.
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3