2012-03-11 10:02:22 +01:00
|
|
|
/*
|
2013-02-24 18:40:43 +01:00
|
|
|
Minetest
|
2013-02-24 19:38:45 +01:00
|
|
|
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2012-03-11 10:02:22 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2012-06-05 16:56:56 +02:00
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
2012-03-11 10:02:22 +01:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2012-06-05 16:56:56 +02:00
|
|
|
GNU Lesser General Public License for more details.
|
2012-03-11 10:02:22 +01:00
|
|
|
|
2012-06-05 16:56:56 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
2012-03-11 10:02:22 +01:00
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2017-08-17 22:19:39 +02:00
|
|
|
#pragma once
|
2012-03-11 10:02:22 +01:00
|
|
|
|
2012-06-17 00:29:13 +02:00
|
|
|
#include "../irrlichttypes.h"
|
2012-06-17 03:00:31 +02:00
|
|
|
#include "../irr_v3d.h"
|
2012-06-17 00:29:13 +02:00
|
|
|
#include <iostream>
|
2012-03-11 10:02:22 +01:00
|
|
|
#include <string>
|
|
|
|
|
2012-06-17 00:29:13 +02:00
|
|
|
enum PointedThingType
|
2012-03-11 10:02:22 +01:00
|
|
|
{
|
2012-06-17 00:29:13 +02:00
|
|
|
POINTEDTHING_NOTHING,
|
|
|
|
POINTEDTHING_NODE,
|
|
|
|
POINTEDTHING_OBJECT
|
|
|
|
};
|
|
|
|
|
2017-01-04 19:18:40 +01:00
|
|
|
//! An active object or node which is selected by a ray on the map.
|
2012-06-17 00:29:13 +02:00
|
|
|
struct PointedThing
|
2012-03-25 11:48:14 +02:00
|
|
|
{
|
2017-01-04 19:18:40 +01:00
|
|
|
//! The type of the pointed object.
|
2017-06-19 23:54:58 +02:00
|
|
|
PointedThingType type = POINTEDTHING_NOTHING;
|
2017-01-04 19:18:40 +01:00
|
|
|
/*!
|
|
|
|
* Only valid if type is POINTEDTHING_NODE.
|
|
|
|
* The coordinates of the node which owns the
|
|
|
|
* nodebox that the ray hits first.
|
|
|
|
* This may differ from node_real_undersurface if
|
|
|
|
* a nodebox exceeds the limits of its node.
|
|
|
|
*/
|
2012-06-17 00:29:13 +02:00
|
|
|
v3s16 node_undersurface;
|
2017-01-04 19:18:40 +01:00
|
|
|
/*!
|
|
|
|
* Only valid if type is POINTEDTHING_NODE.
|
|
|
|
* The coordinates of the last node the ray intersects
|
|
|
|
* before node_undersurface. Same as node_undersurface
|
|
|
|
* if the ray starts in a nodebox.
|
|
|
|
*/
|
2012-06-17 00:29:13 +02:00
|
|
|
v3s16 node_abovesurface;
|
2017-01-04 19:18:40 +01:00
|
|
|
/*!
|
|
|
|
* Only valid if type is POINTEDTHING_NODE.
|
|
|
|
* The coordinates of the node which contains the
|
|
|
|
* point of the collision and the nodebox of the node.
|
|
|
|
*/
|
|
|
|
v3s16 node_real_undersurface;
|
2016-07-23 21:11:20 +02:00
|
|
|
/*!
|
|
|
|
* Only valid if type is POINTEDTHING_OBJECT.
|
|
|
|
* The ID of the object the ray hit.
|
|
|
|
*/
|
|
|
|
s16 object_id = -1;
|
2017-01-04 19:18:40 +01:00
|
|
|
/*!
|
|
|
|
* Only valid if type isn't POINTEDTHING_NONE.
|
|
|
|
* First intersection point of the ray and the nodebox.
|
|
|
|
*/
|
|
|
|
v3f intersection_point;
|
|
|
|
/*!
|
|
|
|
* Only valid if type isn't POINTEDTHING_NONE.
|
|
|
|
* Normal vector of the intersection.
|
|
|
|
* This is perpendicular to the face the ray hits,
|
|
|
|
* points outside of the box and it's length is 1.
|
|
|
|
*/
|
|
|
|
v3s16 intersection_normal;
|
|
|
|
/*!
|
2016-07-23 21:11:20 +02:00
|
|
|
* Square of the distance between the pointing
|
|
|
|
* ray's start point and the intersection point.
|
2017-01-04 19:18:40 +01:00
|
|
|
*/
|
2016-07-23 21:11:20 +02:00
|
|
|
f32 distanceSq = 0;
|
2012-06-17 00:29:13 +02:00
|
|
|
|
2016-07-23 21:11:20 +02:00
|
|
|
//! Constructor for POINTEDTHING_NOTHING
|
2017-06-19 23:54:58 +02:00
|
|
|
PointedThing() {};
|
2016-07-23 21:11:20 +02:00
|
|
|
//! Constructor for POINTEDTHING_NODE
|
|
|
|
PointedThing(const v3s16 &under, const v3s16 &above,
|
|
|
|
const v3s16 &real_under, const v3f &point, const v3s16 &normal,
|
|
|
|
f32 distSq);
|
|
|
|
//! Constructor for POINTEDTHING_OBJECT
|
|
|
|
PointedThing(s16 id, const v3f &point, const v3s16 &normal, f32 distSq);
|
2012-06-17 00:29:13 +02:00
|
|
|
std::string dump() const;
|
|
|
|
void serialize(std::ostream &os) const;
|
|
|
|
void deSerialize(std::istream &is);
|
2017-01-04 19:18:40 +01:00
|
|
|
/*!
|
|
|
|
* This function ignores the intersection point and normal.
|
|
|
|
*/
|
2012-06-17 00:29:13 +02:00
|
|
|
bool operator==(const PointedThing &pt2) const;
|
|
|
|
bool operator!=(const PointedThing &pt2) const;
|
|
|
|
};
|