2009-04-19 18:07:22 +00:00
#region = = = = = = = = = = = = = = = = = = Copyright ( c ) 2007 Pascal vd Heiden
/ *
* Copyright ( c ) 2007 Pascal vd Heiden , www . codeimp . com
* This program is released under GNU General Public License
*
* 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 .
*
* /
#endregion
#region = = = = = = = = = = = = = = = = = = Namespaces
using System ;
using System.Collections.Generic ;
using CodeImp.DoomBuilder.Map ;
using SlimDX.Direct3D9 ;
using SlimDX ;
using CodeImp.DoomBuilder.Geometry ;
using CodeImp.DoomBuilder.Data ;
using CodeImp.DoomBuilder.Rendering ;
2013-04-11 11:04:16 +00:00
using CodeImp.DoomBuilder.GZBuilder.Data ; //mxd
2012-04-17 19:13:47 +00:00
2009-04-19 18:07:22 +00:00
#endregion
namespace CodeImp.DoomBuilder.VisualModes
{
public abstract class VisualThing : IVisualPickable , ID3DResource , IComparable < VisualThing >
{
#region = = = = = = = = = = = = = = = = = = Constants
2013-03-18 13:52:27 +00:00
protected const int FIXED_RADIUS = 8 ; //mxd. Used to render things with zero width and radius
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Variables
// Thing
private Thing thing ;
// Texture
private ImageData texture ;
// Geometry
private WorldVertex [ ] vertices ;
private VertexBuffer geobuffer ;
private bool updategeo ;
private int triangles ;
// Rendering
private int renderpass ;
private Matrix orientation ;
private Matrix position ;
private Matrix cagescales ;
private bool billboard ;
private Vector2D pos2d ;
private float cameradistance ;
private int cagecolor ;
2013-03-18 13:52:27 +00:00
protected bool sizeless ; //mxd. Used to render visual things with 0 width and height
2009-05-01 20:31:17 +00:00
// Selected?
protected bool selected ;
2009-04-19 18:07:22 +00:00
// Disposing
private bool isdisposed = false ;
2012-04-17 19:13:47 +00:00
//mxd
private int cameraDistance3D ;
private int thingHeight ;
2013-06-14 11:40:18 +00:00
protected Matrix scale ; //mxd. Used in model rendering
2012-04-17 19:13:47 +00:00
//mxd. light properties
2013-07-29 08:50:50 +00:00
private DynamicLightType lightType ;
private DynamicLightRenderStyle lightRenderStyle ;
2012-04-17 19:13:47 +00:00
private Color4 lightColor ;
2012-04-25 11:44:36 +00:00
private float lightRadius ; //current radius. used in light animation
2012-05-11 12:28:20 +00:00
private float lightPrimaryRadius ;
private float lightSecondaryRadius ;
2012-04-17 19:13:47 +00:00
private Vector3 position_v3 ;
private float lightDelta ; //used in light animation
private Vector3 [ ] boundingBox ;
2012-06-01 10:17:47 +00:00
//gldefs light
private Vector3 lightOffset ;
private int lightInterval ;
private bool isGldefsLight ;
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Properties
internal VertexBuffer GeometryBuffer { get { return geobuffer ; } }
internal bool NeedsUpdateGeo { get { return updategeo ; } }
internal int Triangles { get { return triangles ; } }
internal int RenderPassInt { get { return renderpass ; } }
internal Matrix Orientation { get { return orientation ; } }
internal Matrix Position { get { return position ; } }
internal Matrix CageScales { get { return cagescales ; } }
internal int CageColor { get { return cagecolor ; } }
2012-04-17 19:13:47 +00:00
//mxd
internal int VertexColor { get { return vertices . Length > 0 ? vertices [ 0 ] . c : 0 ; } }
2013-06-14 11:40:18 +00:00
internal Matrix Scale { get { return scale ; } }
2012-04-17 19:13:47 +00:00
public int CameraDistance3D { get { return cameraDistance3D ; } }
2013-03-18 13:52:27 +00:00
public bool Sizeless { get { return sizeless ; } }
2012-06-01 10:17:47 +00:00
public Vector3 Center {
2013-08-08 11:04:13 +00:00
get {
if ( isGldefsLight ) return position_v3 + lightOffset ;
2012-06-01 10:17:47 +00:00
return new Vector3 ( position_v3 . X , position_v3 . Y , position_v3 . Z + thingHeight / 2 ) ;
}
}
2013-08-08 11:04:13 +00:00
public Vector3D CenterV3D { get { return D3DDevice . V3D ( Center ) ; } }
2012-04-17 19:13:47 +00:00
public Vector3 PositionV3 { get { return position_v3 ; } }
public Vector3 [ ] BoundingBox { get { return boundingBox ; } }
//mxd. light properties
2013-07-29 08:50:50 +00:00
public DynamicLightType LightType { get { return lightType ; } }
2012-04-25 11:44:36 +00:00
public float LightRadius { get { return lightRadius ; } }
2013-07-29 08:50:50 +00:00
public DynamicLightRenderStyle LightRenderStyle { get { return lightRenderStyle ; } }
2012-04-17 19:13:47 +00:00
public Color4 LightColor { get { return lightColor ; } }
2009-04-19 18:07:22 +00:00
/// <summary>
/// Set to True to use billboarding for this thing. When using billboarding,
/// the geometry will be rotated on the XY plane to face the camera.
/// </summary>
public bool Billboard { get { return billboard ; } set { billboard = value ; } }
/// <summary>
/// Returns the Thing that this VisualThing is created for.
/// </summary>
public Thing Thing { get { return thing ; } }
/// <summary>
/// Render pass in which this geometry must be rendered. Default is Solid.
/// </summary>
public RenderPass RenderPass { get { return ( RenderPass ) renderpass ; } set { renderpass = ( int ) value ; } }
/// <summary>
/// Image to use as texture on the geometry.
/// </summary>
public ImageData Texture { get { return texture ; } set { texture = value ; } }
/// <summary>
/// Disposed or not?
/// </summary>
public bool IsDisposed { get { return isdisposed ; } }
2009-05-01 20:31:17 +00:00
/// <summary>
/// Selected or not? This is only used by the core to determine what color to draw it with.
/// </summary>
public bool Selected { get { return selected ; } set { selected = value ; } }
2009-04-19 18:07:22 +00:00
#endregion
#region = = = = = = = = = = = = = = = = = = Constructor / Destructor
// Constructor
public VisualThing ( Thing t )
{
// Initialize
this . thing = t ;
this . renderpass = ( int ) RenderPass . Mask ;
this . billboard = true ;
this . orientation = Matrix . Identity ;
this . position = Matrix . Identity ;
this . cagescales = Matrix . Identity ;
2013-06-14 11:40:18 +00:00
this . scale = Matrix . Identity ; //mxd
2012-04-17 19:13:47 +00:00
//mxd
2013-07-29 08:50:50 +00:00
lightType = DynamicLightType . NONE ;
lightRenderStyle = DynamicLightRenderStyle . NONE ;
2012-05-11 12:28:20 +00:00
lightPrimaryRadius = - 1 ;
lightSecondaryRadius = - 1 ;
2012-06-01 10:17:47 +00:00
lightInterval = - 1 ;
2012-04-17 19:13:47 +00:00
lightColor = new Color4 ( ) ;
boundingBox = new Vector3 [ 9 ] ;
2009-04-19 18:07:22 +00:00
// Register as resource
General . Map . Graphics . RegisterResource ( this ) ;
}
// Disposer
public virtual void Dispose ( )
{
// Not already disposed?
if ( ! isdisposed )
{
// Clean up
if ( geobuffer ! = null ) geobuffer . Dispose ( ) ;
geobuffer = null ;
// Unregister resource
General . Map . Graphics . UnregisterResource ( this ) ;
// Done
isdisposed = true ;
}
}
#endregion
#region = = = = = = = = = = = = = = = = = = Methods
2012-05-21 23:51:32 +00:00
2009-04-19 18:07:22 +00:00
// This sets the distance from the camera
internal void CalculateCameraDistance ( Vector2D campos )
{
cameradistance = Vector2D . DistanceSq ( pos2d , campos ) ;
}
2012-04-17 19:13:47 +00:00
//mxd
internal void CalculateCameraDistance3D ( Vector3 campos ) {
2012-08-10 12:08:08 +00:00
cameraDistance3D = ( int ) Vector3 . DistanceSquared ( PositionV3 , campos ) ;
2012-04-17 19:13:47 +00:00
}
2009-04-19 18:07:22 +00:00
// This is called before a device is reset
// (when resized or display adapter was changed)
public void UnloadResource ( )
{
// Trash geometry buffer
if ( geobuffer ! = null ) geobuffer . Dispose ( ) ;
geobuffer = null ;
updategeo = true ;
}
// This is called resets when the device is reset
// (when resized or display adapter was changed)
public void ReloadResource ( )
{
// Make new geometry
//Update();
}
/// <summary>
/// Sets the size of the cage around the thing geometry.
/// </summary>
public void SetCageSize ( float radius , float height )
{
cagescales = Matrix . Scaling ( radius , radius , height ) ;
2012-04-17 19:13:47 +00:00
//mxd
thingHeight = ( int ) height ;
2009-04-19 18:07:22 +00:00
}
/// <summary>
/// Sets the color of the cage around the thing geometry.
/// </summary>
public void SetCageColor ( PixelColor color )
{
cagecolor = color . ToInt ( ) ;
}
/// <summary>
/// This sets the position to use for the thing geometry.
/// </summary>
public void SetPosition ( Vector3D pos )
{
pos2d = new Vector2D ( pos ) ;
2012-04-17 19:13:47 +00:00
//mxd
position_v3 = D3DDevice . V3 ( pos ) ;
position = Matrix . Translation ( position_v3 ) ;
//mxd. update bounding box
if ( thing . IsModel ) {
updateBoundingBoxForModel ( ) ;
2013-07-29 08:50:50 +00:00
} else if ( lightType ! = DynamicLightType . NONE & & lightRadius > thing . Size ) {
2012-06-19 13:12:28 +00:00
updateBoundingBox ( lightRadius , lightRadius * 2 ) ;
2012-04-17 19:13:47 +00:00
} else {
2012-06-19 13:12:28 +00:00
updateBoundingBox ( ( int ) thing . Size , thingHeight ) ;
2012-04-17 19:13:47 +00:00
}
2009-04-19 18:07:22 +00:00
}
/// <summary>
/// This sets the orientation to use for the thing geometry. When using this, you may want to turn off billboarding.
/// </summary>
public void SetOrientation ( Vector3D angles )
{
orientation = Matrix . RotationYawPitchRoll ( angles . z , angles . y , angles . x ) ;
}
// This sets the vertices for the thing sprite
protected void SetVertices ( ICollection < WorldVertex > verts )
{
2012-06-01 19:53:14 +00:00
// Copy vertices
2009-04-19 18:07:22 +00:00
vertices = new WorldVertex [ verts . Count ] ;
verts . CopyTo ( vertices , 0 ) ;
triangles = vertices . Length / 3 ;
updategeo = true ;
}
2013-06-14 11:40:18 +00:00
//mxd
protected void SetScale ( float scaleX , float scaleY ) {
scale = Matrix . Scaling ( scaleX , scaleX , scaleY ) ;
}
2009-04-19 18:07:22 +00:00
// This updates the visual thing
public virtual void Update ( )
{
2012-04-17 19:13:47 +00:00
// Do we need to update the geometry buffer?
if ( updategeo )
2009-04-19 18:07:22 +00:00
{
2012-04-17 19:13:47 +00:00
// Trash geometry buffer
if ( geobuffer ! = null ) geobuffer . Dispose ( ) ;
geobuffer = null ;
2009-04-19 18:07:22 +00:00
2012-04-17 19:13:47 +00:00
// Any vertics?
if ( vertices . Length > 0 ) {
// Make a new buffer
geobuffer = new VertexBuffer ( General . Map . Graphics . Device , WorldVertex . Stride * vertices . Length ,
Usage . WriteOnly | Usage . Dynamic , VertexFormat . None , Pool . Default ) ;
// Fill the buffer
DataStream bufferstream = geobuffer . Lock ( 0 , WorldVertex . Stride * vertices . Length , LockFlags . Discard ) ;
2013-07-29 08:50:50 +00:00
bufferstream . WriteRange ( vertices ) ;
2012-04-17 19:13:47 +00:00
geobuffer . Unlock ( ) ;
bufferstream . Dispose ( ) ;
}
//mxd. Check if thing is light
2012-06-01 19:53:14 +00:00
checkLightState ( ) ;
2009-04-19 18:07:22 +00:00
// Done
updategeo = false ;
}
}
2012-04-17 19:13:47 +00:00
2012-06-01 19:53:14 +00:00
//mxd
protected void checkLightState ( ) {
//mxd. Check if thing is light
int light_id = Array . IndexOf ( GZBuilder . GZGeneral . GZ_LIGHTS , thing . Type ) ;
if ( light_id ! = - 1 ) {
isGldefsLight = false ;
lightInterval = - 1 ;
updateLight ( light_id ) ;
2012-06-19 13:12:28 +00:00
updateBoundingBox ( lightRadius , lightRadius * 2 ) ;
2012-06-01 19:53:14 +00:00
//check if we have light from GLDEFS
} else if ( General . Map . Data . GldefsEntries . ContainsKey ( thing . Type ) ) {
isGldefsLight = true ;
updateGldefsLight ( ) ;
2012-06-19 13:12:28 +00:00
updateBoundingBox ( lightRadius , lightRadius * 2 ) ;
2012-06-01 19:53:14 +00:00
} else {
if ( thing . IsModel ) {
updateBoundingBoxForModel ( ) ;
} else {
2012-06-19 13:12:28 +00:00
updateBoundingBox ( ( int ) thing . Size , thingHeight ) ;
2012-06-01 19:53:14 +00:00
}
2013-07-29 08:50:50 +00:00
lightType = DynamicLightType . NONE ;
2012-06-01 19:53:14 +00:00
lightRadius = - 1 ;
lightPrimaryRadius = - 1 ;
lightSecondaryRadius = - 1 ;
2013-07-29 08:50:50 +00:00
lightRenderStyle = DynamicLightRenderStyle . NONE ;
2012-06-01 19:53:14 +00:00
lightInterval = - 1 ;
isGldefsLight = false ;
}
}
2012-05-11 12:28:20 +00:00
//used in ColorPicker to update light
public void UpdateLight ( ) {
int light_id = Array . IndexOf ( GZBuilder . GZGeneral . GZ_LIGHTS , thing . Type ) ;
if ( light_id ! = - 1 ) {
updateLight ( light_id ) ;
2012-06-19 13:12:28 +00:00
updateBoundingBox ( lightRadius , lightRadius * 2 ) ;
2012-05-11 12:28:20 +00:00
}
}
2012-04-17 19:13:47 +00:00
//mxd update light info
private void updateLight ( int light_id ) {
2012-04-25 11:44:36 +00:00
float scaled_intensity = 255.0f / General . Settings . GZDynamicLightIntensity ;
2012-04-17 19:13:47 +00:00
if ( light_id < GZBuilder . GZGeneral . GZ_LIGHT_TYPES [ 2 ] ) { //if it's gzdoom light
int n ;
if ( light_id < GZBuilder . GZGeneral . GZ_LIGHT_TYPES [ 0 ] ) {
n = 0 ;
2013-07-29 08:50:50 +00:00
lightRenderStyle = DynamicLightRenderStyle . NORMAL ;
2012-04-23 21:35:48 +00:00
//lightColor.Alpha used in shader to perform some calculations based on light type
2012-04-25 11:44:36 +00:00
lightColor = new Color4 ( ( float ) lightRenderStyle / 100.0f , ( float ) thing . Args [ 0 ] / scaled_intensity , ( float ) thing . Args [ 1 ] / scaled_intensity , ( float ) thing . Args [ 2 ] / scaled_intensity ) ;
2012-04-17 19:13:47 +00:00
} else if ( light_id < GZBuilder . GZGeneral . GZ_LIGHT_TYPES [ 1 ] ) {
n = 10 ;
2013-07-29 08:50:50 +00:00
lightRenderStyle = DynamicLightRenderStyle . ADDITIVE ;
2012-04-25 11:44:36 +00:00
lightColor = new Color4 ( ( float ) lightRenderStyle / 100.0f , ( float ) thing . Args [ 0 ] / scaled_intensity , ( float ) thing . Args [ 1 ] / scaled_intensity , ( float ) thing . Args [ 2 ] / scaled_intensity ) ;
2012-04-17 19:13:47 +00:00
} else {
n = 20 ;
2013-07-29 08:50:50 +00:00
lightRenderStyle = DynamicLightRenderStyle . NEGATIVE ;
2012-04-25 11:44:36 +00:00
lightColor = new Color4 ( ( float ) lightRenderStyle / 100.0f , ( float ) thing . Args [ 0 ] / scaled_intensity , ( float ) thing . Args [ 1 ] / scaled_intensity , ( float ) thing . Args [ 2 ] / scaled_intensity ) ;
2012-04-17 19:13:47 +00:00
}
2013-07-29 08:50:50 +00:00
lightType = ( DynamicLightType ) ( thing . Type - 9800 - n ) ;
2012-04-17 19:13:47 +00:00
2013-07-29 08:50:50 +00:00
if ( lightType = = DynamicLightType . SECTOR ) {
2012-04-25 20:13:12 +00:00
int scaler = 1 ;
if ( thing . Sector ! = null )
scaler = thing . Sector . Brightness / 4 ;
2012-05-11 12:28:20 +00:00
lightPrimaryRadius = ( float ) ( thing . Args [ 3 ] * scaler ) * General . Settings . GZDynamicLightRadius ;
2012-04-17 19:13:47 +00:00
} else {
2012-05-11 12:28:20 +00:00
lightPrimaryRadius = ( float ) ( thing . Args [ 3 ] * 2 ) * General . Settings . GZDynamicLightRadius ; //works... that.. way in GZDoom
if ( lightType > 0 )
lightSecondaryRadius = ( float ) ( thing . Args [ 4 ] * 2 ) * General . Settings . GZDynamicLightRadius ;
2012-04-17 19:13:47 +00:00
}
} else { //it's one of vavoom lights
2013-07-29 08:50:50 +00:00
lightRenderStyle = DynamicLightRenderStyle . VAVOOM ;
lightType = ( DynamicLightType ) thing . Type ;
if ( lightType = = DynamicLightType . VAVOOM_COLORED )
2012-04-25 11:44:36 +00:00
lightColor = new Color4 ( ( float ) lightRenderStyle / 100.0f , ( float ) thing . Args [ 1 ] / scaled_intensity , ( float ) thing . Args [ 2 ] / scaled_intensity , ( float ) thing . Args [ 3 ] / scaled_intensity ) ;
2012-04-17 19:13:47 +00:00
else
2012-04-25 11:44:36 +00:00
lightColor = new Color4 ( ( float ) lightRenderStyle / 100.0f , General . Settings . GZDynamicLightIntensity , General . Settings . GZDynamicLightIntensity , General . Settings . GZDynamicLightIntensity ) ;
2012-05-11 12:28:20 +00:00
lightPrimaryRadius = ( float ) ( thing . Args [ 0 ] * 8 ) * General . Settings . GZDynamicLightRadius ;
2012-04-17 19:13:47 +00:00
}
UpdateLightRadius ( ) ;
}
2012-06-01 10:17:47 +00:00
//mxd
private void updateGldefsLight ( ) {
2013-07-29 08:50:50 +00:00
DynamicLightData light = General . Map . Data . GldefsEntries [ thing . Type ] ;
2012-06-01 10:17:47 +00:00
float intensity_mod = General . Settings . GZDynamicLightIntensity ;
float scale_mod = General . Settings . GZDynamicLightRadius ;
//apply settings
2013-07-29 08:50:50 +00:00
lightRenderStyle = light . Subtractive ? DynamicLightRenderStyle . NEGATIVE : DynamicLightRenderStyle . NORMAL ;
2012-06-01 10:17:47 +00:00
lightColor = new Color4 ( ( float ) lightRenderStyle / 100.0f , light . Color . Red * intensity_mod , light . Color . Green * intensity_mod , light . Color . Blue * intensity_mod ) ;
lightOffset = light . Offset ;
lightType = light . Type ;
2013-07-29 08:50:50 +00:00
if ( lightType = = DynamicLightType . SECTOR ) {
2012-06-01 10:17:47 +00:00
lightPrimaryRadius = light . Interval * thing . Sector . Brightness / 5 ;
} else {
lightPrimaryRadius = light . PrimaryRadius * scale_mod ;
lightSecondaryRadius = light . SecondaryRadius * scale_mod ;
}
lightInterval = light . Interval ;
updateLightRadius ( lightInterval ) ;
}
2012-04-17 19:13:47 +00:00
//mxd
public void UpdateLightRadius ( ) {
2012-06-01 10:17:47 +00:00
updateLightRadius ( ( lightInterval ! = - 1 ? lightInterval : thing . AngleDoom ) ) ;
}
//mxd
private void updateLightRadius ( int interval ) {
2013-07-29 08:50:50 +00:00
if ( lightType = = DynamicLightType . NONE ) {
2012-04-17 19:13:47 +00:00
General . ErrorLogger . Add ( ErrorType . Error , "Please check that thing is light before accessing it's PositionAndRadius! You can use lightType, which is -1 if thing isn't light" ) ;
return ;
}
2012-05-11 12:28:20 +00:00
if ( ! General . Settings . GZAnimateLights | | Array . IndexOf ( GZBuilder . GZGeneral . GZ_ANIMATED_LIGHT_TYPES , lightType ) = = - 1 ) {
lightRadius = lightPrimaryRadius ;
2012-04-17 19:13:47 +00:00
return ;
}
2012-07-12 22:34:12 +00:00
float time = General . Clock . CurrentTime ;
2012-05-11 12:28:20 +00:00
2012-06-19 13:12:28 +00:00
float rMin = Math . Min ( lightPrimaryRadius , lightSecondaryRadius ) ;
float rMax = Math . Max ( lightPrimaryRadius , lightSecondaryRadius ) ;
2012-05-11 12:28:20 +00:00
float diff = rMax - rMin ;
2012-04-17 19:13:47 +00:00
//pulse
2013-07-29 08:50:50 +00:00
if ( lightType = = DynamicLightType . PULSE ) {
2012-06-01 10:17:47 +00:00
lightDelta = ( ( float ) Math . Sin ( time / ( interval * 4.0f ) ) + 1.0f ) / 2.0f ; //just playing by the eye here... in [0.0 ... 1.0] interval
2012-05-11 12:28:20 +00:00
lightRadius = rMin + diff * lightDelta ;
2012-04-17 19:13:47 +00:00
//flicker
2013-07-29 08:50:50 +00:00
} else if ( lightType = = DynamicLightType . FLICKER ) {
2012-05-11 12:28:20 +00:00
float delta = ( float ) Math . Sin ( time / 0.1f ) ; //just playing by the eye here...
2012-04-17 19:13:47 +00:00
if ( Math . Sign ( delta ) ! = Math . Sign ( lightDelta ) ) {
lightDelta = delta ;
2012-06-01 10:17:47 +00:00
if ( new Random ( ) . Next ( 0 , 359 ) < interval )
2012-05-11 12:28:20 +00:00
lightRadius = rMax ;
else
lightRadius = rMin ;
2012-04-17 19:13:47 +00:00
}
//random
2013-07-29 08:50:50 +00:00
} else if ( lightType = = DynamicLightType . RANDOM ) {
2012-06-01 10:17:47 +00:00
float delta = ( float ) Math . Sin ( time / ( interval * 9.0f ) ) ; //just playing by the eye here...
2012-04-17 19:13:47 +00:00
if ( Math . Sign ( delta ) ! = Math . Sign ( lightDelta ) )
2012-05-11 12:28:20 +00:00
lightRadius = rMin + ( float ) ( new Random ( ) . Next ( 0 , ( int ) ( diff * 10 ) ) ) / 10.0f ;
2012-04-17 19:13:47 +00:00
lightDelta = delta ;
}
}
//mxd. update bounding box
2012-06-19 13:12:28 +00:00
public void UpdateBoundingBox ( ) {
2012-07-05 13:48:08 +00:00
//updateBoundingBox(lightRadius, lightRadius * 2f);
if ( thing . IsModel ) {
updateBoundingBoxForModel ( ) ;
2013-07-29 08:50:50 +00:00
} else if ( lightType ! = DynamicLightType . NONE & & lightRadius > thing . Size ) {
2012-07-05 13:48:08 +00:00
updateBoundingBox ( lightRadius , lightRadius * 2 ) ;
} else {
updateBoundingBox ( ( int ) thing . Size , thingHeight ) ;
}
2012-06-19 13:12:28 +00:00
}
private void updateBoundingBox ( float width , float height ) {
2012-04-17 19:13:47 +00:00
boundingBox = new Vector3 [ 9 ] ;
boundingBox [ 0 ] = Center ;
2012-04-25 11:44:36 +00:00
float h2 = height / 2.0f ;
2012-04-17 19:13:47 +00:00
2012-04-23 21:35:48 +00:00
boundingBox [ 1 ] = new Vector3 ( position_v3 . X - width , position_v3 . Y - width , Center . Z - h2 ) ;
boundingBox [ 2 ] = new Vector3 ( position_v3 . X + width , position_v3 . Y - width , Center . Z - h2 ) ;
boundingBox [ 3 ] = new Vector3 ( position_v3 . X - width , position_v3 . Y + width , Center . Z - h2 ) ;
boundingBox [ 4 ] = new Vector3 ( position_v3 . X + width , position_v3 . Y + width , Center . Z - h2 ) ;
2012-04-17 19:13:47 +00:00
2012-04-23 21:35:48 +00:00
boundingBox [ 5 ] = new Vector3 ( position_v3 . X - width , position_v3 . Y - width , Center . Z + h2 ) ;
boundingBox [ 6 ] = new Vector3 ( position_v3 . X + width , position_v3 . Y - width , Center . Z + h2 ) ;
boundingBox [ 7 ] = new Vector3 ( position_v3 . X - width , position_v3 . Y + width , Center . Z + h2 ) ;
boundingBox [ 8 ] = new Vector3 ( position_v3 . X + width , position_v3 . Y + width , Center . Z + h2 ) ;
2012-04-17 19:13:47 +00:00
}
//mxd. update bounding box from model bounding box
private void updateBoundingBoxForModel ( ) {
2013-07-29 08:50:50 +00:00
ModelData mde = General . Map . Data . ModeldefEntries [ thing . Type ] ;
2012-04-17 19:13:47 +00:00
int len = mde . Model . BoundingBox . Length ;
boundingBox = new Vector3 [ len ] ;
for ( int i = 0 ; i < len ; i + + ) {
Vector3 v = mde . Model . BoundingBox [ i ] ;
boundingBox [ i ] = new Vector3 ( v . X + position_v3 . X , v . Y + position_v3 . Y , v . Z + position_v3 . Z ) ;
2012-05-20 00:56:59 +00:00
}
2012-04-17 19:13:47 +00:00
}
2009-04-19 18:07:22 +00:00
/// <summary>
/// This is called when the thing must be tested for line intersection. This should reject
/// as fast as possible to rule out all geometry that certainly does not touch the line.
/// </summary>
public virtual bool PickFastReject ( Vector3D from , Vector3D to , Vector3D dir )
{
return false ;
}
/// <summary>
/// This is called when the thing must be tested for line intersection. This should perform
/// accurate hit detection and set u_ray to the position on the ray where this hits the geometry.
/// </summary>
public virtual bool PickAccurate ( Vector3D from , Vector3D to , Vector3D dir , ref float u_ray )
{
return false ;
}
/// <summary>
/// This sorts things by distance from the camera. Farthest first.
/// </summary>
public int CompareTo ( VisualThing other )
{
return Math . Sign ( other . cameradistance - this . cameradistance ) ;
}
#endregion
}
}