1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

Merge branch 'object_object_collision' into sapier_experimental

This commit is contained in:
sapier 2012-02-07 17:04:32 +01:00
commit 30f16ded7e
8 changed files with 78 additions and 68 deletions

View file

@ -1302,7 +1302,7 @@ minetest.register_node("default:rail", {
walkable = false,
selection_box = {
type = "fixed",
--fixed = <default>
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
},
material = minetest.digprop_dirtlike(0.75),
})

View file

@ -62,7 +62,6 @@ public:
virtual u8 getType() const = 0;
virtual aabb3f* getCollisionBox() = 0;
protected:
u16 m_id; // 0 is invalid, "no id"
};

36
src/collidableobject.h Normal file
View file

@ -0,0 +1,36 @@
/*
Minetest-c55
Copyright (C) 2012 sapier
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(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
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef __COLLIDABLEOBJECT_H__
#define __COLLIDABLEOBJECT_H__
#include <irrlichttypes.h>
class CollidableObject {
public:
virtual aabb3f* getCollisionBox() = 0;
inline float getFlexibility() { return m_Flexibility; }
inline int getWeight() { return m_Weight; }
protected:
int m_Weight;
float m_Flexibility;
aabb3f m_collisionbox;
};
#endif //__COLLIDABLEOBJECT_H__

View file

@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
*/
#include "collision.h"
#include "collidableobject.h"
#include "mapblock.h"
#include "map.h"
#include "nodedef.h"
@ -266,13 +267,18 @@ collisionMoveResult collisionMoveSimple(Environment* env,
for (core::list<ActiveObject*>::Iterator iter = objects.begin();
iter != objects.end(); iter++)
{
aabb3f* object_collisionbox = (*iter)->getCollisionBox();
//TODO do we need to check if it's really near enough?
if (object_collisionbox != NULL)
CollidableObject* object = dynamic_cast<CollidableObject*>(*iter);
if (object != NULL)
{
cboxes.push_back(*object_collisionbox);
is_unloaded.push_back(false);
is_step_up.push_back(false);
aabb3f* object_collisionbox = object->getCollisionBox();
//TODO do we need to check if it's really near enough?
if (object_collisionbox != NULL)
{
cboxes.push_back(*object_collisionbox);
is_unloaded.push_back(false);
is_step_up.push_back(false);
}
}
}
} //tt3

View file

@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "tile.h"
#include "environment.h"
#include "collision.h"
#include "collidableobject.h"
#include "settings.h"
#include <ICameraSceneNode.h>
#include <ITextSceneNode.h>
@ -1681,7 +1682,7 @@ void MobV2CAO::setLooks(const std::string &looks)
#include "luaentity_common.h"
class LuaEntityCAO : public ClientActiveObject
class LuaEntityCAO : public ClientActiveObject , public CollidableObject
{
private:
core::aabbox3d<f32> m_selection_box;
@ -1701,7 +1702,6 @@ private:
int m_anim_num_frames;
float m_anim_framelength;
float m_anim_timer;
aabb3f m_collisionbox;
public:
LuaEntityCAO(IGameDef *gamedef, ClientEnvironment *env):
@ -2123,7 +2123,7 @@ LuaEntityCAO proto_LuaEntityCAO(NULL, NULL);
PlayerCAO
*/
class PlayerCAO : public ClientActiveObject
class PlayerCAO : public ClientActiveObject, public CollidableObject
{
private:
core::aabbox3d<f32> m_selection_box;
@ -2137,7 +2137,6 @@ private:
LocalPlayer *m_local_player;
float m_damage_visual_timer;
bool m_dead;
aabb3f m_collisionbox;
public:
PlayerCAO(IGameDef *gamedef, ClientEnvironment *env):

View file

@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "serverobject.h"
#include "content_object.h"
#include "collidableobject.h"
class TestSAO : public ServerActiveObject
{
@ -32,7 +33,6 @@ public:
static ServerActiveObject* create(ServerEnvironment *env, v3f pos,
const std::string &data);
void step(float dtime, bool send_recommended);
inline aabb3f* getCollisionBox() { return NULL; }
private:
float m_timer1;
float m_age;
@ -52,7 +52,6 @@ public:
ItemStack createItemStack();
void punch(ServerActiveObject *puncher, float time_from_last_punch);
float getMinimumSavedMovement(){ return 0.1*BS; }
inline aabb3f* getCollisionBox() { return NULL; }
private:
std::string m_itemstring;
bool m_itemstring_changed;
@ -73,7 +72,6 @@ public:
std::string getClientInitializationData();
std::string getStaticData();
void punch(ServerActiveObject *puncher, float time_from_last_punch);
inline aabb3f* getCollisionBox() { return NULL; }
private:
bool m_is_active;
IntervalLimiter m_inactive_interval;
@ -100,7 +98,6 @@ public:
std::string getStaticData();
void punch(ServerActiveObject *puncher, float time_from_last_punch);
bool isPeaceful(){return false;}
inline aabb3f* getCollisionBox() { return NULL; }
private:
void doDamage(u16 d);
@ -129,7 +126,6 @@ public:
void step(float dtime, bool send_recommended);
std::string getClientInitializationData();
std::string getStaticData();
inline aabb3f* getCollisionBox() { return NULL; }
private:
bool m_is_active;
IntervalLimiter m_inactive_interval;
@ -160,7 +156,6 @@ public:
void step(float dtime, bool send_recommended);
void punch(ServerActiveObject *puncher, float time_from_last_punch);
bool isPeaceful();
inline aabb3f* getCollisionBox() { return NULL; }
private:
void sendPosition();
void setPropertyDefaults();
@ -198,7 +193,7 @@ private:
struct LuaEntityProperties;
class LuaEntitySAO : public ServerActiveObject
class LuaEntitySAO : public ServerActiveObject, public CollidableObject
{
public:
LuaEntitySAO(ServerEnvironment *env, v3f pos,
@ -245,7 +240,6 @@ private:
v3f m_last_sent_velocity;
float m_last_sent_position_timer;
float m_last_sent_move_precision;
aabb3f m_collisionbox;
};
#endif

View file

@ -362,15 +362,6 @@ PointedThing getPointedThing(Client *client, v3f player_position,
if(!isPointableNode(n, client, liquids_pointable))
continue;
v3s16 facedirs[6] = {
v3s16(-1,0,0),
v3s16(1,0,0),
v3s16(0,-1,0),
v3s16(0,1,0),
v3s16(0,0,-1),
v3s16(0,0,1),
};
std::vector<aabb3f> boxes = n.getSelectionBoxes(client->ndef());
v3s16 np(x,y,z);
@ -384,52 +375,37 @@ PointedThing getPointedThing(Client *client, v3f player_position,
box.MinEdge += npf;
box.MaxEdge += npf;
f32 d = 0.001*BS;
aabb3f faceboxes[6] = {
// X-
aabb3f(
box.MinEdge.X, box.MinEdge.Y, box.MinEdge.Z,
box.MinEdge.X+d, box.MaxEdge.Y, box.MaxEdge.Z
),
// X+
aabb3f(
box.MaxEdge.X-d, box.MinEdge.Y, box.MinEdge.Z,
box.MaxEdge.X, box.MaxEdge.Y, box.MaxEdge.Z
),
// Y-
aabb3f(
box.MinEdge.X, box.MinEdge.Y, box.MinEdge.Z,
box.MaxEdge.X, box.MinEdge.Y+d, box.MaxEdge.Z
),
// Y+
aabb3f(
box.MinEdge.X, box.MaxEdge.Y-d, box.MinEdge.Z,
box.MaxEdge.X, box.MaxEdge.Y, box.MaxEdge.Z
),
// Z-
aabb3f(
box.MinEdge.X, box.MinEdge.Y, box.MinEdge.Z,
box.MaxEdge.X, box.MaxEdge.Y, box.MinEdge.Z+d
),
// Z+
aabb3f(
box.MinEdge.X, box.MinEdge.Y, box.MaxEdge.Z-d,
box.MaxEdge.X, box.MaxEdge.Y, box.MaxEdge.Z
),
};
for(u16 j=0; j<6; j++)
{
v3f centerpoint = faceboxes[j].getCenter();
v3s16 facedir = g_6dirs[j];
aabb3f facebox = box;
f32 d = 0.001*BS;
if(facedir.X > 0)
facebox.MinEdge.X = facebox.MaxEdge.X-d;
else if(facedir.X < 0)
facebox.MaxEdge.X = facebox.MinEdge.X+d;
else if(facedir.Y > 0)
facebox.MinEdge.Y = facebox.MaxEdge.Y-d;
else if(facedir.Y < 0)
facebox.MaxEdge.Y = facebox.MinEdge.Y+d;
else if(facedir.Z > 0)
facebox.MinEdge.Z = facebox.MaxEdge.Z-d;
else if(facedir.Z < 0)
facebox.MaxEdge.Z = facebox.MinEdge.Z+d;
v3f centerpoint = facebox.getCenter();
f32 distance = (centerpoint - camera_position).getLength();
if(distance >= mindistance)
continue;
if(!faceboxes[j].intersectsWithLine(shootline))
if(!facebox.intersectsWithLine(shootline))
continue;
v3s16 np_above = floatToInt(centerpoint + intToFloat(facedir, d), BS);
result.type = POINTEDTHING_NODE;
result.node_undersurface = np;
result.node_abovesurface = np+facedirs[j];
result.node_abovesurface = np_above;
mindistance = distance;
hilightboxes.clear();

View file

@ -22,13 +22,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "player.h"
#include "serverobject.h"
#include "collidableobject.h"
#include "content_object.h" // Object type IDs
/*
Player on the server
*/
class ServerRemotePlayer : public Player, public ServerActiveObject
class ServerRemotePlayer : public Player, public ServerActiveObject , public CollidableObject
{
public:
ServerRemotePlayer(ServerEnvironment *env);
@ -96,7 +97,6 @@ public:
aabb3f* getCollisionBox();
private:
bool m_position_not_sent;
aabb3f m_collisionbox;
};
#endif