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 - AGP

Pages: 1 ... 10 11 [12] 13 14 15
Support / Adding Publishing Date to Download Site
« on: October 11, 2010, 04:46:17 am »
Just so we can know whether we have the latest version without manually running jPCT. It'll probably save you some bandwidth by reducing the number of times the same version gets downloaded.

Support / What's the best Android-powered phone for jPCT?
« on: October 08, 2010, 05:25:15 pm »
Please give me a few names as well as, if there is a clear one, the very best.

Support / Max Camera Matrix to JPCT
« on: September 24, 2010, 05:12:42 pm »
The following have been my attempts at converting 3ds max's camera matrix into jPCT's. None have worked (and I've since forgotten the Maxscript to even get the camera's matrix!). Anyway, if anyone could help with this I would really appreciate it.

Code: [Select]
      private Matrix convertMaxToJpctMatrix(Matrix toConvert) {
Matrix newMatrix = new Matrix(toConvert);
Matrix transformer = new Matrix();
float[] transformerValues = {1f, 0f, 0f, 0f,0f, 0f, -1f, 0f,0f, 1f, 0f, 0f,0f,0f,0f,1f};
// float[] transformerValues = {1f, 0f, 0f, 0f, 0f, -1f, 0f, 0f, 0f, 0f, -1f, 0f, 0f,0f,0f,1f};
[ 1 0 0 ]
[ 0 0 1 ]
[ 0 1 0 ]*/
 1  0  0  0
 0  0 -1  0
 0  1  0  0
 0  0  0  1
 0  -1  0  0
 0  0 -1  0
 1  0  0  0
 0  0  0  1
1.0     -0.0    0.0     0.0
0.0     -1.0    0.0f     0.0
0.0     0.0f    -1.0    0.0
0.0     0.0     0.0     1.0
// transformer.matMul(newMatrix);
return newMatrix;

Support / Object3D.setShadingMode(SHADING_FAKED_FLAT) is Broken...
« on: September 09, 2010, 06:28:52 am »
...probably. I meant to tell you this months ago, when I first figured out what was breaking my game in some computers. If I remember correctly, it made the billboarded planes appear completely black. But only on certain computers (the ones I had tested it on when I first added the line worked fine).

Support / Any Way to Speed Up the OBJ Importer?
« on: August 28, 2010, 07:41:27 am »
Egon, I know OBJ is ASCII rather than binary, but are you sure it's being read as quickly as possible? For static objects, OBJ is by far the most useful format that jpct reads (unlike 3DS, it's not improperly rotated and it doesn't have the 8.3 texture name limitation). Plus Max has an absolutely kick-ass exporter that converts and rescales all of its textures to your desired format. The problem is that it takes SO VERY LONG to import a 70,000-poly city with it.

I'm writing a MD2 fixer (sometimes an animation is short a frame and the next, therefore, has one too many). Since I decided to use jPCT so we can see the changes in real-time, it would be helpful if I could have the above-mentioned methods to work with, lest I be forced to identify the animation names and lengths from the MD2 bytes themselves.

Support / Object3D.getNumberOfChildren() && Object3D.getChild(int)
« on: May 18, 2010, 12:25:20 am »
Egon, could you write those for a static method I'm working on? Thanks in advance.

I'm trying to write a widget whose background is transparent and, to do so, I need to be able to set the pixels alpha values. Since the transparency isn't working, I'm starting to question whether the FrameBuffer ignores its alpha value. Please help, Egon, I really need this to work!

Support / Object3D.checkForCollision(Object3D)...
« on: March 10, 2010, 07:38:45 pm »
...would be extremely helpful so I could hold the primitive I'm using for my collision-detection, and, when having problems, (as I am now), I could draw it and know where it is. VERY helpful for debugging. Please?

Support / Order of the Values in the Matrix
« on: March 05, 2010, 09:47:05 pm »
I'm trying to convert between Max's camera matrix to jPCT (which, by the way, will make for a good Wiki). Problem is that the documentation doesn't specify how the matrices are arranged (just that it's a 4x4 matrix), and jPCT's matrix doesn't match Max's. So, what is the order?

Support / Projector Class Isn't Working
« on: February 28, 2010, 12:38:13 am »
And the mirrorCamera is looking the right way! The following doesn't do anything other than paint the mirror's plane yellow:

Code: [Select]
Projector mirrorCamera = new Projector();
TextureManager.getInstance().addTexture("Mirror", new Texture(256, 256, Color.yellow));
TextureManager.getInstance().getTexture("Mirror").setProjector(mirrorCamera, true);

I'm just going to use the projector as a camera, render into an Image's graphics, then replace the texture on my mirror, or is that WAY too stupid (expensive) a method? But either way, as I understand it I would need this for the software renderer anyway.

Support / MD5 Importer I'm Porting
« on: February 23, 2010, 05:59:36 pm »
Got this far an hour ago: will try to attach to Raft's bones now and hopefully fix the distortion. On the left is the distorted model with texture coordinates. And on the right, it's the model in Max.

Support / Lightsaber Test
« on: October 22, 2009, 07:28:17 pm »
I was going to put this little example in the wiki anyway, but something strange is happening. The very simple premise is that at 0-degree x rotation, the lightsaber pointed up, the lightsaber's blade (a transparent plane on top of a 3d cylinder) is at its full height. At 90 degrees, it's invisible. So for every degree you rotate it, it shrinks height/90. That was going to work for the first 90 degrees, and I would apply it appropriately for each of the other three sets of 90, and then apply it on the second axis (it never needs to rotate on all 3). To prove that everything works I'm drawing squares around the edges of the blade and I wrote a shrinkOrGrow() method which successfully fully shrinks the blade plane and extends it again to its full height. Yet when I rotate the lightsaber by 10 degrees and shrink the plane by unitPerDegree*10, the plane doesn't shrink far enough. The lightsaber is Obi-wan's off of

Code: [Select]
AGP, 2009
import java.awt.*;
import java.awt.event.*;
import com.threed.jpct.*;
import com.threed.jpct.util.*;

public class LightsaberTest extends Frame implements WindowListener, KeyListener {
     private World theWorld;
     private FrameBuffer buffer;
     private Camera theCamera;
     private boolean keepGoing;
     private Graphics g;
     private Light light;
     private Canvas canvasGL;
     private Lightsaber lightsaber;
     protected float xRotation;

     public LightsaberTest() {
xRotation = 0.0f;
keepGoing = true;
Config.maxPolysVisible *= 16;
theWorld = new World();
lightsaber = new Lightsaber(theWorld);
theCamera = theWorld.getCamera();
buffer = new FrameBuffer(1024, 768, FrameBuffer.SAMPLINGMODE_NORMAL);
canvasGL = new Canvas();
// canvasGL = buffer.enableGLCanvasRenderer();
// buffer.disableRenderer(IRenderer.RENDERER_SOFTWARE);
this.add(canvasGL, BorderLayout.CENTER);
theWorld.setAmbientLight(145, 145, 145);
light = new Light(theWorld);
light.setIntensity(35, 35, 35);
theCamera.moveCamera(Camera.CAMERA_MOVEOUT, 25f);

this.setSize(1024, 768);

     private void drawLoop() {
g = this.getGraphics();
while (keepGoing) {

     try {
     catch (InterruptedException e) {}
if (canvasGL.getGraphics() == null)
//      buffer.display(g);
lightsaber.drawEdges(theCamera, buffer, (Graphics2D)canvasGL.getGraphics());

// buffer.displayGLOnly();
// canvasGL.paint(canvasGL.getGraphics());//NEEDED ONLY BECAUSE displayGLOnly() DOESN'T GO AS FAR AS display()

     public void windowClosing(WindowEvent e) {
if (e.getWindow() == this) {
     keepGoing = false;
     public void windowClosed(WindowEvent e) {}
     public void windowOpened(WindowEvent e) {}
     public void windowActivated(WindowEvent e) {}
     public void windowDeactivated(WindowEvent e) {}
     public void windowIconified(WindowEvent e) {}
     public void windowDeiconified(WindowEvent e) {}

     public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
if (e.isShiftDown() && keyCode == KeyEvent.VK_UP)
     theCamera.moveCamera(Camera.CAMERA_MOVEIN, 5f);
else if (e.isShiftDown() && keyCode == KeyEvent.VK_DOWN)
     theCamera.moveCamera(Camera.CAMERA_MOVEOUT, 5f);
else if (keyCode == KeyEvent.VK_UP)
     xRotation += 10f;
else if (keyCode == KeyEvent.VK_DOWN)
     xRotation -= 10f;

else if (keyCode == KeyEvent.VK_G)
     public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_DOWN)
     xRotation = 0f;
     public void keyTyped(KeyEvent e) {}

     public static void main(String[] args) {
new LightsaberTest();
class Lightsaber {
     private Object3D lightsaber, bladePlane;
     protected VertexController bladeController;
     private float totalX;

     public Lightsaber(World theWorld) {
totalX = 0.00f;
TextureManager.getInstance().addTexture("PLATEOX2.JPG", new Texture("PLATEOX2.JPG"));
TextureManager.getInstance().addTexture("scratch.jpg", new Texture("scratch.jpg"));
lightsaber = Object3D.mergeAll(Loader.load3DS("saber.3ds", .1f));

TextureManager.getInstance().addTexture("Blade2.jpg", new Texture("Blade2.jpg"));
bladePlane = Primitives.getPlane(1, 8);
bladePlane.translate(-1.4f, -19f, 0);
bladeController = new VertexController(bladePlane);
     public SimpleVector getTransformedCenter() {
return lightsaber.getTransformedCenter();//CHANGE LATER TO AVERAGE GRIP'S AND BLADE'S CENTERS

     private void toWorldSpace(SimpleVector objectSpace) {
SimpleVector translation = bladePlane.getTranslation();
objectSpace.x += translation.x;
objectSpace.y += translation.y;
objectSpace.z += translation.z;
     public void drawEdges(Camera cam, FrameBuffer buffer, Graphics2D g) {
VectorAndIndex[] topMost = bladeController.getTopMost();

toWorldSpace(topMost[0].vector=new SimpleVector(topMost[0].vector));
toWorldSpace(topMost[1].vector=new SimpleVector(topMost[1].vector));
SimpleVector[] top2D = new SimpleVector[]{Interact2D.project3D2D(cam, buffer, topMost[0].vector), Interact2D.project3D2D(cam, buffer, topMost[1].vector)};

VectorAndIndex[] bottomMost = bladeController.getBottomMost();
toWorldSpace(bottomMost[0].vector=new SimpleVector(bottomMost[0].vector));
toWorldSpace(bottomMost[1].vector=new SimpleVector(bottomMost[1].vector));
SimpleVector[] bottom2D = new SimpleVector[]{Interact2D.project3D2D(cam, buffer, bottomMost[0].vector), Interact2D.project3D2D(cam, buffer, bottomMost[1].vector)};
if (bottom2D[0].y > 0) {
     g.drawRect((int)top2D[0].x-10, (int)top2D[0].y-10, 20, 20);
     g.drawRect((int)top2D[1].x-10, (int)top2D[1].y-10, 20, 20);
     g.setColor(new Color(255, 0, 128));
     g.drawRect((int)bottom2D[0].x-10, (int)bottom2D[0].y-10, 20, 20);
     g.drawRect((int)bottom2D[1].x-10, (int)bottom2D[1].y-10, 20, 20);

     public void rotateDegreesX(float xRotation) {//.05 RADIANS==2.8647, 90 DEGREES==1.5707 RADIANS
float rotationRadians = (float) Math.toRadians(xRotation);
lightsaber.rotateAxis(lightsaber.getXAxis(), rotationRadians);
if (xRotation != 0.0f) {
     totalX += xRotation;
class VertexController extends GenericVertexController {
     protected Mesh controlled;
     private float originalWidth = 0f;
     private boolean activated;
     private float originalHeight;

     public VertexController(Object3D toControl) {
controlled = toControl.getMesh();
this.init(controlled, true);
unitPerDegree = getHeight()/90.0f;

activated = true;
System.out.println("Height: "+getHeight() +", unitPerDegree: "+unitPerDegree);

     public void scaleYandShift(float scale) {
SimpleVector[] vertices = this.getSourceMesh();
SimpleVector[] destination = this.getDestinationMesh();
VectorAndIndex[] topMost = getTopMost();

float height = getHeight();
topMost[0].vector.y -= height*scale;
topMost[1].vector.y -= height*scale;
destination[topMost[0].index] = topMost[0].vector;
destination[topMost[1].index] = topMost[1].vector;
originalHeight = getHeight();

     public void shrinkOrGrow() {

VectorAndIndex[] topMost = getTopMost();
SimpleVector[] destination = this.getDestinationMesh();
if (activated) {

    float height = getHeight();
    destination[topMost[0].index].y += height-.05;
    destination[topMost[1].index].y += height-.05;
else {

    destination[topMost[0].index].y -= originalHeight+.05;
    destination[topMost[1].index].y -= originalHeight+.05;    
activated = !activated;


     public void shrinkByDegrees(float degrees) {
VectorAndIndex[] topMost = getTopMost();
SimpleVector[] destination = this.getDestinationMesh();
System.out.println("Shrink factor: "+(unitPerDegree*degrees));
destination[topMost[0].index].y += (unitPerDegree*degrees);
destination[topMost[1].index].y += (unitPerDegree*degrees);

     protected VectorAndIndex[] getTopMost() {//POSITIVE y GOES *DOWN*
VectorAndIndex[] topMost = new VectorAndIndex[2];
SimpleVector[] vertices = this.getSourceMesh();

topMost[0] = new VectorAndIndex(vertices[0], 0);
for (int i = 1; i < vertices.length; i++)
     if (topMost[0].vector.y > vertices[i].y)
topMost[0] = new VectorAndIndex(vertices[i], i);
topMost[1] = new VectorAndIndex(vertices[0], 0);
for (int i = 1; i < vertices.length; i++)
     if (topMost[1].vector.y >= vertices[i].y && topMost[0].index != i)
topMost[1] = new VectorAndIndex(vertices[i], i);
return topMost;
     public float getHeight() {
VectorAndIndex[] topMost = getTopMost();
VectorAndIndex[] bottomMost = getBottomMost();

float height = bottomMost[0].vector.y-topMost[0].vector.y;
return height;

     public void apply() {}

     protected VectorAndIndex[] getBottomMost() {//POSITIVE y GOES *DOWN*
VectorAndIndex[] bottomMost = new VectorAndIndex[2];
SimpleVector[] vertices = this.getSourceMesh();

bottomMost[0] = new VectorAndIndex(vertices[0], 0);
for (int i = 1; i < vertices.length; i++)
     if (bottomMost[0].vector.y < vertices[i].y)
bottomMost[0] = new VectorAndIndex(vertices[i], i);
bottomMost[1] = new VectorAndIndex(vertices[0], 0);
for (int i = 1; i < vertices.length; i++)
     if (bottomMost[1].vector.y <= vertices[i].y && bottomMost[1].index != i)
bottomMost[1] = new VectorAndIndex(vertices[i], i);
return bottomMost;
class VectorAndIndex {
     protected SimpleVector vector;
     protected int index;
     public VectorAndIndex(SimpleVector vector, int index) {
this.vector = vector;
this.index = index;

Support / Opacity Map Ala 3ds Max?
« on: October 16, 2009, 03:30:20 am »
As a feature request, could that be implemented? Would be very helpful, including in additive transparency by the software renderer, I imagine (I wrote a little lightsaber test and the software additive transparency barely worked at all, hardware was perfect). I'm thinking it would be particularly useful for hair.

Support / Screen Space to 3D Space
« on: September 30, 2009, 12:14:59 am »
I asked an old professor for help on transforming screen coordinates into worldspace coordinates, and his solution was for me to put four objects on the world with known positions and print their screen coordinates, then do the following. The first numbers are my results (worldspace, then screen), and the last description was his response to me. I just got two books on matrices off Amazon but they haven't arrived yet and I don't remember a lot about matrices, so I need help from someone who does.

-300, -300, 0.008033752
300, -300, 0.008033752
300, 300, 0.008033752
-300, 300, 0.008033752
Screen coordinates: 209, 180
Screen coordinates: 594, 180
Screen coordinates: 595, 563
Screen coordinates: 210, 564

After getting those values I would have the following matrices.
M(P1) => S1
M(P2) => S2
M(P3) => S3
M(P4) =>S4
Where Pi is the position (in the world) of the 4 objects.  This is known.
Si is the position (on the screen) of the 4 objects.  Also known - via
the print function.
Those equations will be enough to compute the map functions you need -
particularly from your view.  Just solve the equations by hand or use
the following observation.

Let P be the matrix formed with P1 P2 P3 P4 (as columns).
The same for S.
Then the above becomes
MP = S

Multiply both sides by the inverse of P (assuming it is non-singular) -
actually if done right might only need 3 objects.
MP P^-1 = S P^-1
Which becomes
M = S P^-1

Actually you want the inverse of M (to reverse the process).  But this
is then:
M^-1 = P S^-1
That is compute S inverse and multiply with P to get the inverse matrix.

Then for any screen point S_i you would be able to do M S_i and get P_i.

Pages: 1 ... 10 11 [12] 13 14 15