Added spinning raccoons and fixed TRansform component bug

This commit is contained in:
Kah Wei 2022-09-28 23:55:44 +08:00
parent 566c12a922
commit 70559204bf
5 changed files with 75 additions and 40 deletions

View File

@ -44,7 +44,7 @@ namespace Sandbox
{
if (mesh.meshName == "Cube.012")
{
handles.push_back(graphicsSystem->AddMesh(
handles.push_back(graphicsSystem->AddMesh(
mesh.header.vertexCount,
mesh.vertexPosition.data(),
mesh.texCoords.data(),
@ -107,9 +107,9 @@ namespace Sandbox
stressTestObjects.emplace_back(entity);
}
auto entity = SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();
auto& renderable = *SHComponentManager::GetComponent_s<SHRenderable>(entity);
auto& transform = *SHComponentManager::GetComponent_s<SHTransformComponent>(entity);
auto raccoonSpin = SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();
auto& renderable = *SHComponentManager::GetComponent_s<SHRenderable>(raccoonSpin);
auto& transform = *SHComponentManager::GetComponent_s<SHTransformComponent>(raccoonSpin);
renderable.Mesh = handles.front();
renderable.SetMaterial(customMat);
@ -137,7 +137,21 @@ namespace Sandbox
//testObjRenderable.SetMaterial(matInst);
SHADE::SHScriptEngine* scriptEngine = static_cast<SHADE::SHScriptEngine*>(SHADE::SHSystemManager::GetSystem<SHADE::SHScriptEngine>());
scriptEngine->AddScript(testObj, "TestScript");
scriptEngine->AddScript(raccoonSpin, "RaccoonSpin");
auto raccoonShowcase = SHEntityManager::CreateEntity<SHRenderable, SHTransformComponent>();
auto& renderableShowcase = *SHComponentManager::GetComponent_s<SHRenderable>(raccoonShowcase);
auto& transformShowcase = *SHComponentManager::GetComponent_s<SHTransformComponent>(raccoonShowcase);
renderableShowcase.Mesh = handles.front();
renderableShowcase.SetMaterial(customMat);
renderableShowcase.GetModifiableMaterial()->SetProperty("data.color", SHVec4(0.0f, 0.0f, 0.0f, 0.0f));
renderableShowcase.GetModifiableMaterial()->SetProperty("data.alpha", 1.0f);
renderableShowcase.GetModifiableMaterial()->SetProperty("data.textureIndex", 1);
transformShowcase.SetWorldPosition({ 3.0f, -1.0f, -1.0f });
transformShowcase.SetLocalScale({ 5.0f, 5.0f, 5.0f });
scriptEngine->AddScript(raccoonShowcase, "RaccoonShowcase");
}
void SBTestScene::Update(float dt)

View File

@ -35,7 +35,7 @@ namespace SHADE
}
void Transform::LocalRotation::set(Vector3 val)
{
GetNativeComponent()->SetLocalPosition(Convert::ToNative(val));
GetNativeComponent()->SetLocalRotation(Convert::ToNative(val));
}
Vector3 Transform::LocalScale::get()
{

View File

@ -0,0 +1,31 @@
using SHADE;
using System;
public class RaccoonShowcase : Script
{
public double RotateSpeed = 1.0;
public Vector3 ScaleSpeed = new Vector3(1.0, 1.0, 0.0);
private Transform Transform;
private double rotation = 0.0;
private Vector3 scale = Vector3.Zero;
private double originalScale = 1.0f;
public RaccoonShowcase(GameObject gameObj) : base(gameObj) {}
protected override void awake()
{
Transform = GetComponent<Transform>();
if (Transform == null)
{
Debug.LogError("Transform is NULL!");
}
originalScale = Transform.LocalScale.z;
}
protected override void update()
{
rotation += RotateSpeed * 0.16;
scale += ScaleSpeed * 0.16;
Transform.LocalRotation = new Vector3(0.0f, rotation, 0.0f);
Transform.LocalScale = new Vector3(System.Math.Abs(System.Math.Sin(scale.x)) * originalScale, System.Math.Abs(System.Math.Cos(scale.y)) * originalScale, System.Math.Abs(System.Math.Sin(scale.z)) * originalScale);
}
}

View File

@ -0,0 +1,24 @@
using SHADE;
using System;
public class RaccoonSpin : Script
{
public double RotateSpeed = 1.0;
private double rotation = 0.0;
private Transform Transform;
public RaccoonSpin(GameObject gameObj) : base(gameObj) { }
protected override void awake()
{
Transform = GetComponent<Transform>();
if (Transform == null)
{
Debug.LogError("Transform is NULL!");
}
}
protected override void update()
{
rotation += RotateSpeed * 0.16;
Transform.LocalRotation = new Vector3(0.0f, rotation, 0.0f);
}
}

View File

@ -1,34 +0,0 @@
using SHADE;
public class TestScript : Script
{
public double Speed = 1.0;
public Vector3 ATestVector;
public bool ABoolean;
private Transform Transform;
private double time = 0.0;
public TestScript(GameObject gameObj) : base(gameObj) {}
protected override void awake()
{
Debug.Log("TestScript.Awake()");
Transform = GetComponent<Transform>();
if (Transform == null)
{
Debug.LogError("Transform is NULL!");
}
}
protected override void start()
{
Debug.Log("TestScript.Start()");
}
protected override void update()
{
time += Speed * 0.16;
Transform.GlobalPosition = new Vector3(System.Math.Sin(time), System.Math.Cos(time), 0.0f);
}
protected override void onDestroy()
{
Debug.Log("TestScript.OnDestroy()");
}
}