Está en la página 1de 31

Unidad 3:Trabajando API grafica

Presentado Por:
Eddie Enrique Leudo - Código: 1.077.460.105

Presentado a:
Tutor:
Celso Javier Rodriguez Pizza

Grupo Colaborativo:  299210_22

Universidad Nacional Abierta Y A Distancia – Unad


Escuela De Ciencias Básicas, Tecnología E Ingeniería
Computación grafica
Mayo 2020
DESARROLLO PASO 4

TIPO DE ACTIVIDAD: Individual

IMAGENES DE LA SOLUCION PROPUESTA

En el siguiente cuadro se debe presentar 5 imágenes (pantallazos) de la


solución propuesta.
Código de la solución propuesta comentado cada transformación de las
imágenes.

Aplicación banana

//Autor:Eddie Enrique Leudo Asprilla


//Institucion:UNAD

package aplicacion;

import java.awt.GraphicsConfiguration;

import com.sun.j3d.loaders.objectfile.ObjectFile;

import com.sun.j3d.loaders.Scene;

import java.applet.Applet;

import java.awt.BorderLayout;

import java.awt.GraphicsConfiguration;

import com.sun.j3d.utils.applet.MainFrame;

import com.sun.j3d.utils.image.TextureLoader;

import com.sun.j3d.utils.universe.*;

import java.io.*;

import javax.media.j3d.*;

import javax.vecmath.*;

public class uvas extends Applet {

private SimpleUniverse Universe = null;

private Canvas3D canvas = null;

public uvas () {

setLayout(new BorderLayout());
GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();

canvas = new Canvas3D(config);

add("Center", canvas);

Universe = new SimpleUniverse(canvas);

//El siquiente codigo es para crear una escena simple

BranchGroup scene = createSceneGraph();

Universe.getViewingPlatform().setNominalViewingTransform();

Universe.addBranchGraph(scene);

private BranchGroup createSceneGraph() {

BranchGroup objRoot = new BranchGroup();

BoundingSphere bounds = new BoundingSphere(new Point3d(0, 0, 0),


1000);

//Cargamos textura...

TextureLoader bgtexture = new


TextureLoader("C:\\Users\\eddie\\OneDrive\\Documentos\\NetBeansProjects\\
Aplicacion\\src\\img\\Fondo_uvas.png", this);

Background bg = new Background(bgtexture.getImage());

bg.setImageScaleMode(Background.SCALE_FIT_ALL);
bg.setApplicationBounds(bounds);

objRoot.addChild(bg);

objRoot.addChild(createBlades());

objRoot.addChild(createLight());

return objRoot;

//Para realizar la transformacion codificamos...

public BranchGroup createBlades() {

BranchGroup objRoot = new BranchGroup();

TransformGroup tg = new TransformGroup();

Transform3D t3d = new Transform3D();

t3d.setTranslation(new Vector3d(0.0, 0.1, -1));

t3d.setScale(0.08);

tg.setTransform(t3d);

TransformGroup vp = new TransformGroup();

vp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

vp.addChild(createObjLoad("C:\\Users\\eddie\\OneDrive\\Documentos\\NetBe
ansProjects\\Aplicacion\\src\\img\\10181_Grape-L2.obj"));

Alpha alpha = new Alpha(-1, 20000);


Transform3D axis = new Transform3D();

axis.setRotation(new AxisAngle4f(1.3f, 8.0f, 7.0f, 8.0f));

RotationInterpolator rotator = new RotationInterpolator (alpha, vp, axis,


0.0f, (float) Math.PI * (6.0f));

BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0,


0.0), 2000.0);

rotator.setSchedulingBounds(bounds);

vp.addChild(rotator);

tg.addChild(vp);

objRoot.addChild(tg);

objRoot.addChild(createLight());

objRoot.compile();

return objRoot;

private BranchGroup createObjLoad (String filename) {

BranchGroup objRoot = new BranchGroup();

TransformGroup tg = new TransformGroup();

ObjectFile loader = new ObjectFile();

Scene s = null;
File file = new java.io.File(filename);

try {

s = loader.load(file.toURI().toURL());

} catch (Exception e){

System.err.println(e);

System.exit(1);

tg.addChild(s.getSceneGroup());

objRoot.addChild(tg);

objRoot.compile();

return objRoot;

private Light createLight(){

DirectionalLight light = new DirectionalLight(true, new Color3f(1.0f,


1.0f,1.0f), new Vector3f(0-3f,0.2f, -1.0f));

light.setInfluencingBounds(new BoundingSphere(new Point3d(),1000.0));

return light;

}
public static void main (String[] args){

uvas applet = new uvas ();

MainFrame frame = new MainFrame (applet, 1060, 600);

Aplicación cebolla

//Autor:Eddie Enrique Leudo Asprilla

//Institucion:UNAD

package aplicacion;

import java.awt.GraphicsConfiguration;

import com.sun.j3d.loaders.objectfile.ObjectFile;

import com.sun.j3d.loaders.Scene;

import java.applet.Applet;

import java.awt.BorderLayout;

import java.awt.GraphicsConfiguration;

import com.sun.j3d.utils.applet.MainFrame;

import com.sun.j3d.utils.image.TextureLoader;

import com.sun.j3d.utils.universe.*;

import java.io.*;

import javax.media.j3d.*;

import javax.vecmath.*;

public class cebolla extends Applet {


private SimpleUniverse Universe = null;

private Canvas3D canvas = null;

public cebolla () {

setLayout(new BorderLayout());

GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();

canvas = new Canvas3D(config);

add("Center", canvas);

Universe = new SimpleUniverse(canvas);

//El siquiente codigo es para crear una escena simple

BranchGroup scene = createSceneGraph();

Universe.getViewingPlatform().setNominalViewingTransform();

Universe.addBranchGraph(scene);

private BranchGroup createSceneGraph() {

BranchGroup objRoot = new BranchGroup();


BoundingSphere bounds = new BoundingSphere(new Point3d(0, 0, 0),
1000);

//Cargamos textura...

TextureLoader bgtexture = new


TextureLoader("C:\\Users\\eddie\\OneDrive\\Documentos\\NetBeansProjects\\
Aplicacion\\src\\img\\Fondo_cebolla.png", this);

Background bg = new Background(bgtexture.getImage());

bg.setImageScaleMode(Background.SCALE_FIT_ALL);

bg.setApplicationBounds(bounds);

objRoot.addChild(bg);

objRoot.addChild(createBlades());

objRoot.addChild(createLight());

return objRoot;

//Para realizar la transformacion codificamos...

public BranchGroup createBlades() {

BranchGroup objRoot = new BranchGroup();

TransformGroup tg = new TransformGroup();

Transform3D t3d = new Transform3D();

t3d.setTranslation(new Vector3d(-0.0, 0.1, -1));

t3d.setScale(0.040);

tg.setTransform(t3d);
TransformGroup vp = new TransformGroup();

vp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

vp.addChild(createObjLoad("C:\\Users\\eddie\\OneDrive\\Documentos\\NetBe
ansProjects\\Aplicacion\\src\\img\\18462_English_Onion_Bottle_v1.obj"));

Alpha alpha = new Alpha(-1, 20000);

Transform3D axis = new Transform3D();

axis.setRotation(new AxisAngle4f(1.3f, 8.0f, 7.0f, 8.0f));

RotationInterpolator rotator = new RotationInterpolator (alpha, vp, axis,


0.0f, (float) Math.PI * (6.0f));

BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0,


0.0), 2000.0);

rotator.setSchedulingBounds(bounds);

vp.addChild(rotator);

tg.addChild(vp);

objRoot.addChild(tg);

objRoot.addChild(createLight());

objRoot.compile();

return objRoot;

}
private BranchGroup createObjLoad (String filename) {

BranchGroup objRoot = new BranchGroup();

TransformGroup tg = new TransformGroup();

ObjectFile loader = new ObjectFile();

Scene s = null;

File file = new java.io.File(filename);

try {

s = loader.load(file.toURI().toURL());

} catch (Exception e){

System.err.println(e);

System.exit(1);

tg.addChild(s.getSceneGroup());

objRoot.addChild(tg);

objRoot.compile();

return objRoot;

private Light createLight(){


DirectionalLight light = new DirectionalLight(true, new Color3f(1.0f,
1.0f,1.0f), new Vector3f(0-3f,0.2f, -1.0f));

light.setInfluencingBounds(new BoundingSphere(new Point3d(),1000.0));

return light;

public static void main (String[] args){

cebolla applet = new cebolla ();

MainFrame frame = new MainFrame (applet, 1060, 600);

Aplicación Limón

//Autor:Eddie Enrique Leudo Asprilla

//Institucion:UNAD

package aplicacion;

import java.awt.GraphicsConfiguration;

import com.sun.j3d.loaders.objectfile.ObjectFile;

import com.sun.j3d.loaders.Scene;

import java.applet.Applet;

import java.awt.BorderLayout;

import java.awt.GraphicsConfiguration;

import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.image.TextureLoader;

import com.sun.j3d.utils.universe.*;

import java.io.*;

import javax.media.j3d.*;

import javax.vecmath.*;

public class limon extends Applet {

private SimpleUniverse Universe = null;

private Canvas3D canvas = null;

public limon () {

setLayout(new BorderLayout());

GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();

canvas = new Canvas3D(config);

add("Center", canvas);

Universe = new SimpleUniverse(canvas);

//El siquiente codigo es para crear una escena simple

BranchGroup scene = createSceneGraph();

Universe.getViewingPlatform().setNominalViewingTransform();

Universe.addBranchGraph(scene);
}

private BranchGroup createSceneGraph() {

BranchGroup objRoot = new BranchGroup();

BoundingSphere bounds = new BoundingSphere(new Point3d(0, 0, 0),


1000);

//Cargamos textura...

TextureLoader bgtexture = new


TextureLoader("C:\\Users\\eddie\\OneDrive\\Documentos\\NetBeansProjects\\
Aplicacion\\src\\img\\Fondo_limon.png", this);

Background bg = new Background(bgtexture.getImage());

bg.setImageScaleMode(Background.SCALE_FIT_ALL);

bg.setApplicationBounds(bounds);

objRoot.addChild(bg);

objRoot.addChild(createBlades());

objRoot.addChild(createLight());

return objRoot;

//Para realizar la transformacion codificamos...

public BranchGroup createBlades() {


BranchGroup objRoot = new BranchGroup();

TransformGroup tg = new TransformGroup();

Transform3D t3d = new Transform3D();

t3d.setTranslation(new Vector3d(0.0, 0.1, -1));

t3d.setScale(0.08);

tg.setTransform(t3d);

TransformGroup vp = new TransformGroup();

vp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

vp.addChild(createObjLoad("C:\\Users\\eddie\\OneDrive\\Documentos\\NetBe
ansProjects\\Aplicacion\\src\\img\\10186_Lemon.obj"));

Alpha alpha = new Alpha(-1, 20000);

Transform3D axis = new Transform3D();

axis.setRotation(new AxisAngle4f(1.3f, 8.0f, 7.0f, 8.0f));

RotationInterpolator rotator = new RotationInterpolator (alpha, vp, axis,


0.0f, (float) Math.PI * (6.0f));

BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0,


0.0), 2000.0);

rotator.setSchedulingBounds(bounds);

vp.addChild(rotator);

tg.addChild(vp);
objRoot.addChild(tg);

objRoot.addChild(createLight());

objRoot.compile();

return objRoot;

private BranchGroup createObjLoad (String filename) {

BranchGroup objRoot = new BranchGroup();

TransformGroup tg = new TransformGroup();

ObjectFile loader = new ObjectFile();

Scene s = null;

File file = new java.io.File(filename);

try {

s = loader.load(file.toURI().toURL());

} catch (Exception e){

System.err.println(e);

System.exit(1);

tg.addChild(s.getSceneGroup());

objRoot.addChild(tg);

objRoot.compile();
return objRoot;

private Light createLight(){

DirectionalLight light = new DirectionalLight(true, new Color3f(1.0f,


1.0f,1.0f), new Vector3f(0-3f,0.2f, -1.0f));

light.setInfluencingBounds(new BoundingSphere(new Point3d(),1000.0));

return light;

public static void main (String[] args){

limon applet = new limon ();

MainFrame frame = new MainFrame (applet, 1060, 600);

Aplicación mango

//Autor:Eddie Enrique Leudo Asprilla

//Institucion:UNAD

package aplicacion;
import java.awt.GraphicsConfiguration;

import com.sun.j3d.loaders.objectfile.ObjectFile;

import com.sun.j3d.loaders.Scene;

import java.applet.Applet;

import java.awt.BorderLayout;

import java.awt.GraphicsConfiguration;

import com.sun.j3d.utils.applet.MainFrame;

import com.sun.j3d.utils.image.TextureLoader;

import com.sun.j3d.utils.universe.*;

import java.io.*;

import javax.media.j3d.*;

import javax.vecmath.*;

public class mango extends Applet {

private SimpleUniverse Universe = null;

private Canvas3D canvas = null;

public mango () {

setLayout(new BorderLayout());

GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();

canvas = new Canvas3D(config);

add("Center", canvas);
Universe = new SimpleUniverse(canvas);

//El siquiente codigo es para crear una escena simple

BranchGroup scene = createSceneGraph();

Universe.getViewingPlatform().setNominalViewingTransform();

Universe.addBranchGraph(scene);

private BranchGroup createSceneGraph() {

BranchGroup objRoot = new BranchGroup();

BoundingSphere bounds = new BoundingSphere(new Point3d(0, 0, 0),


1000);

//Cargamos textura...

TextureLoader bgtexture = new


TextureLoader("C:\\Users\\eddie\\OneDrive\\Documentos\\NetBeansProjects\\
Aplicacion\\src\\img\\Fondo_mango.png", this);

Background bg = new Background(bgtexture.getImage());

bg.setImageScaleMode(Background.SCALE_FIT_ALL);

bg.setApplicationBounds(bounds);

objRoot.addChild(bg);

objRoot.addChild(createBlades());
objRoot.addChild(createLight());

return objRoot;

//Para realizar la transformacion codificamos...

public BranchGroup createBlades() {

BranchGroup objRoot = new BranchGroup();

TransformGroup tg = new TransformGroup();

Transform3D t3d = new Transform3D();

t3d.setTranslation(new Vector3d(0.0, 0.1, -1));

t3d.setScale(0.08);

tg.setTransform(t3d);

TransformGroup vp = new TransformGroup();

vp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

vp.addChild(createObjLoad("C:\\Users\\eddie\\OneDrive\\Documentos\\NetBe
ansProjects\\Aplicacion\\src\\img\\10190_Mango-L3.obj"));

Alpha alpha = new Alpha(-1, 20000);

Transform3D axis = new Transform3D();

axis.setRotation(new AxisAngle4f(1.3f, 8.0f, 7.0f, 8.0f));


RotationInterpolator rotator = new RotationInterpolator (alpha, vp, axis,
0.0f, (float) Math.PI * (6.0f));

BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0,


0.0), 2000.0);

rotator.setSchedulingBounds(bounds);

vp.addChild(rotator);

tg.addChild(vp);

objRoot.addChild(tg);

objRoot.addChild(createLight());

objRoot.compile();

return objRoot;

private BranchGroup createObjLoad (String filename) {

BranchGroup objRoot = new BranchGroup();

TransformGroup tg = new TransformGroup();

ObjectFile loader = new ObjectFile();

Scene s = null;

File file = new java.io.File(filename);

try {

s = loader.load(file.toURI().toURL());
} catch (Exception e){

System.err.println(e);

System.exit(1);

tg.addChild(s.getSceneGroup());

objRoot.addChild(tg);

objRoot.compile();

return objRoot;

private Light createLight(){

DirectionalLight light = new DirectionalLight(true, new Color3f(1.0f,


1.0f,1.0f), new Vector3f(0-3f,0.2f, -1.0f));

light.setInfluencingBounds(new BoundingSphere(new Point3d(),1000.0));

return light;

public static void main (String[] args){

mango applet = new mango ();

MainFrame frame = new MainFrame (applet, 1060, 600);


}

Aplicación uvas

//Autor:Eddie Enrique Leudo Asprilla

//Institucion:UNAD

package aplicacion;

import java.awt.GraphicsConfiguration;

import com.sun.j3d.loaders.objectfile.ObjectFile;

import com.sun.j3d.loaders.Scene;

import java.applet.Applet;

import java.awt.BorderLayout;

import java.awt.GraphicsConfiguration;

import com.sun.j3d.utils.applet.MainFrame;

import com.sun.j3d.utils.image.TextureLoader;

import com.sun.j3d.utils.universe.*;

import java.io.*;

import javax.media.j3d.*;

import javax.vecmath.*;

public class uvas extends Applet {

private SimpleUniverse Universe = null;

private Canvas3D canvas = null;


public uvas () {

setLayout(new BorderLayout());

GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();

canvas = new Canvas3D(config);

add("Center", canvas);

Universe = new SimpleUniverse(canvas);

//El siquiente codigo es para crear una escena simple

BranchGroup scene = createSceneGraph();

Universe.getViewingPlatform().setNominalViewingTransform();

Universe.addBranchGraph(scene);

private BranchGroup createSceneGraph() {

BranchGroup objRoot = new BranchGroup();

BoundingSphere bounds = new BoundingSphere(new Point3d(0, 0, 0),


1000);

//Cargamos textura...
TextureLoader bgtexture = new
TextureLoader("C:\\Users\\eddie\\OneDrive\\Documentos\\NetBeansProjects\\
Aplicacion\\src\\img\\Fondo_uvas.png", this);

Background bg = new Background(bgtexture.getImage());

bg.setImageScaleMode(Background.SCALE_FIT_ALL);

bg.setApplicationBounds(bounds);

objRoot.addChild(bg);

objRoot.addChild(createBlades());

objRoot.addChild(createLight());

return objRoot;

//Para realizar la transformacion codificamos...

public BranchGroup createBlades() {

BranchGroup objRoot = new BranchGroup();

TransformGroup tg = new TransformGroup();

Transform3D t3d = new Transform3D();

t3d.setTranslation(new Vector3d(0.0, 0.1, -1));

t3d.setScale(0.08);

tg.setTransform(t3d);

TransformGroup vp = new TransformGroup();

vp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
vp.addChild(createObjLoad("C:\\Users\\eddie\\OneDrive\\Documentos\\NetBe
ansProjects\\Aplicacion\\src\\img\\10181_Grape-L2.obj"));

Alpha alpha = new Alpha(-1, 20000);

Transform3D axis = new Transform3D();

axis.setRotation(new AxisAngle4f(1.3f, 8.0f, 7.0f, 8.0f));

RotationInterpolator rotator = new RotationInterpolator (alpha, vp, axis,


0.0f, (float) Math.PI * (6.0f));

BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0,


0.0), 2000.0);

rotator.setSchedulingBounds(bounds);

vp.addChild(rotator);

tg.addChild(vp);

objRoot.addChild(tg);

objRoot.addChild(createLight());

objRoot.compile();

return objRoot;

private BranchGroup createObjLoad (String filename) {

BranchGroup objRoot = new BranchGroup();


TransformGroup tg = new TransformGroup();

ObjectFile loader = new ObjectFile();

Scene s = null;

File file = new java.io.File(filename);

try {

s = loader.load(file.toURI().toURL());

} catch (Exception e){

System.err.println(e);

System.exit(1);

tg.addChild(s.getSceneGroup());

objRoot.addChild(tg);

objRoot.compile();

return objRoot;

private Light createLight(){

DirectionalLight light = new DirectionalLight(true, new Color3f(1.0f,


1.0f,1.0f), new Vector3f(0-3f,0.2f, -1.0f));

light.setInfluencingBounds(new BoundingSphere(new Point3d(),1000.0));


return light;

public static void main (String[] args){

uvas applet = new uvas ();

MainFrame frame = new MainFrame (applet, 1060, 600);

Recuerde que también debe hacer entrega de la carpeta con el


proyecto desarrollado en JAVA.

R/ Realizado

También podría gustarte