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 Point
add(float[] vector)
Add a vector to the positionPoint
add(float x, float y, float z)
Add a vector to the positionPoint
add(com.badlogic.gdx.math.Vector2 vector)
Add a vector to the positionPoint
add(com.badlogic.gdx.math.Vector3 vector)
Add a vector to the positionboolean
canSee(Point p, float maxdistance)
Point
cpy()
avoid this method because it creates a new instance.float
distanceTo(AbstractGameObject object)
float
distanceTo(Point point)
float
distanceTo(Position pos)
float
distanceToHorizontal(AbstractGameObject object)
checks only x and y.float
distanceToHorizontal(Point point)
checks only x and y.float
distanceToHorizontal(Position pos)
checks only x and y.float
distanceToHorizontalSquared(AbstractGameObject object)
checks only x and y.float
distanceToHorizontalSquared(Point point)
checks only x and y.float
distanceToHorizontalSquared(Position pos)
checks only x and y.float
distanceToSquared(AbstractGameObject object)
The result is squared for fast comparison.float
distanceToSquared(Point point)
The result is squared for fast comparison.float
distanceToSquared(Position pos)
The result is squared for fast comparison.int
getBlock()
byte
getBlockId()
Get the block at the position.Chunk
getChunk()
int
getChunkX()
The chunk coordinate.int
getChunkY()
The chunk coordinate.Coordinate
getCoord()
May not be copy safe.float
getDistanceToCellCenterX()
Distance to cell center.float
getDistanceToCellCenterY()
Distance to cell center.float
getDistanceToCellCenterZ()
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)Point
getPoint()
May not be copy safe.int
getProjectionSpaceX(GameView view, Camera camera)
equals screen space when zoom=1 with a single, fullscreen camera.int
getProjectionSpaceY(GameView view, Camera camera)
equals screen space when zoom=1 with a single camera.static Point
getShared()
A shared object to pass values without using the heap.int
getViewSpcX()
Calculate position in view space.int
getViewSpcY()
Calculate position in view space.float
getX()
Get the game world position from leftfloat
getY()
Get the game world position from top.float
getZ()
Get the height (z-value) of the coordinate.int
getZGrid()
Get the z in block grid coordinates of the coordinate.float
getZPoint()
Get the z in game world coordinates.boolean
isInMemoryAreaXY()
Checks if the coordiantes are accessable with the currently loaded chunks.boolean
isInMemoryAreaXYZ()
Checks if the position is on the chunks currently in memory.boolean
isObstacle()
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.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.Point
set(Point point)
overwrites the coordinates with values from another point.Point
setFromCoord(Coordinate coord)
Set x,y,z based on a coordinate.Point
setToCenterOfCell()
Relative to the current coordiante field set the offset.void
setZ(float height)
Coordinate
toCoord()
returns coordinate aquivalent.Point
toPoint()
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:Position
Get the z in block grid coordinates of the coordinate. Faster than transforming to coordinate first.
-
getZPoint
public float getZPoint()
Description copied from interface:Position
Get 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:Position
May not be copy safe.
-
toPoint
public Point toPoint()
Description copied from interface:Position
Calculates 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:Position
Get the block at the position. Clamps positions over the map at topmost layer.- Specified by:
getBlockId
in 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:Position
Calculate position in view space.- Specified by:
getViewSpcX
in 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:Position
Calculate position in view space.- Specified by:
getViewSpcY
in 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:Position
equals screen space when zoom=1 with a single, fullscreen camera.- Specified by:
getProjectionSpaceX
in interfacePosition
- Returns:
-
getProjectionSpaceY
public int getProjectionSpaceY(GameView view, Camera camera)
Description copied from interface:Position
equals screen space when zoom=1 with a single camera.- Specified by:
getProjectionSpaceY
in interfacePosition
- Returns:
-
isInMemoryAreaXY
public boolean isInMemoryAreaXY()
Description copied from interface:Position
Checks 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:
isInMemoryAreaXY
in interfacePosition
- Returns:
-
isInMemoryAreaXYZ
public boolean isInMemoryAreaXYZ()
Description copied from interface:Position
Checks if the position is on the chunks currently in memory. Checks all axis'.- Specified by:
isInMemoryAreaXYZ
in 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:
add
in 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:
add
in 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:
distanceTo
in 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:
distanceTo
in interfacePosition
- Parameters:
object
-- Returns:
- the distance from this point to the other object
-
distanceToSquared
public float distanceToSquared(AbstractGameObject object)
Description copied from interface:Position
The result is squared for fast comparison.- Specified by:
distanceToSquared
in 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:Position
The result is squared for fast comparison.- Specified by:
distanceToSquared
in 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:
distanceToHorizontal
in 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:Position
checks only x and y.- Specified by:
distanceToHorizontal
in 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:
distanceToHorizontalSquared
in 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:Position
checks only x and y.- Specified by:
distanceToHorizontalSquared
in 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:Position
get entities in radius (horizontal only)- Specified by:
getEntitiesNearbyHorizontal
in 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:Position
get entities in horizontal radius (like a pipe)- Specified by:
getEntitiesNearbyHorizontal
in interfacePosition
- Parameters:
radius
- in game dimension pixelstype
- whitelist- Returns:
- every entitie in radius
-
getChunkX
public int getChunkX()
Description copied from interface:Position
The chunk coordinate.
-
getChunkY
public int getChunkY()
Description copied from interface:Position
The 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:Position
Get entities in radius.- Specified by:
getEntitiesNearby
in 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:
-
-