Page MenuHomePhorge

Cursor.cpp
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

Cursor.cpp

#include <echo/GUI/Element.h>
#include <echo/GUI/Cursor.h>
#include <echo/Graphics/Renderer.h>
#include <echo/Maths/Ray.h>
namespace Echo
{
namespace GUI
{
Cursor::Cursor(shared_ptr< Input<bool> > button,
shared_ptr< Input<f32> > xInput,
shared_ptr< Input<f32> > yInput,
shared_ptr<Element> rootElement,
shared_ptr<Renderer> renderer,
shared_ptr<Element> cursorElement) :
mButton(button),
mX(xInput),
mY(yInput),
mRootElement(rootElement),
mCursorElement(cursorElement),
mRenderer(renderer)
{
}
bool Cursor::OnStart()
{
//Prevent starting this task if we have any null required parameters.
return (mRenderer && mRootElement && mButton && mX && mY);
}
void Cursor::Update(Seconds)
{
Ray rayIntoScene;
if(mRenderer->GetRayIntoScene(*mX,*mY,rayIntoScene))
{
Plane plane(Vector3::UNIT_Z,0.f);
std::pair<bool, f32> intersectResult = rayIntoScene.Intersects(plane);
if(intersectResult.first)
{
Vector3 positionInSpace = rayIntoScene.GetPoint(intersectResult.second);
if(mCursorElement)
{
positionInSpace.z=mCursorElement->GetPosition().z;
mCursorElement->SetPosition(positionInSpace);
}
mRootElement->UpdateCursor(positionInSpace.x,positionInSpace.y,*mButton);
}
}
}
}
}

File Metadata

Mime Type
text/x-c++
Expires
Wed, Jan 15, 11:33 PM (12 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
72091
Default Alt Text
Cursor.cpp (1 KB)

Event Timeline