Remove all references to external dependencies.

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
origin
sigonasr2, Sig, Sigo 3 years ago
parent 8f7d77dfa8
commit 9601cb9133
  1. 6
      pom.xml
  2. 4
      src/sig/Matrix.java
  3. 11
      src/sig/Panel.java
  4. 18
      src/sig/SigRenderer.java
  5. 7
      src/sig/Triangle.java
  6. 17
      src/sig/Vector.java
  7. 4
      src/sig/utils/GraphicsUtils.java
  8. 9
      src/sig/utils/OBJReader.java

@ -17,12 +17,6 @@
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/javax.vecmath/vecmath -->
<dependency>
<groupId>javax.vecmath</groupId>
<artifactId>vecmath</artifactId>
<version>1.5.2</version>
</dependency>
</dependencies>
<build>

@ -1,14 +1,12 @@
package sig;
import javax.vecmath.Vector3f;
public class Matrix {
float[][] m = new float[4][4];
Matrix(float[][]m) {
this.m=m;
}
public static void MultiplyMatrixVector(Vector3f i,Vector3f o,Matrix m) {
public static void MultiplyMatrixVector(Vector i,Vector o,Matrix m) {
o.x=i.x*m.m[0][0]+i.y*m.m[1][0]+i.z*m.m[2][0]+m.m[3][0];
o.y=i.x*m.m[0][1]+i.y*m.m[1][1]+i.z*m.m[2][1]+m.m[3][1];
o.z=i.x*m.m[0][2]+i.y*m.m[1][2]+i.z*m.m[2][2]+m.m[3][2];

@ -1,6 +1,5 @@
package sig;
import javax.swing.JPanel;
import javax.vecmath.Vector3f;
import sig.utils.DrawUtils;
@ -103,7 +102,7 @@ public class Panel extends JPanel implements Runnable {
fTheta+=0.01f;
for (Triangle t : SigRenderer.cube.triangles) {
Triangle triProjected = new Triangle(new Vector3f(),new Vector3f(),new Vector3f()),triTranslated=new Triangle(new Vector3f(),new Vector3f(),new Vector3f()),triRotatedZ=new Triangle(new Vector3f(),new Vector3f(),new Vector3f()),triRotatedZX=new Triangle(new Vector3f(),new Vector3f(),new Vector3f());
Triangle triProjected = new Triangle(new Vector(),new Vector(),new Vector()),triTranslated=new Triangle(new Vector(),new Vector(),new Vector()),triRotatedZ=new Triangle(new Vector(),new Vector(),new Vector()),triRotatedZX=new Triangle(new Vector(),new Vector(),new Vector());
Matrix.MultiplyMatrixVector(t.A, triRotatedZ.A, matRotZ);
@ -119,7 +118,7 @@ public class Panel extends JPanel implements Runnable {
triTranslated.B.z=triRotatedZX.B.z+6f;
triTranslated.C.z=triRotatedZX.C.z+6f;
Vector3f normal=new Vector3f(),line1=new Vector3f(),line2=new Vector3f();
Vector normal=new Vector(),line1=new Vector(),line2=new Vector();
line1.x=triTranslated.B.x-triTranslated.A.x;
line1.y=triTranslated.B.y-triTranslated.A.y;
line1.z=triTranslated.B.z-triTranslated.A.z;
@ -138,7 +137,7 @@ public class Panel extends JPanel implements Runnable {
normal.y*(triTranslated.A.y-SigRenderer.vCamera.y)+
normal.z*(triTranslated.A.z-SigRenderer.vCamera.z)<0) {
Vector3f lightDir = new Vector3f(0,0,-1);
Vector lightDir = new Vector(0,0,-1);
l = (float)Math.sqrt(lightDir.x*lightDir.x+lightDir.y*lightDir.y+lightDir.z*lightDir.z);
lightDir.x/=l; lightDir.y/=l; lightDir.z/=l;
@ -181,8 +180,6 @@ public class Panel extends JPanel implements Runnable {
DrawUtils.DrawTriangle(p,(int)t.A.x,(int)t.A.y,(int)t.B.x,(int)t.B.y,(int)t.C.x,(int)t.C.y,Color.BLACK);
}
}
endTime=System.nanoTime();
SigRenderer.DRAWLOOPTIME=(endTime-startTime)/1000000f;
}
public void repaint() {
@ -199,6 +196,8 @@ public class Panel extends JPanel implements Runnable {
mImageProducer.newPixels();
// draw it on panel
g.drawImage(this.imageBuffer, 0, 0, this);
endTime=System.nanoTime();
SigRenderer.DRAWLOOPTIME=(endTime-startTime)/1000000f;
}
/**

@ -1,25 +1,15 @@
package sig;
import javax.swing.JFrame;
import javax.vecmath.Matrix4f;
import javax.vecmath.Point2d;
import javax.vecmath.Tuple3d;
import javax.vecmath.Vector3f;
import sig.utils.DrawUtils;
import sig.utils.OBJReader;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.File;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.awt.Toolkit;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.BorderLayout;
public class SigRenderer implements KeyListener,MouseListener,MouseMotionListener{
@ -34,7 +24,7 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
public static float DRAWLOOPTIME=0;
public static final float RESOLUTION=1;
public static Vector3f origin = new Vector3f(0,0,10);
public static Vector origin = new Vector(0,0,10);
public static float rot = (float)Math.PI/4; //In radians.
public static List<Pixel> pixels;
@ -52,7 +42,7 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
{0,0,(-fFar*fNear)/(fFar-fNear),0f},
});
public static Vector3f vCamera = new Vector3f();
public static Vector vCamera = new Vector();
public void runGameLoop() {
rot+=Math.PI/480d;
@ -142,16 +132,12 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_UP:{
origin.add(new Vector3f(0,0,-0.05f));
}break;
case KeyEvent.VK_RIGHT:{
origin.add(new Vector3f(0.05f,0,0));
}break;
case KeyEvent.VK_LEFT:{
origin.add(new Vector3f(-0.05f,0,0));
}break;
case KeyEvent.VK_DOWN:{
origin.add(new Vector3f(0,0,0.05f));
}break;
}
}

@ -1,18 +1,17 @@
package sig;
import javax.vecmath.Vector3f;
import java.awt.Color;
public class Triangle {
Vector3f A,B,C;
Vector A,B,C;
Color col = Color.WHITE;
public Triangle(Vector3f A,Vector3f B,Vector3f C) {
public Triangle(Vector A,Vector B,Vector C) {
this.A=A;
this.B=B;
this.C=C;
}
@Override
protected Object clone(){
return new Triangle((Vector3f)this.A.clone(),(Vector3f)this.B.clone(),(Vector3f)this.C.clone());
return new Triangle((Vector)this.A.clone(),(Vector)this.B.clone(),(Vector)this.C.clone());
}
@Override
public String toString() {

@ -0,0 +1,17 @@
package sig;
public class Vector {
public float x,y,z;
Vector() {
this(0,0,0);
}
public Vector(float x,float y,float z) {
this.x=x;
this.y=y;
this.z=z;
}
@Override
protected Object clone(){
return new Vector(x,y,z);
}
}

@ -0,0 +1,4 @@
package sig.utils;
public class GraphicsUtils {
}

@ -5,9 +5,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import javax.vecmath.Vector3f;
import sig.Triangle;
import sig.Vector;
public class OBJReader {
public static List<Triangle> ReadOBJFile(String f) {
@ -21,15 +20,15 @@ public class OBJReader {
} else
if (split[0].equalsIgnoreCase("f")) {
tris.add(new Triangle(
new Vector3f(
new Vector(
vertices.get(Integer.parseInt(split[1])-1)[0],
vertices.get(Integer.parseInt(split[1])-1)[1],
vertices.get(Integer.parseInt(split[1])-1)[2]),
new Vector3f(
new Vector(
vertices.get(Integer.parseInt(split[2])-1)[0],
vertices.get(Integer.parseInt(split[2])-1)[1],
vertices.get(Integer.parseInt(split[2])-1)[2]),
new Vector3f(
new Vector(
vertices.get(Integer.parseInt(split[3])-1)[0],
vertices.get(Integer.parseInt(split[3])-1)[1],
vertices.get(Integer.parseInt(split[3])-1)[2])));

Loading…
Cancel
Save