///////////////////////////////////////////////////// ///////////////////////////////////////////////////// // // GetProportionalScreenPos // ///////////////////////////////////////////////////// ///////////////////////////////////////////////////// #include "CKAll.h" CKObjectDeclaration *FillBehaviorGetProportionalScreenPosDecl(); CKERROR CreateGetProportionalScreenPosProto(CKBehaviorPrototype **); int GetProportionalScreenPos(const CKBehaviorContext& behcontext); CKObjectDeclaration *FillBehaviorGetProportionalScreenPosDecl() { CKObjectDeclaration *od = CreateCKObjectDeclaration("Get Proportional Screen Pos"); od->SetDescription("Converts a given 2d position on the screen to a proportional position."); /* rem: In: triggers the process.
Out: is activated when the process is completed.

Pos X: X position on screen.
Pos Y: Y position on screen.

%Pos X: proportional X position on screen.
%Pos Y: proportional Y position on screen.

eg: if the 3dview size is (400,300), and X=200,Y=150 then %X=50 and %Y=50.
*/ /* warning: - the position is supposed to be given in the 3dview window.
*/ od->SetCategory("Interface/Screen"); od->SetType( CKDLL_BEHAVIORPROTOTYPE); od->SetGuid(CKGUID(0x671e53a2,0x5ba16d62)); od->SetAuthorGuid(VIRTOOLS_GUID); od->SetAuthorName("Virtools"); od->SetVersion(0x00010000); od->SetCreationFunction(CreateGetProportionalScreenPosProto); od->SetCompatibleClassId(CKCID_BEOBJECT); return od; } CKERROR CreateGetProportionalScreenPosProto(CKBehaviorPrototype **pproto) { CKBehaviorPrototype *proto = CreateCKBehaviorPrototype("Get Proportional Screen Pos"); if(!proto) return CKERR_OUTOFMEMORY; proto->DeclareInput("In"); proto->DeclareOutput("Out"); proto->DeclareInParameter("Pos X", CKPGUID_INT); proto->DeclareInParameter("Pos Y", CKPGUID_INT); proto->DeclareOutParameter("%Pos X", CKPGUID_PERCENTAGE); proto->DeclareOutParameter("%Pos Y", CKPGUID_PERCENTAGE); proto->SetFlags(CK_BEHAVIORPROTOTYPE_NORMAL); proto->SetFunction(GetProportionalScreenPos); *pproto = proto; return CK_OK; } int GetProportionalScreenPos(const CKBehaviorContext& behcontext) { CKBehavior* beh = behcontext.Behavior; beh->ActivateInput(0, FALSE); int x, y; beh->GetInputParameterValue(0, &x); beh->GetInputParameterValue(1, &y); CKRenderContext* rc = behcontext.CurrentRenderContext; if(!rc) return CKBR_OK; float percx = (float)x/rc->GetWidth(); float percy = (float)y/rc->GetHeight(); beh->SetOutputParameterValue(0, &percx); beh->SetOutputParameterValue(1, &percy); beh->ActivateOutput(0); return CKBR_OK; }