It looks like you're new here. If you want to get involved, click one of these buttons!
void DrawDirectionLine(orxOBJECT *obj)
{
...
orxVECTOR a, b; // a is a start point; b is the end point of direction line
orxObject_GetPosition(obj, &a);
orxVector_Sub(&b, &data->movable->target, &a);
//orxRender_GetScreenPosition(&a, _viewport, &a);
//orxRender_GetScreenPosition(&b, _viewport, &b);
orxRGBA color;
orxRGBA_Set(1., 1., 1., .5);
a.fZ = b.fZ = -0.6;
orxDisplay_DrawLine(&a, &b, color);
//orxLOG("Draw line");
}
orxSTATUS orxFASTCALL HandleRenderEvent(const orxEVENT *currentEvent)
{
switch(currentEvent->eID)
case orxRENDER_EVENT_START: {
traverseScene(_scene, DrawDirectionLine);
}
return orxSTATUS_SUCCESS;
}
orxSTATUS orxFASTCALL Init()
{
...
status = status == orxSTATUS_SUCCESS && orxEvent_AddHandler(orxEVENT_TYPE_RENDER, HandleRenderEvent);
Comments
However direct draw calls are not as optimized as using objects, if it's for a game feature, I'd recommend using an object instead, scaling it from point A to point B and using whichever texture you want, including "pixel".
All draw calls are in screen space, your code with the GetScreenPosition not commented out looks fine to me, is your DrawDirectionLine function called every frame?
Ah, actually here's the issue, I think: orxRGBA is the traditionnal 8bits/channel internal color representation, ie. with values ranging from 0 to 255, not working with normalized floating point values.
Try with
Draw line worked in Run method of 01_Object tutorial, but it failed in my project.
I traced it down to background color option in INI file:
When I have BackgroundColor set, draw line would not work. Draw line worked the moment I commented out BackgroundColor.
I don't necessary think it is a bug, but sure would like to understand the role of Viewport background color.
Another interesting behavior observation: draw line does not get drawn if there is an object in the same space. I ended up placing code to draw line from current cursor position. I have an area that has no objects, so it is all black. Draw line gets displayed there. The moment I move cursor into area filled with objects like background and game objects line disappears. Is it expected behavior?
As far as my goal. I will use the object to draw line. For some reason I did not think straight and did not figure out how to make a directed line out of object with pixel. I slept on it and it is all clear now
That means if you request a background color for your viewport, it'll happen after your draw calls, same for any object getting rendered, they'll be displayed on top of your draw calls.
The best way for that is to issue your draw calls in an ordered fashion. If you want them on top of the objects rendered by a camera/viewport, listen to the matching orxRENDER_EVENT_VIEWPORT_STOP and issue your calls from there.