Draw on viewport.

Draw on viewport.

Anonymous
Not applicable
1,555 Views
14 Replies
Message 1 of 15

Draw on viewport.

Anonymous
Not applicable

I want to draw some graphics on viewport.

On rotating the co-ordinate system this graphics must not transform.

 

how to do it.

 

 

0 Likes
1,556 Views
14 Replies
Replies (14)
Message 2 of 15

maisoui
Advocate
Advocate

Hi,

 

I'm not sure I understood your wish, but I've a solution to draw a custom entity always in front of camera's eye regardless of the view or the coordinate system. Maybe it will give you some ideas.

 

First:

Adesk::Boolean CustomEntity::subWorldDraw(AcGiWorldDraw * wd) 
{
	assertReadEnabled();
	return Adesk::kFalse; // -> call viewport draw
}

Then:

void CustomEntity::subViewportDraw(AcGiViewportDraw * mode)
{
	assertReadEnabled();

	//independant of the viewport's camera and target locations
	AcGiViewport * pViewport = &mode->viewport();

	AcGeVector3d normal = pViewport->viewDir();
	AcGeVector3d vY;
	pViewport->getCameraUpVector(vY);
	vY.normalize();
	AcGeVector3d vX = vY.crossProduct(normal);
	vX.normalize();

	mode->geometry().circle(m_ptWcs, 50., normal);
}

 

Example above will draw a circle always in front of user. You can try to rotate view cube.

 

Regards,

Jonathan

--
Jonathan
Message 3 of 15

Anonymous
Not applicable

Thanks for the reply.

It was really useful.

 

But still have some issues.

When I pan or zoom, the circle gets translated/pan.

 

Why this is so?

Any solution for this.?

 

Waiting for reply.

0 Likes
Message 4 of 15

maisoui
Advocate
Advocate

I guess you need to calculate the position where you draw the circle in the worlddraw method.

With AcGsView you can retrieve the screen's center point, like this:

AcGsView * pView = NULL;
int vportNum = 0;
if(!getGsViewObj(pView, vportNum))
    return false;

ptCenterWcs = pView->target();

My suggestion is to draw your circle at a position relative to the view's target (= center of screen).

 

Regards,

Jonathan

--
Jonathan
0 Likes
Message 5 of 15

Anonymous
Not applicable

==Got Error==

 

identifier "getGsViewObj" is undefined.

0 Likes
Message 6 of 15

maisoui
Advocate
Advocate

And AcGiViewport::getCameraTarget (according to my first sample)?

--
Jonathan
0 Likes
Message 7 of 15

Anonymous
Not applicable

Sorry.. but it doesn't work.

Same output.

 

It works exactly correct for rotation. But on pan it moves. Same for zoom in and zoom out.

0 Likes
Message 8 of 15

fenton_webb
Autodesk
Autodesk

First of all, try not to use AcGsView inside of your viewportDraw - besides the fact that it depends on acad.exe which will stop your object enabler working inside of other RealDWG hosts it can be very expensive on performance.

 

If you want to draw scale dependent graphics inside of your viewportDraw, you can use AcGiViewport::getNumPixelsInUnitSquare to determine your geometry size

 




Fenton Webb
AutoCAD Engineering
Autodesk

0 Likes
Message 9 of 15

Anonymous
Not applicable

Thanks for the reply Fenton.

 

Can you please help me with the code.

 

Waiting for reply.

0 Likes
Message 10 of 15

Anonymous
Not applicable

Still I cant find the solution.

 

Please help ASAP.

0 Likes
Message 11 of 15

owenwengerd
Advisor
Advisor

You'll be more likely to get assistance if you post your code and explain where it fails.

--
Owen Wengerd
ManuSoft
0 Likes
Message 12 of 15

Anonymous
Not applicable

The code posted above works for rotation.... but fail for pan and zoom..

 

When i rotate, it repaint..... but when i pan/zoom it dont do repaint...

0 Likes
Message 13 of 15

fenton_webb
Autodesk
Autodesk

We have a function called AcGiDrawable::SetAttributes() - you should override that in your Custom entity and then check out the SetAttributesFlags enumeration...I bet if you return kDrawableViewDependentViewportDraw it will start working...

 

enum SetAttributesFlags {
  kDrawableNone = 0,
  kDrawableIsAnEntity = 1,
  kDrawableUsesNesting = 2,
  kDrawableIsCompoundObject = 4,
  kDrawableViewIndependentViewportDraw = 8,
  kDrawableIsInvisible = 16,
  kDrawableHasAttributes = 32,
  kDrawableRegenTypeDependantGeometry = 64,
  kDrawableIsDimension = (kDrawableIsAnEntity + kDrawableIsCompoundObject + 128),
  kDrawableRegenDraw = 256,
  kDrawableStandardDisplaySingleLOD = 512,
  kDrawableShadedDisplaySingleLOD = 1024,
  kDrawableViewDependentViewportDraw = 2048,
  kDrawableBlockDependentViewportDraw = 4096,
  kDrawableIsExternalReference = 8192,
  kDrawableNotPlottable = 16384
};




Fenton Webb
AutoCAD Engineering
Autodesk

0 Likes
Message 14 of 15

fenton_webb
Autodesk
Autodesk
0 Likes
Message 15 of 15

Anonymous
Not applicable

Hi,

I was facing the same issue, returning kDrawableViewDependentViewportDraw fixed it in 3d mode only but in 2dwireframe, subSetAttributes/subWorldDraw/subViewportDraw are not called on my drawable during (or event after) zoom/pan.

Is there any way to work around this?

 

Thanks

 

Loic Jourdan

0 Likes