Author Topic: Swings with JPCT  (Read 3363 times)

Offline san14

  • int
  • **
  • Posts: 60
    • View Profile
Swings with JPCT
« on: February 22, 2007, 11:03:55 am »
Hi
   I am trying to add button on JPCTDemo.jave example. Could any one tell if it is possible to add Jpct with Swings Components( Fram, Panel, Layouts...)
San14

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Swings with JPCT
« Reply #1 on: February 22, 2007, 01:34:07 pm »
The software renderer renders into an Image. You can use that in any way you like instead of using the display()-method and combine it with Swing as you would do with any other Image.
The hardware renderer runs in a native window of its own. You can not combine it with Swing.
The AWTGLRenderer renders into a special, heavyweight Canvas. You can do everything with that what can be done with any other heavyweight component.

Offline san14

  • int
  • **
  • Posts: 60
    • View Profile
Swings with JPCT
« Reply #2 on: February 23, 2007, 08:33:01 am »
HI

    I am using world object to add two Object3D with sphere and cube to them But able to see only one of those. Is there any Layout so i can decide position and area  and size of Objects3D in the World object


Code: [Select]

import java.io.File;

import org.lwjgl.opengl.Display;

import com.threed.jpct.Camera;
import com.threed.jpct.Config;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.IPostProcessor;
import com.threed.jpct.IRenderer;
import com.threed.jpct.Loader;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.World;
import com.threed.jpct.util.Light;

public class HelloWorld3 {

public static void main(String[] arg0){
     HelloWorld3 goSo=new HelloWorld3();
     goSo.creJPCTFrame();
     
}
public void creJPCTFrame(){

    FrameBuffer buffer=new FrameBuffer(800, 600,200);  
   
    buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
    buffer.enableRenderer(IRenderer.RENDERER_OPENGL);
   
    //Create an world Object  
    World world=new World();
     
  // I am createing Object3D with Shpere of size 10,
    Object3D sphere=Primitives.getPyramide(15f,5f);
   //I am adding Cube to Object3D
    Object3D cube=Primitives.getCube(5);  
   
 
   //Add the object to the world
    world.addObject(sphere);
    world.addObject(cube);
     
     
  //We need to Build The Object to be viewed
    world.buildAllObjects();
     
    //We create Object for Light
    Light light=new Light(world);
   
    //We have to set intency to light
    light.setIntensity(255, 50, 50);
     
    //We Set the light Position
    light.setPosition(new SimpleVector(0,-200,-50));      
     
   
    //We set Camera to world;
    Camera cam=world.getCamera();
       
      //Set Camera movement ...
    cam.moveCamera(Camera.CAMERA_MOVEOUT,60);
      cam.moveCamera(Camera.CAMERA_MOVEUP, 130);
       
      //This set The positon of camera to Spehere
      cam.lookAt(sphere.getTransformedCenter());
     
      cam.lookAt(cube.getTransformedCenter());
     
     while(!Display.isCloseRequested()) {
        buffer.clear();        
        world.renderScene(buffer);
        world.draw(buffer);
        buffer.update();
        buffer.displayGLOnly();
       
     }
     
       buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
       buffer.dispose();
         
       System.exit(0);
  }

}




 
Quote

                     --------------------------------------------------------
                    |                                                                      |
                    |                                                                      |
                    |                                                                      |
                    |                             Sphere                               |
                    |                                                                      |
                     --------------------------------------------------------
                    |                                                                      |
                    |                                                                      |
                    |                                                                      |
                    |                                                                      |
                    |                                   cube                            |
                    |                                                                      |
                    |                                                                      |
                    |                                                                      |
                     --------------------------------------------------------


I wanted to put sphere and cube in two different Canvas in same world.


With Regards
San
San14

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Swings with JPCT
« Reply #3 on: February 23, 2007, 01:38:29 pm »
In your example, one object contains the other because they are both located at (0,0,0). If you want to have it different, translate them to where you want them to be.
If you want them to be rendered in two different canvas', i suggest to use two different worlds instead. You may do it in one world by adjusting the camera to the cube respectively the sphere, but that makes no sense unless they should interact with each other, being rendered together in one frame or similar.

Offline san14

  • int
  • **
  • Posts: 60
    • View Profile
Swings with JPCT
« Reply #4 on: February 24, 2007, 08:35:40 am »
Hi
    I am adding two objects Sphere and cube to same world but at different positions. I have set same camera to both the object.


Am I doing in right way?

In this I have followed your first suggestion


Quote

In your example, one object contains the other because they are both located at (0,0,0). If you want to have it different, translate them to where you want them to be.



Code: [Select]

import java.io.File;

import javax.swing.JButton;

import org.lwjgl.opengl.Display;

import com.threed.jpct.Camera;
import com.threed.jpct.Config;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.IPostProcessor;
import com.threed.jpct.IRenderer;
import com.threed.jpct.Loader;
import com.threed.jpct.Matrix;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.World;
import com.threed.jpct.util.Light;

public class HelloWorld3 {

public static void main(String[] arg0){
     HelloWorld3 goSo=new HelloWorld3();
     goSo.creJPCTFrame();
     
}
public void creJPCTFrame(){

    FrameBuffer buffer=new FrameBuffer(800, 600,200);  
   
    buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
    buffer.enableRenderer(IRenderer.RENDERER_OPENGL);
     
    //Create an world Object  
    World world=new World();
 
     
   //I am createing Object3D with Shpere of size 10,
     Object3D sphere=Primitives.getPyramide(8f,5f);    
   //I am adding Cube to Object3D
     Object3D cube=Primitives.getCylinder(5) ;  
     
   
 
    //Add the object to the world
    world.addObject(sphere);
    world.addObject(cube);
   
  //I have created two Matrix object  
     Matrix m=new Matrix();
     Matrix n=new Matrix();  
   
   /**I am adding translate to Matrix object
    * This will give position to the object in the world(x,y,z)
    *  Or can say Layout to OBject Defines position to object
    */
    m.translate(0.65f,6f,5f);
    sphere.setTranslationMatrix(m);
   
    n.translate(0f,100f,5f);
    cube.setTranslationMatrix(n);
     
  //We need to Build The Object to be viewed
    world.buildAllObjects();
   
     
     //We create Object for Light
    Light light=new Light(world);
     
   
     //We have to set intency to light
    light.setIntensity(255, 50, 50);
   
     
   //We Set the light Position
    light.setPosition(new SimpleVector(0,-200,-50));
   
     
   
   //We set Camera to world;
    Camera cam=world.getCamera();
           
     //Set Camera movement ...
    cam.moveCamera(Camera.CAMERA_MOVEOUT,60);
      cam.moveCamera(Camera.CAMERA_MOVEUP, 130);
       
     
     //This set The positon of camera to Spehere
      cam.lookAt(sphere.getTransformedCenter());    
      cam.lookAt(cube.getTransformedCenter());
         
     while(!Display.isCloseRequested()) {
        buffer.clear();        
        world.renderScene(buffer);
   
        world.draw(buffer);
       
        buffer.update();
        buffer.displayGLOnly();
       
     }
     
       buffer.disableRenderer(IRenderer.RENDERER_OPENGL);
       buffer.dispose();
         
       System.exit(0);
  }

}



I will try with two different world.
Could you suggest how do I add button to world?


With Regards
San[/quote]
San14

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Swings with JPCT
« Reply #5 on: February 24, 2007, 10:45:56 am »
Well, your camera code makes no sense...You can only lookAt one entity at a time. What are multiple lookats are supposed to do? I mean you can't look forward and backward at the same time in real life either, or can you... :wink:
About the button: I've explained this above, i don't know what else i should say about it. In your example, you are using the OpenGL renderer. This is a native OpenGL window. It has absolutely nothing to do with Swing/AWT. You simply can't add a swing-button to it. You can use the AWTGLRenderer instead, which may allow this because it renders into a heavyweight canvas, but then the usually lightweight against heavyweight rules apply. You'll find some explainations about this on the web.
You may also do the button by blitting a texture that contains the image of a button. But event handling (has the user clicked the button?) is then up to you to implement. Or you can give FengGUI a try: http://www.fenggui.org/doku.php It will work when combined with jPCT. raft already did this.

Offline san14

  • int
  • **
  • Posts: 60
    • View Profile
Swings with JPCT
« Reply #6 on: February 27, 2007, 06:10:41 am »
:)  I too donít look at two side's...Thanks for your suggestion FingGui. Could you suggest more technologies by which I can create login and admin part and then I can call my JPCTDemo type example on it.


With Regards
San
San14