mudi12 -3

Hello

I am student of BSCS 4th Semester.
we studied basics of java in OOP subject
i want to make a 3D Paint in java simple free hand diagrams
by using sphere..
drawing on different coordinates..

``````/**
*
* @author MuDi
*/
import com.sun.j3d.utils.geometry.*;

import com.sun.j3d.utils.universe.*;
import java.util.Scanner;

import javax.media.j3d.*;

import javax.vecmath.*;

public class Position {
boolean flag=true;
public Position() {
boolean ch = true;
while(ch)
{
SimpleUniverse universe = new SimpleUniverse();

BranchGroup group = new BranchGroup();

// X axis made of spheres

//for (float x = -1.0f; x <= 1.0f; x = x + 0.0005f)

Color3f light1Color = new Color3f(.1f, 1.4f, .1f); // green light

BoundingSphere bounds =

new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);

Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);

DirectionalLight light1

= new DirectionalLight(light1Color, light1Direction);

light1.setInfluencingBounds(bounds);
universe.getViewingPlatform().setNominalViewingTransform();

Sphere sphere = new Sphere(0.05f);
TransformGroup tg = new TransformGroup();
Scanner sc = new Scanner(System.in);
float a = sc.nextFloat();
float b = sc.nextFloat();
float c = sc.nextFloat();
int ac = sc.nextInt();
if(ac==0)
{
ch=false;
}
Transform3D transform = new Transform3D();

Vector3f vector = new Vector3f( a, b, c);

transform.setTranslation(vector);

tg.setTransform(transform);

group.removeAllChildren();

// add the group of objects to the Universe

//universe.getCanvas().invalidate();
//universe.getCanvas().validate();

}

}

public static void main(String[] args) {

new Position();

}

}``````

I tried this
it draw one sphere but when i enter 2nd.. it gives me error

it will be usefull for me in some 3d project in future..

and if there is some other method of 3d drawing (free hand) which draw points on each coordinate given.. please let me know i want to learn this..

Thanks alot

JamesCherrill 3,661

it draw one sphere but when i enter 2nd.. it gives me error

It would help if you told us exactly what the error was.

mudi12 -3

``````/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package XML;

/**
*
* @author MuDi
*/
import com.sun.j3d.utils.geometry.*;

import com.sun.j3d.utils.universe.*;
import java.util.Scanner;

import javax.media.j3d.*;

import javax.vecmath.*;

public class Position {
boolean flag=true;
public Position() {
boolean ch = true;
SimpleUniverse universe = new SimpleUniverse();

BranchGroup group = new BranchGroup();

Color3f light1Color = new Color3f(.1f, 1.4f, .1f); // green light

BoundingSphere bounds =

new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);

Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);

DirectionalLight light1

= new DirectionalLight(light1Color, light1Direction);

light1.setInfluencingBounds(bounds);
universe.getViewingPlatform().setNominalViewingTransform();

while(ch)
{

Sphere sphere = new Sphere(0.05f);
TransformGroup tg = new TransformGroup();
Scanner sc = new Scanner(System.in);
float a = sc.nextFloat();
float b = sc.nextFloat();
float c = sc.nextFloat();
int ac = sc.nextInt();
if(ac==0)
{
ch=false;
}
Transform3D transform = new Transform3D();

Vector3f vector = new Vector3f( a, b, c);

transform.setTranslation(vector);

tg.setTransform(transform);

}

}

public static void main(String[] args) {

new Position();

}

}``````

1st Code is wrong this one is correct.

I face this error when i input coordinates for second sphere

Exception in thread "main" javax.media.j3d.RestrictedAccessException: Group: only a BranchGroup node may be added
at XML.Position.<init>(Position.java:67)
at XML.Position.main(Position.java:80)

NormR1 563

RestrictedAccessException: Group: only a BranchGroup node may be added

Have you read the API doc for the method you are trying to use? group.addChild(tg);
And for the Exception you are getting?
The message seems pretty specific.

mudi12 -3

Thanks ;)
i resolved my problem

msi_333

can you please post the code after resolving the problem .

mudi12 -3

``````group.setCapability(BranchGroup.ALLOW_DETACH);
group.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
group.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);

BranchGroup temp = new BranchGroup();
Sphere sphere = new Sphere(0.02f);
TransformGroup tg = new TransformGroup();
Transform3D transform = new Transform3D();

Vector3f vector = new Vector3f( a,b,0.5f);
transform.setTranslation(vector);

tg.setTransform(transform);