Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (500)
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  
  Making more easy the creation of a Canvas3D + View + Locale + main BranchGraph  (Read 727 times)
0 Members and 1 Guest are viewing this topic.
Offline Amos Wenger

Senior Member




Everything's possible, but not everything's fun...


« Posted 2006-05-23 18:56:20 »

I did a small class for my game which sum up the creation of Canvas3D + View + Locale + main BranchGraph in a few line.
Here's what it looks like when you use it :
Quote
graphic = new RenderCode(RenderCode.DisplayMode.D800x600);

graphic.lookAt(
      new Vector3f(30f, 0f, 10f),
      new Vector3f(0f, 0f, 0f),
      new Vector3f(0f, 0f, 1f)
);

graphic.getScene().addChild(new Sphere(10, 10, 2f));

while(true) {

  graphic.renderOnce();

  Thread.sleep(20L);

}

The class looks like that :
Quote
package org.stratagem.code;

import java.awt.Dimension;
import java.awt.Toolkit;

import javax.vecmath.Vector3f;

import com.xith3d.render.CanvasPeer;
import com.xith3d.render.RenderPeer;
import com.xith3d.render.jsr231.RenderPeerImpl;
import com.xith3d.scenegraph.BranchGroup;
import com.xith3d.scenegraph.Canvas3D;
import com.xith3d.scenegraph.Locale;
import com.xith3d.scenegraph.View;
import com.xith3d.scenegraph.VirtualUniverse;

public class RenderCode {

   /*
    * 3D
    */
   Canvas3D canvas;
   VirtualUniverse universe;
   View view;
   BranchGroup scene;
   Locale locale;

   public enum DisplayMode {
      D320x240,
      D640x480,
      D800x600,
      D1024x768,
      DS0,
      DS200
   };
   
   /**
    * @param mode D320x240, D640x480, D800x600, D1024x768, or DS200
    */
   public RenderCode(DisplayMode mode) {

      // Universe
      universe = new VirtualUniverse();
      view = new View();
      view.setFieldOfView(35f * 3.14f / 180f);
      locale = new Locale();
      universe.addLocale(locale);
      universe.addView(view);
      scene = new BranchGroup();
      locale.addBranchGraph(scene);

      // Canvas
      RenderPeer rp = new RenderPeerImpl();
      
      int xSize, ySize;
      Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
      
      switch(mode) {
      
      case D320x240 :
         xSize = 320; ySize = 240;
         break;
         
      case D640x480 :
         xSize = 640; ySize = 480;
         break;
         
      case D800x600 :
         xSize = 800; ySize = 600;
         break;
         
      case D1024x768 :
         xSize = 1024; ySize = 768;
         break;
         
      case DS0 :
         xSize = d.width; ySize = d.height;
         break;
         
      case DS200 :
         d = Toolkit.getDefaultToolkit().getScreenSize();
         xSize = d.width - 200; ySize = d.height - 200;
         break;
         
      default :
         return;
      
      }
      
      int xPos = d.width  / 2 - xSize / 2;
      int yPos = d.height / 2 - ySize / 2;
      
      CanvasPeer cp = rp.makeCanvas(null, xSize, ySize, 16,
            true);
      if(xPos != -1) {
         cp.setLocation(xPos, yPos);
      }
      canvas = new Canvas3D();
      canvas.set3DPeer(cp);
      canvas.setView(new View());
      view.addCanvas3D(canvas);

   }

   public Canvas3D getCanvas() {
      return canvas;
   }

   public BranchGroup getScene() {
      return scene;
   }

   public View getView() {
      return view;
   }
   
   public Locale getLocale() {
      return locale;
   }

   public void render() {
      view.renderOnce();
   }

   public void lookAt(Vector3f eye, Vector3f center, Vector3f up) {
      getView().getTransform().lookAt(eye, center, up);
   }

}

I can integrate it in Xith if some find it useful. I think it's very convenient and would be useful for people who don't mind of the details of the canvas creation.

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (50 views)
2014-04-15 18:08:23

BurntPizza (46 views)
2014-04-15 03:46:01

UprightPath (62 views)
2014-04-14 17:39:50

UprightPath (44 views)
2014-04-14 17:35:47

Porlus (61 views)
2014-04-14 15:48:38

tom_mai78101 (85 views)
2014-04-10 04:04:31

BurntPizza (143 views)
2014-04-08 23:06:04

tom_mai78101 (242 views)
2014-04-05 13:34:39

trollwarrior1 (201 views)
2014-04-04 12:06:45

CJLetsGame (208 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!