Class Point
- java.lang.Object
-
- com.badlogic.gdx.math.Vector3
-
- com.bombinggames.wurfelengine.core.map.Point
-
- All Implemented Interfaces:
Position,java.io.Serializable
public class Point extends com.badlogic.gdx.math.Vector3 implements Position
A point is a single position in the game world not bound to the grid. Use this for entities.- Since:
- WE1.1
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Point()Creates a point refering to a position in the game world.Point(float posX, float posY, float height)Creates a point refering to a position in the game world.Point(com.badlogic.gdx.math.Vector3 vec)Point(Point point)Copy-constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Pointadd(float[] vector)Add a vector to the positionPointadd(float x, float y, float z)Add a vector to the positionPointadd(com.badlogic.gdx.math.Vector2 vector)Add a vector to the positionPointadd(com.badlogic.gdx.math.Vector3 vector)Add a vector to the positionbooleancanSee(Point p, float maxdistance)Pointcpy()avoid this method because it creates a new instance.floatdistanceTo(AbstractGameObject object)floatdistanceTo(Point point)floatdistanceTo(Position pos)floatdistanceToHorizontal(AbstractGameObject object)checks only x and y.floatdistanceToHorizontal(Point point)checks only x and y.floatdistanceToHorizontal(Position pos)checks only x and y.floatdistanceToHorizontalSquared(AbstractGameObject object)checks only x and y.floatdistanceToHorizontalSquared(Point point)checks only x and y.floatdistanceToHorizontalSquared(Position pos)checks only x and y.floatdistanceToSquared(AbstractGameObject object)The result is squared for fast comparison.floatdistanceToSquared(Point point)The result is squared for fast comparison.floatdistanceToSquared(Position pos)The result is squared for fast comparison.intgetBlock()bytegetBlockId()Get the block at the position.ChunkgetChunk()intgetChunkX()The chunk coordinate.intgetChunkY()The chunk coordinate.CoordinategetCoord()May not be copy safe.floatgetDistanceToCellCenterX()Distance to cell center.floatgetDistanceToCellCenterY()Distance to cell center.floatgetDistanceToCellCenterZ()Distance to cell center.java.util.ArrayList<AbstractEntity>getEntitiesNearby(float radius)get entities in radius<T> java.util.LinkedList<T>getEntitiesNearby(float radius, java.lang.Class<T> type)Get entities in radius.java.util.LinkedList<AbstractEntity>getEntitiesNearbyHorizontal(float radius)get entities in radius (horizontal only)<T> java.util.LinkedList<T>getEntitiesNearbyHorizontal(float radius, java.lang.Class<T> type)get entities in horizontal radius (like a pipe)PointgetPoint()May not be copy safe.intgetProjectionSpaceX(GameView view, Camera camera)equals screen space when zoom=1 with a single, fullscreen camera.intgetProjectionSpaceY(GameView view, Camera camera)equals screen space when zoom=1 with a single camera.static PointgetShared()A shared object to pass values without using the heap.intgetViewSpcX()Calculate position in view space.intgetViewSpcY()Calculate position in view space.floatgetX()Get the game world position from leftfloatgetY()Get the game world position from top.floatgetZ()Get the height (z-value) of the coordinate.intgetZGrid()Get the z in block grid coordinates of the coordinate.floatgetZPoint()Get the z in game world coordinates.booleanisInMemoryAreaXY()Checks if the coordiantes are accessable with the currently loaded chunks.booleanisInMemoryAreaXYZ()Checks if the position is on the chunks currently in memory.booleanisObstacle()Intersectionraycast(com.badlogic.gdx.math.Vector3 dir, float maxDistance, RenderStorage rs, java.util.function.Predicate<java.lang.Byte> hitCondition)Trace a ray through the map until ray hits non air block.
Does not work properly with the staggered map but is quite fast.IntersectionrayMarching(com.badlogic.gdx.math.Vector3 dir, float maxDistance, RenderStorage rS, java.util.function.Predicate<java.lang.Byte> hitCondition)Sends a ray by moving a coordinate though the map.Pointset(Point point)overwrites the coordinates with values from another point.PointsetFromCoord(Coordinate coord)Set x,y,z based on a coordinate.PointsetToCenterOfCell()Relative to the current coordiante field set the offset.voidsetZ(float height)CoordinatetoCoord()returns coordinate aquivalent.PointtoPoint()Calculates it and creates new instance if not already in correct format then return a copy of itself.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from class com.badlogic.gdx.math.Vector3
add, clamp, crs, crs, dot, dot, dot, dst, dst, dst, dst2, dst2, dst2, epsilonEquals, epsilonEquals, equals, fromString, hashCode, hasOppositeDirection, hasSameDirection, idt, interpolate, isCollinear, isCollinear, isCollinearOpposite, isCollinearOpposite, isOnLine, isOnLine, isPerpendicular, isPerpendicular, isUnit, isUnit, isZero, isZero, len, len, len2, len2, lerp, limit, limit2, mul, mul, mul, mul4x3, mulAdd, mulAdd, nor, prj, rot, rotate, rotate, rotateRad, rotateRad, scl, scl, scl, set, set, set, set, setFromSpherical, setLength, setLength2, setToRandomDirection, setZero, slerp, sub, sub, sub, toString, traMul, traMul, unrotate, untransform
-
-
-
-
Constructor Detail
-
Point
public Point()
Creates a point refering to a position in the game world. Points at 0,0,0.
-
Point
public Point(float posX, float posY, float height)Creates a point refering to a position in the game world.- Parameters:
posX- The distance from the left border of the map (game space)posY- The distance from the top border of the map (game space)height- The distance from ground (game space)
-
Point
public Point(com.badlogic.gdx.math.Vector3 vec)
- Parameters:
vec-
-
Point
public Point(Point point)
Copy-constructor. This constructor copies the values.- Parameters:
point- the source of the copy
-
-
Method Detail
-
getShared
public static Point getShared()
A shared object to pass values without using the heap.- Returns:
-
getZ
public float getZ()
Get the height (z-value) of the coordinate.- Returns:
- game dimension
-
getZGrid
public int getZGrid()
Description copied from interface:PositionGet the z in block grid coordinates of the coordinate. Faster than transforming to coordinate first.
-
getZPoint
public float getZPoint()
Description copied from interface:PositionGet the z in game world coordinates.
-
setZ
public void setZ(float height)
- Parameters:
height-
-
toCoord
public Coordinate toCoord()
returns coordinate aquivalent. Removes floating of block.
Looks complicated but has runtime O(const). You should avoid this method in loops or the update method because it uses the heap.
-
getCoord
public Coordinate getCoord()
Description copied from interface:PositionMay not be copy safe.
-
toPoint
public Point toPoint()
Description copied from interface:PositionCalculates it and creates new instance if not already in correct format then return a copy of itself.
-
getX
public float getX()
Get the game world position from left- Returns:
-
getY
public float getY()
Get the game world position from top.- Returns:
-
getDistanceToCellCenterX
public float getDistanceToCellCenterX()
Distance to cell center.- Returns:
- the offset to the coordinates center.
-
getDistanceToCellCenterY
public float getDistanceToCellCenterY()
Distance to cell center.- Returns:
- the offset to the coordinates center.
-
getDistanceToCellCenterZ
public float getDistanceToCellCenterZ()
Distance to cell center.- Returns:
- the offset to the coordinates center.
-
getBlockId
public byte getBlockId()
Description copied from interface:PositionGet the block at the position. Clamps positions over the map at topmost layer.- Specified by:
getBlockIdin interfacePosition- Returns:
- If the coordiante is not in memory will crash.
-
getBlock
public int getBlock()
- Returns:
-
cpy
public Point cpy()
avoid this method because it creates a new instance.
-
getViewSpcX
public int getViewSpcX()
Description copied from interface:PositionCalculate position in view space.- Specified by:
getViewSpcXin interfacePosition- Returns:
- Returns the center of the projected (screen) x-position where the object is rendered without regarding the camera. It also adds the cell offset.
-
getViewSpcY
public int getViewSpcY()
Description copied from interface:PositionCalculate position in view space.- Specified by:
getViewSpcYin interfacePosition- Returns:
- Returns the center of the projected (view space) y-position where the object is rendered without regarding the camera.
-
getProjectionSpaceX
public int getProjectionSpaceX(GameView view, Camera camera)
Description copied from interface:Positionequals screen space when zoom=1 with a single, fullscreen camera.- Specified by:
getProjectionSpaceXin interfacePosition- Returns:
-
getProjectionSpaceY
public int getProjectionSpaceY(GameView view, Camera camera)
Description copied from interface:Positionequals screen space when zoom=1 with a single camera.- Specified by:
getProjectionSpaceYin interfacePosition- Returns:
-
isInMemoryAreaXY
public boolean isInMemoryAreaXY()
Description copied from interface:PositionChecks if the coordiantes are accessable with the currently loaded chunks. Does not check for z axis (horizontal only). So the position can be udner or over the map.- Specified by:
isInMemoryAreaXYin interfacePosition- Returns:
-
isInMemoryAreaXYZ
public boolean isInMemoryAreaXYZ()
Description copied from interface:PositionChecks if the position is on the chunks currently in memory. Checks all axis'.- Specified by:
isInMemoryAreaXYZin interfacePosition- Returns:
- true if inside a chunk. false if currently not loaded or outside range.
-
add
public Point add(float[] vector)
Add a vector to the position- Parameters:
vector- all values in game world values- Returns:
- returns itself
-
add
public Point add(com.badlogic.gdx.math.Vector2 vector)
Add a vector to the position- Parameters:
vector- all values in game world values- Returns:
- returns itself
-
add
public Point add(com.badlogic.gdx.math.Vector3 vector)
Add a vector to the position- Overrides:
addin classcom.badlogic.gdx.math.Vector3- Parameters:
vector- all values in game world values- Returns:
- returns itself
-
add
public Point add(float x, float y, float z)
Add a vector to the position- Overrides:
addin classcom.badlogic.gdx.math.Vector3- Parameters:
x- x value to addy- y value to addz- height to add- Returns:
- returns itself
-
setToCenterOfCell
public Point setToCenterOfCell()
Relative to the current coordiante field set the offset.- Returns:
-
raycast
public Intersection raycast(com.badlogic.gdx.math.Vector3 dir, float maxDistance, RenderStorage rs, java.util.function.Predicate<java.lang.Byte> hitCondition)
Trace a ray through the map until ray hits non air block.
Does not work properly with the staggered map but is quite fast.- Parameters:
dir- dir of the raymaxDistance- the distance after which it should stop. (in game meters)rs-hitCondition-- Returns:
- can return null if not hitting anything. The normal on the back sides may be wrong. The normals are in a turned coordiante system.
- Since:
- 1.2.29
- See Also:
rayMarching(com.badlogic.gdx.math.Vector3, float, com.bombinggames.wurfelengine.core.map.rendering.RenderStorage, java.util.function.Predicate)
-
rayMarching
public Intersection rayMarching(com.badlogic.gdx.math.Vector3 dir, float maxDistance, RenderStorage rS, java.util.function.Predicate<java.lang.Byte> hitCondition)
Sends a ray by moving a coordinate though the map. Slow but it mostly returns precise results.
Stops at first point where the criteria is met.- Parameters:
dir-maxDistance- game space in metersrS- used when regarding clipping informationhitCondition- can be null- Returns:
- intersection point
- See Also:
raycast(com.badlogic.gdx.math.Vector3, float, com.bombinggames.wurfelengine.core.map.rendering.RenderStorage, java.util.function.Predicate)
-
distanceTo
public float distanceTo(Position pos)
- Specified by:
distanceToin interfacePosition- Parameters:
pos-- Returns:
- the distance from this point to the other point in game world coordinates
-
distanceTo
public float distanceTo(Point point)
- Parameters:
point-- Returns:
- the distance from this point to the other point in game coordinates
-
distanceTo
public float distanceTo(AbstractGameObject object)
- Specified by:
distanceToin interfacePosition- Parameters:
object-- Returns:
- the distance from this point to the other object
-
distanceToSquared
public float distanceToSquared(AbstractGameObject object)
Description copied from interface:PositionThe result is squared for fast comparison.- Specified by:
distanceToSquaredin interfacePosition- Returns:
- the distance from this point to the other object squared
- See Also:
Position.distanceTo(AbstractGameObject)
-
distanceToSquared
public float distanceToSquared(Position pos)
Description copied from interface:PositionThe result is squared for fast comparison.- Specified by:
distanceToSquaredin interfacePosition- Returns:
- the distance from this point to the other object squared
- See Also:
Position.distanceTo(Position)
-
distanceToSquared
public float distanceToSquared(Point point)
The result is squared for fast comparison.- Parameters:
point-- Returns:
- the distance from this point to the other point in game coordinates squared
-
distanceToHorizontal
public float distanceToHorizontal(Point point)
checks only x and y.- Parameters:
point-- Returns:
- the distance from this point to the other point only regarding horizontal components.
-
distanceToHorizontalSquared
public float distanceToHorizontalSquared(Point point)
checks only x and y.- Parameters:
point-- Returns:
- the distance from this point to the other point only regarding horizontal components.
-
distanceToHorizontal
public float distanceToHorizontal(AbstractGameObject object)
checks only x and y.- Specified by:
distanceToHorizontalin interfacePosition- Parameters:
object-- Returns:
- the distance from this point to the other point only regarding horizontal components.
-
distanceToHorizontal
public float distanceToHorizontal(Position pos)
Description copied from interface:Positionchecks only x and y.- Specified by:
distanceToHorizontalin interfacePosition- Returns:
- the distance from this pos to the other pos only regarding horizontal components.
-
distanceToHorizontalSquared
public float distanceToHorizontalSquared(AbstractGameObject object)
checks only x and y.- Specified by:
distanceToHorizontalSquaredin interfacePosition- Parameters:
object-- Returns:
- the distance from this point to the other point only regarding horizontal components.
-
distanceToHorizontalSquared
public float distanceToHorizontalSquared(Position pos)
Description copied from interface:Positionchecks only x and y.- Specified by:
distanceToHorizontalSquaredin interfacePosition- Returns:
- the distance from this pos to the other pos squared only regarding horizontal components.
-
getEntitiesNearby
public java.util.ArrayList<AbstractEntity> getEntitiesNearby(float radius)
get entities in radius- Parameters:
radius- in game dimension pixels- Returns:
- every entitie in radius
-
getEntitiesNearbyHorizontal
public java.util.LinkedList<AbstractEntity> getEntitiesNearbyHorizontal(float radius)
Description copied from interface:Positionget entities in radius (horizontal only)- Specified by:
getEntitiesNearbyHorizontalin interfacePosition- Parameters:
radius- in game dimension pixels- Returns:
- every entitie in radius
-
getEntitiesNearbyHorizontal
public <T> java.util.LinkedList<T> getEntitiesNearbyHorizontal(float radius, java.lang.Class<T> type)Description copied from interface:Positionget entities in horizontal radius (like a pipe)- Specified by:
getEntitiesNearbyHorizontalin interfacePosition- Parameters:
radius- in game dimension pixelstype- whitelist- Returns:
- every entitie in radius
-
getChunkX
public int getChunkX()
Description copied from interface:PositionThe chunk coordinate.
-
getChunkY
public int getChunkY()
Description copied from interface:PositionThe chunk coordinate.
-
canSee
public boolean canSee(Point p, float maxdistance)
- Parameters:
p-maxdistance- game space in meters- Returns:
-
set
public Point set(Point point)
overwrites the coordinates with values from another point. Faster then creating a new object-- Parameters:
point- is not modified- Returns:
- itself for chaining
-
getEntitiesNearby
public <T> java.util.LinkedList<T> getEntitiesNearby(float radius, java.lang.Class<T> type)Description copied from interface:PositionGet entities in radius.- Specified by:
getEntitiesNearbyin interfacePosition- Type Parameters:
T- returns only object if type which is the filter- Parameters:
radius- in game dimension pixelstype- the type you want to filter- Returns:
- every entitie in radius
-
setFromCoord
public Point setFromCoord(Coordinate coord)
Set x,y,z based on a coordinate.- Parameters:
coord-- Returns:
-
isObstacle
public boolean isObstacle()
- Returns:
-
-