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
166
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?

167
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.

168
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.


169
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 scifi3d.com.

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() {
this.setTitle("BR's");
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);
theCamera.setPosition(lightsaber.getTransformedCenter());
light = new Light(theWorld);
light.setIntensity(35, 35, 35);
light.setAttenuation(8f);
theCamera.moveCamera(Camera.CAMERA_MOVEOUT, 25f);
theCamera.lookAt(lightsaber.getTransformedCenter());
light.setPosition(theCamera.getPosition());

canvasGL.addKeyListener(this);
this.addKeyListener(this);
this.addWindowListener(this);
this.setSize(1024, 768);
this.setVisible(true);
drawLoop();
     }

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

     try {
Thread.sleep(50);
     }
     catch (InterruptedException e) {}
if (canvasGL.getGraphics() == null)
continue;
     buffer.clear();
     lightsaber.rotateDegreesX(xRotation);
     theWorld.renderScene(buffer);
     theWorld.draw(buffer);
//      buffer.display(g);
buffer.display(canvasGL.getGraphics());
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;
     this.dispose();
     System.exit(0);
}
     }
     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)
     lightsaber.bladeController.shrinkOrGrow();
     }
     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.setTransparency(0);
bladePlane.setTransparencyMode(Object3D.TRANSPARENCY_MODE_ADD);
bladePlane.setTexture("Blade2.jpg");
bladePlane.setBillboarding(true);
theWorld.addObject(lightsaber);
theWorld.addObject(bladePlane);
theWorld.buildAllObjects();
bladePlane.translate(-1.4f, -19f, 0);
bladeController = new VertexController(bladePlane);
bladeController.scaleYandShift(8f);
     }
     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) {
bladeController.refreshMeshData();
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.setColor(Color.red);
     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;
     bladeController.shrinkByDegrees(xRotation);
}
     }
}
class VertexController extends GenericVertexController {
     protected Mesh controlled;
     private float originalWidth = 0f;
     private float unitPerDegree;//THE AMOUNT BY WHICH THE PLACE SHOULD SHRINK PER DEGREE's ROTATION
     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;
this.updateMesh();
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;

this.updateMesh();
     }

     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);
this.updateMesh();
     }

     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;
     }
}

170
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.

171
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.

172
Support / Object3D.getTransformedCenter() of Current Mesh
« on: September 10, 2009, 11:09:14 pm »
One of my models unfortunately moves forward on his own (as opposed to simply moving its legs) so that, obviously, it moves back when the animation loops. The following method doesn't work because the center is the same for both the start and end of the animation (I'm guessing it's right in the middle of the extremes). Is the answer along the lines of a VertexController or is there a simpler way to get different centers for both the first and last frames?

Code: [Select]
   private void advance() {//THEY WALK FORWARD BY THEMSELVES, THEN, WHEN ANIMATION LOOPS, GO BACK TO THEIR STARTING POINT...
model.calcCenter();
SimpleVector currentPosition = model.getTransformedCenter();
model.animate(animationPosition, currentAnimation);
model.calcCenter();
moveTowards(model, currentPosition, 1f);/**THIS WOULD WORK IF model.getTransformedCenter() DIDN'T RETURN THE SAME VALUE AS currentPosition*/
    }

173
Support / Is there a means by which to count the polygons in a world?
« on: September 07, 2009, 02:41:23 am »
By my count I shouldn't have passed my specified number, but jpct tells me I have. How could I get a count (without getting into the vertex controllers)? I've looked but couldn't find one such method. If none exists, perhaps just changing the error message to include current number of polygons would do.

174
Support / Why Can I Never Export (or Otherwise Import) 3ds Animations?
« on: August 22, 2009, 12:36:33 am »
Is there something different I should do when importing an animated 3ds model than when I import an MD2 (MD2 works for me but is bigger and uses more RAM)?

175
Support / Can't Rotate an Object By Its Center
« on: August 11, 2009, 12:05:01 am »
I tried everything both in MAX and in my program. The 3dsmax pivot is at the very center of the object and I get the desired effect on MAX, but Object3D.rotateAxis(Object3D.getZAxis(), float) simply won't rotate my model exactly in its center. I even tried writing a VertexController to get the objectspace center then apply to that the object's world transformation and set the object's new center, but that failed as well! Is it my code or is it jpct's?

Code: [Select]
currentMission.groundModel.build();
SimpleVector newCenter = new VertexController(currentMission.groundModel).getCenter();
newCenter.matMul(currentMission.groundModel.getWorldTransformation());
currentMission.groundModel.setCenter(newCenter);

// camera.setPosition(newCenter);
// camera.moveCamera(Camera.CAMERA_MOVEOUT, 10f);

while (currentMission.missionName.equals("Mission Briefing Room")) {
keyboardAndJoystick();
draw();
currentMission.groundModel.rotateAxis(currentMission.groundModel.getZAxis(), .02f);

//       currentMission.groundModel.rotateZ(.02f);
// awtGlCanvas.getGraphics().drawLine(this.getWidth()/2, 0, this.getWidth()/2, this.getHeight());
// awtGlCanvas.getGraphics().drawLine(0, this.getHeight()/2, this.getWidth(), this.getHeight()/2);
if (!paused) {}
try {
Thread.sleep(50);
}
catch (InterruptedException e) {System.err.println("Trouble sleeping: "+e.getMessage());}
}

176
Support / ship.align(plane) IN MULTIPLE ITERATIONS
« on: July 20, 2009, 07:23:03 pm »
I'm trying to achieve the equivalent of ship.align(plane) (leveling the ship) in multiple iterations. This is what I have. What I'm getting instead is the exact same thing as ship.align(plane): it aligns the ship to the plane in a single pass. Shouldn't lastRotation.interpolate(Matrix, Matrix, .1f) take care of only rotating 10%?

Code: [Select]
if (shipLeveling == 10) {
      lastRotation = plane.getRotationMatrix();
      shipLeveling = 0;
}

Matrix softMatrix = ship.getRotationMatrix();
lastRotation.interpolate(lastRotation, softMatrix, 0.1f);// interpolate between the matrices
Matrix matrix = new Matrix(lastRotation);
ship.setRotationMatrix(matrix);
shipLeveling++;

177
Support / Draw distance seems to shrink every time I draw an Overlay
« on: July 13, 2009, 08:59:45 pm »
And the Overlay itself doesn't show. The first lines are how I initialized the Overlay, the second are in my collision(CollisionEvent) method.

Code: [Select]
explosionPlane = new Overlay(theWorld, buffer, "explosion2.gif");
explosionPlane.setVisibility(false);

Code: [Select]
explosionPlane.setSourceCoordinates((int)point.x-explosion.getWidth()/2, (int)point.y-explosion.getHeight()/2, (int)(point.x+explosion.getWidth()/2), (int)(point.y+explosion.getHeight()/2));
explosionPlane.setVisibility(true);

178
Support / KeyMapper Class
« on: June 22, 2009, 11:44:50 pm »
Egon suggested I used the KeyMapper class to improve keyboard-input-reading for the racing game, and so it is that I am. Problem is, the input is at least as bad as it was before with the following code. The idea is that the car speeds up while you're holding down the UP key and slows down when you're holding DOWN, but in practice it only speeds up and slows down when I press, release, and press again. keyPressed at VK_UP sets speedingUp to true, and at VK_DOWN sets slowingDown to true. Shouldn't the car speed up with every loop iteration? It turns just fine. And I did remove the awt KeyListener, by the way, I'm just using its keyPressed because I'm being lazy.

Code: [Select]
      KeyState state = keyMapper.poll();
      if (state.getState() == KeyState.PRESSED || (speedingUp && state.getKeyCode() == KeyEvent.VK_UP) || (slowingDown && state.getKeyCode() == KeyEvent.VK_DOWN))
keyPressed(new KeyEvent(this, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), 0, state.getKeyCode(), KeyEvent.CHAR_UNDEFINED));

179
Support / Very Very Simple C Question
« on: June 20, 2009, 07:27:27 pm »
I figure at the very least paulscode and Egon will know: what does the line "typedef struct animation Animation" do in a header file? I see no other defining reference to animation (lower or upper case) anywhere in this little assignment. I haven't done C programming in so long, I forgot more than I knew I had known. And to clarify, the assignment uses Animation* pointers a lot, I meant that this line is the only part that defines it.

180
Support / Using FrameBuffer's Graphics With AWTGLCanvas
« on: June 17, 2009, 11:27:18 pm »
I actually solved the ArrayIndexOutOfBoundsException. That little program I had written over a few years (it was the first one I built with jPCT) and it uses both the software and the hardware renderer (not at the same time obviously). And in changing it a million times I had introduced a stupid glitch in which I called run in one part of it (one attempt at getting the non-canvas OpenGL renderer to use the software loop), and started a separate thread that called it. So sometimes, draw() was being called twice at the same time (and before it draws it moves the objects). So that's that.

But now here's a question: what's the point of using AWTGLCanvas if the FrameBuffer's Graphics object will still be null (or useless, whichever it is)? I can no more use canvas.getGraphics()'s Graphics instance than I could a frame's (I can, but the screen will flicker). So is this a jPCT bug (I hope so)?

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