runelite-api: expose higher level getTriangles instead in Model
This commit is contained in:
@@ -24,6 +24,11 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.api;
|
package net.runelite.api;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import net.runelite.api.model.Triangle;
|
||||||
|
import net.runelite.api.model.Vertex;
|
||||||
|
|
||||||
public class Model
|
public class Model
|
||||||
{
|
{
|
||||||
private final net.runelite.rs.api.Model model;
|
private final net.runelite.rs.api.Model model;
|
||||||
@@ -33,33 +38,49 @@ public class Model
|
|||||||
this.model = model;
|
this.model = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] getVerticesX()
|
public List<Triangle> getTriangles()
|
||||||
{
|
{
|
||||||
return model.getVerticesX();
|
int[] verticiesX = model.getVerticesX();
|
||||||
}
|
int[] verticiesY = model.getVerticesY();
|
||||||
|
int[] verticiesZ = model.getVerticesZ();
|
||||||
|
|
||||||
public int[] getVerticesY()
|
int[] trianglesX = model.getTrianglesX();
|
||||||
{
|
int[] trianglesY = model.getTrianglesY();
|
||||||
return model.getVerticesY();
|
int[] trianglesZ = model.getTrianglesZ();
|
||||||
}
|
|
||||||
|
|
||||||
public int[] getVerticesZ()
|
assert trianglesX.length == trianglesY.length;
|
||||||
{
|
assert trianglesY.length == trianglesZ.length;
|
||||||
return model.getVerticesZ();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int[] getTrianglesX()
|
List<Triangle> triangles = new ArrayList<>(trianglesX.length);
|
||||||
{
|
|
||||||
return model.getTrianglesX();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int[] getTrianglesY()
|
for (int i = 0; i < trianglesX.length; ++i)
|
||||||
{
|
{
|
||||||
return model.getTrianglesY();
|
int triangleX = trianglesX[i];
|
||||||
}
|
int triangleY = trianglesY[i];
|
||||||
|
int triangleZ = trianglesZ[i];
|
||||||
|
|
||||||
public int[] getTrianglesZ()
|
Vertex x = new Vertex(
|
||||||
{
|
verticiesX[triangleX],
|
||||||
return model.getTrianglesZ();
|
verticiesY[triangleX],
|
||||||
|
verticiesZ[triangleX]
|
||||||
|
);
|
||||||
|
|
||||||
|
Vertex y = new Vertex(
|
||||||
|
verticiesX[triangleY],
|
||||||
|
verticiesY[triangleY],
|
||||||
|
verticiesZ[triangleY]
|
||||||
|
);
|
||||||
|
|
||||||
|
Vertex z = new Vertex(
|
||||||
|
verticiesX[triangleZ],
|
||||||
|
verticiesY[triangleZ],
|
||||||
|
verticiesZ[triangleZ]
|
||||||
|
);
|
||||||
|
|
||||||
|
Triangle triangle = new Triangle(x, y, z);
|
||||||
|
triangles.add(triangle);
|
||||||
|
}
|
||||||
|
|
||||||
|
return triangles;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ package net.runelite.api;
|
|||||||
import java.awt.Polygon;
|
import java.awt.Polygon;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import net.runelite.api.model.Triangle;
|
||||||
|
import net.runelite.api.model.Vertex;
|
||||||
|
|
||||||
public class Player extends Actor
|
public class Player extends Actor
|
||||||
{
|
{
|
||||||
@@ -60,37 +62,47 @@ public class Player extends Actor
|
|||||||
|
|
||||||
public Polygon[] getPolygons()
|
public Polygon[] getPolygons()
|
||||||
{
|
{
|
||||||
List<Polygon> polys = new ArrayList<>();
|
|
||||||
Model model = getModel();
|
Model model = getModel();
|
||||||
int localX = player.getX();
|
|
||||||
int localY = player.getY();
|
|
||||||
|
|
||||||
// models are orientated north (1024) and there are 2048 angles total
|
|
||||||
int orientation = (player.getOrientation() + 1024) % 2048;
|
|
||||||
|
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int[] verticesX = model.getVerticesX().clone();
|
int localX = player.getX();
|
||||||
int[] verticesY = model.getVerticesY();
|
int localY = player.getY();
|
||||||
int[] verticesZ = model.getVerticesZ().clone();
|
|
||||||
|
|
||||||
int[] trianglesX = model.getTrianglesX();
|
// models are orientated north (1024) and there are 2048 angles total
|
||||||
int[] trianglesY = model.getTrianglesY();
|
int orientation = (player.getOrientation() + 1024) % 2048;
|
||||||
int[] trianglesZ = model.getTrianglesZ();
|
|
||||||
|
List<Triangle> triangles = model.getTriangles();
|
||||||
|
|
||||||
if (orientation != 0)
|
if (orientation != 0)
|
||||||
{
|
{
|
||||||
setOrientation(model, orientation, verticesX, verticesZ);
|
triangles = rotate(triangles, orientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < trianglesX.length; i++)
|
List<Polygon> polys = new ArrayList<>();
|
||||||
|
for (Triangle triangle : triangles)
|
||||||
{
|
{
|
||||||
Point x = Perspective.worldToCanvas(client, localX - verticesX[trianglesX[i]], localY - verticesZ[trianglesX[i]], -verticesY[trianglesX[i]]);
|
Vertex vx = triangle.getA();
|
||||||
Point y = Perspective.worldToCanvas(client, localX - verticesX[trianglesY[i]], localY - verticesZ[trianglesY[i]], -verticesY[trianglesY[i]]);
|
Vertex vy = triangle.getB();
|
||||||
Point z = Perspective.worldToCanvas(client, localX - verticesX[trianglesZ[i]], localY - verticesZ[trianglesZ[i]], -verticesY[trianglesZ[i]]);
|
Vertex vz = triangle.getC();
|
||||||
|
|
||||||
|
Point x = Perspective.worldToCanvas(client,
|
||||||
|
localX - vx.getX(),
|
||||||
|
localY - vx.getZ(),
|
||||||
|
-vx.getY());
|
||||||
|
|
||||||
|
Point y = Perspective.worldToCanvas(client,
|
||||||
|
localX - vy.getX(),
|
||||||
|
localY - vy.getZ(),
|
||||||
|
-vy.getY());
|
||||||
|
|
||||||
|
Point z = Perspective.worldToCanvas(client,
|
||||||
|
localX - vz.getX(),
|
||||||
|
localY - vz.getZ(),
|
||||||
|
-vz.getY());
|
||||||
|
|
||||||
int xx[] =
|
int xx[] =
|
||||||
{
|
{
|
||||||
@@ -106,18 +118,34 @@ public class Player extends Actor
|
|||||||
return polys.toArray(new Polygon[polys.size()]);
|
return polys.toArray(new Polygon[polys.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setOrientation(Model model, int orientation, int[] verticesX, int[] verticesZ)
|
private List<Triangle> rotate(List<Triangle> triangles, int orientation)
|
||||||
|
{
|
||||||
|
List<Triangle> rotatedTriangles = new ArrayList<>();
|
||||||
|
for (Triangle triangle : triangles)
|
||||||
|
{
|
||||||
|
Vertex a = triangle.getA();
|
||||||
|
Vertex b = triangle.getB();
|
||||||
|
Vertex c = triangle.getC();
|
||||||
|
|
||||||
|
Triangle rotatedTriangle = new Triangle(
|
||||||
|
rotate(a, orientation),
|
||||||
|
rotate(b, orientation),
|
||||||
|
rotate(c, orientation)
|
||||||
|
);
|
||||||
|
rotatedTriangles.add(rotatedTriangle);
|
||||||
|
}
|
||||||
|
return rotatedTriangles;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Vertex rotate(Vertex vertex, int orientation)
|
||||||
{
|
{
|
||||||
int sin = Perspective.SINE[orientation];
|
int sin = Perspective.SINE[orientation];
|
||||||
int cos = Perspective.COSINE[orientation];
|
int cos = Perspective.COSINE[orientation];
|
||||||
|
|
||||||
int[] originalX = model.getVerticesX();
|
return new Vertex(
|
||||||
int[] originalZ = model.getVerticesZ();
|
vertex.getX() * cos + vertex.getZ() * sin >> 16,
|
||||||
|
vertex.getY(),
|
||||||
for (int i = 0; i < originalX.length; ++i)
|
vertex.getZ() * cos - vertex.getX() * sin >> 16
|
||||||
{
|
);
|
||||||
verticesX[i] = originalX[i] * cos + originalZ[i] * sin >> 16;
|
|
||||||
verticesZ[i] = originalZ[i] * cos - originalX[i] * sin >> 16;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
package net.runelite.api.model;
|
||||||
|
|
||||||
|
public class Triangle
|
||||||
|
{
|
||||||
|
private final Vertex a;
|
||||||
|
private final Vertex b;
|
||||||
|
private final Vertex c;
|
||||||
|
|
||||||
|
public Triangle(Vertex a, Vertex b, Vertex c)
|
||||||
|
{
|
||||||
|
this.a = a;
|
||||||
|
this.b = b;
|
||||||
|
this.c = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "Triangle{" + "a=" + a + ", b=" + b + ", c=" + c + '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vertex getA()
|
||||||
|
{
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vertex getB()
|
||||||
|
{
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vertex getC()
|
||||||
|
{
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||||
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||||
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||||
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
package net.runelite.api.model;
|
||||||
|
|
||||||
|
public class Vertex
|
||||||
|
{
|
||||||
|
private final int x;
|
||||||
|
private final int y;
|
||||||
|
private final int z;
|
||||||
|
|
||||||
|
public Vertex(int x, int y, int z)
|
||||||
|
{
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return "Vertex{" + "x=" + x + ", y=" + y + ", z=" + z + '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getX()
|
||||||
|
{
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getY()
|
||||||
|
{
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getZ()
|
||||||
|
{
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user