Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - tony-kun

Pages: [1]
1
Support / problem with uv coordinates
« on: February 06, 2013, 04:47:55 pm »
Hi, first of all, thanks very much for this software. I played a little with this 3d thing with jpct some time ago, but now I started to do a complete game.

I have encountered several (and very basic) problems. Perhaps I must be doing something very wrong. The first problem, is that normally when I use uv coordinates greater than 10 or so, I get strange graphics. I post an example. This example uses one of the textures in tp.zip downloadable from the page.

I'm using the latest jpct (1.26). The same problem happens with previous version.

Code: [Select]
import com.threed.jpct.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;

public class Prueba extends JFrame implements Runnable
{

private World world;
private FrameBuffer buffer;

private boolean finish = false;

public static void main(String[] args)throws Exception
{
    Prueba p = new Prueba();
    p.setSize(800, 600);

    p.initWorld(800, 600);//new MyPanel());//(JPanel)p.getContentPane().getComponent(0));
    p.setVisible(true);
   
    new Thread(p).start();
}

public Prueba()
{
    getContentPane().add(new MyPanel(), java.awt.BorderLayout.CENTER);

    setUndecorated(true);

    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    this.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent ev) {
            finish = true;
        }
    });
}

public void initWorld(int sizeX, int sizeY)throws Exception//JPanel panel)throws Exception
{
    world = new World();
    world.setAmbientLight(255, 255, 255);

    File f = new File("expo_stones2.png");
    System.out.println(f.getAbsolutePath());
    BufferedImage img = ImageIO.read(f);
    TextureManager.getInstance().addTexture("stones", new Texture(img));

    Object3D grass = new Object3D(2);

    float factorX = 20;
    float factorY = 20;

    grass.addTriangle(getSV(0, 0, 0), 0, factorY, getSV(50, 0, 0), factorX, factorY, getSV(50, 50, 0), factorX, 0,
            TextureManager.getInstance().getTextureID("stones"));
    grass.addTriangle(getSV(50, 50, 0), factorX, 0, getSV(0, 50, 0), 0, 0, getSV(0, 0, 0), 0, factorY,
            TextureManager.getInstance().getTextureID("stones"));

    grass.build();
    world.addObject(grass);

    world.getCamera().setPosition(getSV(-3, -3, 10));
    world.getCamera().lookAt(getSV(10, 10, 0));

    buffer = new FrameBuffer(sizeX, sizeY, FrameBuffer.SAMPLINGMODE_NORMAL);
    buffer.enableRenderer(IRenderer.RENDERER_SOFTWARE);
}

public void run()
{
    while (!finish)
    {
buffer.clear(new Color(0, 100, 255));
world.renderScene(buffer);
world.draw(buffer);
buffer.update();
        repaint();//buffer.display(getContentPane().getGraphics());
try
        { Thread.sleep(10); }
        catch (Exception e) {}
    }
    setVisible(false);
    dispose();
    System.exit(0);
}

public SimpleVector getSV (float x, float y, float z)
{
    return new SimpleVector(x, -z, y);
}

class MyPanel extends JPanel
{
    public void paintComponent(Graphics g)
    {
        buffer.display(g);
    }
}

}

2
Support / how to obtain selected triangle
« on: February 22, 2009, 12:00:57 am »
Hi! I will get fun starting a 3d game project. jcpt is the first engine am trying and looks very nice all this. Not worrying about the 3d stuff and filling textures so easly is so great.. But one thing I miss is obtaining the original triangle of a 2d position in the screen. Something like:

int idTriangle = Interact2D.getTriangleID(r);

off course triangles when adding them they should have an unique global id in addittion to just a local to the object.

May be am missing something. Otherwise, how do you know which face of an object the user points to?

A drastic solution could be definind an object for every face. But I don't think that's normal.

Many thanks for any help.

Pages: [1]