Browse Source

Exposed AnimationTriggerPoint to script.
Exposed Material::SetTechnique() to script.
Added camera functions from Magic.Lixin.

Lasse Öörni 12 years ago
parent
commit
c55c9cf064

+ 16 - 2
Docs/ScriptAPI.dox

@@ -108,6 +108,8 @@ namespace Urho3D
 \section ScriptAPI_GlobalConstants Global constants
 - float M_INFINITY
 - float M_EPSILON
+- float M_DEGTORAD
+- float M_RADTODEG
 - int LOG_DEBUG
 - int LOG_INFO
 - int LOG_WARNING
@@ -1604,6 +1606,8 @@ Methods:<br>
 - void SetOrthoSize(const Vector2&)
 - Frustum GetSplitFrustum(float, float) const
 - Ray GetScreenRay(float, float)
+- Vector2 WorldToScreenPoint(const Vector3&)
+- Vector3 ScreenToWorldPoint(const Vector3&)
 - float GetDistance(const Vector3&) const
 - float GetDistanceSquared(const Vector3&) const
 
@@ -1892,6 +1896,7 @@ Methods:<br>
 - void SendEvent(const String&, VariantMap& arg1 = VariantMap ( ))
 - bool Load(File@)
 - bool Save(File@)
+- void SetTechnique(uint, Technique@, uint arg2 = 0, float arg3 = 0.0)
 - void SetUVTransform(const Vector2&, float, const Vector2&)
 - void SetUVTransform(const Vector2&, float, float)
 - void RemoveShaderParameter(const String&)
@@ -1906,7 +1911,7 @@ Properties:<br>
 - uint memoryUse (readonly)
 - uint useTimer (readonly)
 - uint numTechniques
-- Technique@[] technique (readonly)
+- Technique@[] techniques (readonly)
 - Vector4[] shaderParameters
 - Texture@[] textures
 - bool occlusion (readonly)
@@ -1937,6 +1942,13 @@ Properties:<br>
 - uint numMorphs (readonly)
 
 
+AnimationTriggerPoint
+
+Properties:<br>
+- float time
+- Variant data
+
+
 Animation
 
 Methods:<br>
@@ -1958,7 +1970,8 @@ Properties:<br>
 - String animationName (readonly)
 - float length (readonly)
 - uint numTracks (readonly)
-- uint numTriggers (readonly)
+- uint numTriggers
+- AnimationTriggerPoint@[] triggers (readonly)
 
 
 Drawable
@@ -4862,6 +4875,7 @@ Properties:<br>
 - float ccdRadius
 - float ccdMotionThreshold
 - bool useGravity
+- Vector3 gravityOverride
 - bool phantom
 - bool kinematic
 - bool active (readonly)

+ 18 - 1
Engine/Engine/GraphicsAPI.cpp

@@ -72,6 +72,8 @@ static void RegisterCamera(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Camera", "void SetOrthoSize(const Vector2&in)", asMETHODPR(Camera, SetOrthoSize, (const Vector2&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("Camera", "Frustum GetSplitFrustum(float, float) const", asMETHOD(Camera, GetSplitFrustum), asCALL_THISCALL);
     engine->RegisterObjectMethod("Camera", "Ray GetScreenRay(float, float)", asMETHOD(Camera, GetScreenRay), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Camera", "Vector2 WorldToScreenPoint(const Vector3&in)", asMETHOD(Camera, WorldToScreenPoint), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Camera", "Vector3 ScreenToWorldPoint(const Vector3&in)", asMETHOD(Camera, ScreenToWorldPoint), asCALL_THISCALL);
     engine->RegisterObjectMethod("Camera", "float GetDistance(const Vector3&in) const", asMETHOD(Camera, GetDistance), asCALL_THISCALL);
     engine->RegisterObjectMethod("Camera", "float GetDistanceSquared(const Vector3&in) const", asMETHOD(Camera, GetDistanceSquared), asCALL_THISCALL);
     engine->RegisterObjectMethod("Camera", "void set_nearClip(float)", asMETHOD(Camera, SetNearClip), asCALL_THISCALL);
@@ -536,13 +538,14 @@ static void RegisterMaterial(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Technique", "Pass@+ get_passes(StringHash)", asMETHOD(Technique, GetPass), asCALL_THISCALL);
     
     RegisterResource<Material>(engine, "Material");
+    engine->RegisterObjectMethod("Material", "void SetTechnique(uint, Technique@+, uint qualityLevel = 0, float lodDistance = 0.0)", asMETHOD(Material, SetTechnique), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "void SetUVTransform(const Vector2&in, float, const Vector2&in)", asMETHODPR(Material, SetUVTransform, (const Vector2&, float, const Vector2&), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "void SetUVTransform(const Vector2&in, float, float)", asMETHODPR(Material, SetUVTransform, (const Vector2&, float, float), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "void RemoveShaderParameter(const String&in)", asMETHOD(Material, RemoveShaderParameter), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "Material@ Clone(const String&in cloneName = String()) const", asFUNCTION(MaterialClone), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Material", "void set_numTechniques(uint)", asMETHOD(Material, SetNumTechniques), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "uint get_numTechniques() const", asMETHOD(Material, GetNumTechniques), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Material", "Technique@+ get_technique(uint)", asMETHOD(Material, GetTechnique), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Material", "Technique@+ get_techniques(uint)", asMETHOD(Material, GetTechnique), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "void set_shaderParameters(const String&in, const Vector4&in)", asMETHOD(Material, SetShaderParameter), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "const Vector4& get_shaderParameters(const String&in) const", asMETHOD(Material, GetShaderParameter), asCALL_THISCALL);
     engine->RegisterObjectMethod("Material", "void set_textures(uint, Texture@+)", asMETHOD(Material, SetTexture), asCALL_THISCALL);
@@ -566,8 +569,20 @@ static void RegisterModel(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Model", "uint get_numMorphs() const", asMETHOD(Model, GetNumMorphs), asCALL_THISCALL);
 }
 
+static AnimationTriggerPoint* AnimationGetTrigger(unsigned index, Animation* animation)
+{
+    const Vector<AnimationTriggerPoint>& points = animation->GetTriggers();
+    return index < points.Size() ? const_cast<AnimationTriggerPoint*>(&points[index]) : (AnimationTriggerPoint*)0;
+}
+
 static void RegisterAnimation(asIScriptEngine* engine)
 {
+    engine->RegisterObjectType("AnimationTriggerPoint", 0, asOBJ_REF);
+    engine->RegisterObjectBehaviour("AnimationTriggerPoint", asBEHAVE_ADDREF, "void f()", asFUNCTION(FakeAddRef), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectBehaviour("AnimationTriggerPoint", asBEHAVE_RELEASE, "void f()", asFUNCTION(FakeReleaseRef), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectProperty("AnimationTriggerPoint", "float time", offsetof(AnimationTriggerPoint, time_));
+    engine->RegisterObjectProperty("AnimationTriggerPoint", "Variant data", offsetof(AnimationTriggerPoint, data_));
+    
     RegisterResource<Animation>(engine, "Animation");
     engine->RegisterObjectMethod("Animation", "const String& get_animationName() const", asMETHOD(Animation, GetAnimationName), asCALL_THISCALL);
     engine->RegisterObjectMethod("Animation", "void AddTrigger(float, bool, const Variant&in)", asMETHOD(Animation, AddTrigger), asCALL_THISCALL);
@@ -575,6 +590,8 @@ static void RegisterAnimation(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Animation", "void RemoveAllTriggers()", asMETHOD(Animation, RemoveAllTriggers), asCALL_THISCALL);
     engine->RegisterObjectMethod("Animation", "float get_length() const", asMETHOD(Animation, GetLength), asCALL_THISCALL);
     engine->RegisterObjectMethod("Animation", "uint get_numTracks() const", asMETHOD(Animation, GetNumTracks), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Animation", "void set_numTriggers(uint)", asMETHOD(Animation, SetNumTriggers), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Animation", "AnimationTriggerPoint@+ get_triggers(uint) const", asFUNCTION(AnimationGetTrigger), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("Animation", "uint get_numTriggers() const", asMETHOD(Animation, GetNumTriggers), asCALL_THISCALL);
 }
 

+ 2 - 0
Engine/Engine/MathAPI.cpp

@@ -71,6 +71,8 @@ static void RegisterMathFunctions(asIScriptEngine* engine)
 {
     engine->RegisterGlobalProperty("const float M_INFINITY", (void*)&M_INFINITY);
     engine->RegisterGlobalProperty("const float M_EPSILON", (void*)&M_EPSILON);
+    engine->RegisterGlobalProperty("const float M_DEGTORAD", (void*)&M_DEGTORAD);
+    engine->RegisterGlobalProperty("const float M_RADTODEG", (void*)&M_RADTODEG);
     
     engine->RegisterGlobalFunction("bool Equals(float, float)", asFUNCTION(Equals), asCALL_CDECL);
     engine->RegisterGlobalFunction("float Sin(float)", asFUNCTION(Sin), asCALL_CDECL);

+ 5 - 0
Engine/Graphics/Animation.cpp

@@ -248,6 +248,11 @@ void Animation::RemoveAllTriggers()
     triggers_.Clear();
 }
 
+void Animation::SetNumTriggers(unsigned num)
+{
+    triggers_.Resize(num);
+}
+
 const AnimationTrack* Animation::GetTrack(unsigned index) const
 {
     return index < tracks_.Size() ? &tracks_[index] : 0;

+ 8 - 0
Engine/Graphics/Animation.h

@@ -62,6 +62,12 @@ struct AnimationTrack
 /// %Animation trigger point.
 struct AnimationTriggerPoint
 {
+    /// Construct.
+    AnimationTriggerPoint() :
+        time_(0.0f)
+    {
+    }
+    
     /// Trigger time.
     float time_;
     /// Trigger data.
@@ -102,6 +108,8 @@ public:
     void RemoveTrigger(unsigned index);
     /// Remove all trigger points.
     void RemoveAllTriggers();
+    /// Resize trigger point vector.
+    void SetNumTriggers(unsigned num);
     
     /// Return animation name.
     const String& GetAnimationName() const { return animationName_; }

+ 28 - 0
Engine/Graphics/Camera.cpp

@@ -290,6 +290,34 @@ Ray Camera::GetScreenRay(float x, float y)
     return ret;
 }
 
+Vector2 Camera::WorldToScreenPoint(const Vector3& worldPos)
+{
+    Vector3 eyeSpacePos = GetInverseWorldTransform() * worldPos;
+    Vector2 ret;
+    
+    if(eyeSpacePos.z_ > 0.0f)
+    {
+        Vector3 screenSpacePos = GetProjection(false) * eyeSpacePos;
+        ret.x_ = screenSpacePos.x_;
+        ret.y_ = screenSpacePos.y_;
+    }
+    else
+    {
+        ret.x_ = (-eyeSpacePos.x_ > 0.0f) ? -1.0f : 1.0f;
+        ret.y_ = (-eyeSpacePos.y_ > 0.0f) ? -1.0f : 1.0f;
+    }
+    
+    ret.x_ = (ret.x_ / 2.0f) + 0.5f;
+    ret.y_ = 1.0f - ((ret.y_ / 2.0f) + 0.5f);
+    return ret;
+}
+
+Vector3 Camera::ScreenToWorldPoint(const Vector3& screenPos)
+{
+    Ray ray = GetScreenRay(screenPos.x_, screenPos.y_);
+    return ray.origin_ + ray.direction_ * screenPos.z_;
+}
+
 const Frustum& Camera::GetFrustum() const
 {
     if (frustumDirty_)

+ 5 - 1
Engine/Graphics/Camera.h

@@ -119,8 +119,12 @@ public:
     Frustum GetViewSpaceFrustum() const;
     /// Return split frustum in view space.
     Frustum GetViewSpaceSplitFrustum(float nearClip, float farClip) const;
-    /// Return ray corresponding to screen coordinates (0.0 to 1.0.)
+    /// Return ray corresponding to normalized screen coordinates (0.0 to 1.0.)
     Ray GetScreenRay(float x, float y);
+    // Convert a world space point to normalized screen coordinates (0.0 - 1.0).
+    Vector2 WorldToScreenPoint(const Vector3& worldPos);
+    // Convert normalized screen coordinates (0.0 - 1.0) and depth to a world space point.
+    Vector3 ScreenToWorldPoint(const Vector3& screenPos);
     /// Return forward vector.
     Vector3 GetForwardVector();
     /// Return right vector.