本文整理汇总了C++中tgt::ivec2方法的典型用法代码示例。如果您正苦于以下问题:C++ tgt::ivec2方法的具体用法?C++ tgt::ivec2怎么用?C++ tgt::ivec2使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tgt
的用法示例。
在下文中一共展示了tgt::ivec2方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: transformMouseCoordinates
tgt::MouseEvent* ScalingProcessor::transformMouseCoordinates(tgt::MouseEvent* e, int scalingMode, RenderPort* inport, RenderPort* outport ) const {
float aspectRatioIn = (float)inport->getSize().x / (float)inport->getSize().y;
float aspectRatioOut = (float)outport->getSize().x / (float)outport->getSize().y;
vec2 scalingFactor(1.f);
switch(scalingMode) {
case 0:
break;
case 1:
//map pixels 1:1
scalingFactor = vec2((float)inport->getSize().x / (float)outport->getSize().x, (float)inport->getSize().y / (float)outport->getSize().y);
break;
case 2:
//scale respecting aspect ratio and view all of the inport:
if (aspectRatioOut < aspectRatioIn) {
scalingFactor = vec2(1.0f, aspectRatioOut/aspectRatioIn);
}
else {
scalingFactor = vec2(aspectRatioIn/aspectRatioOut, 1.0f);
}
break;
case 3:
//scale respecting aspect ratio and fill outport:
if (aspectRatioOut < aspectRatioIn) {
scalingFactor = vec2(aspectRatioIn/aspectRatioOut, 1.0f);
}
else {
scalingFactor = vec2(1.0f, aspectRatioOut/aspectRatioIn);
}
break;
case 4:
//scale to height:
scalingFactor = vec2(aspectRatioIn/aspectRatioOut, 1.0f);
break;
case 5:
//scale to width:
scalingFactor = vec2(1.0f, aspectRatioIn*aspectRatioOut);
break;
default:
break;
}
// compute transformation
vec2 pixelOffset = ((1.f - scalingFactor) * vec2(outport->getSize())) / 2.f;
vec2 pixelScale = (vec2(outport->getSize())*scalingFactor) / vec2(inport_.getSize());
vec2 trafoCoords = (vec2(e->coord()) - pixelOffset)/pixelScale;
// clone event and assign transformed coords
tgt::MouseEvent* trafoEvent = new tgt::MouseEvent(*e);
trafoEvent->setCoord(ivec2(trafoCoords));
trafoEvent->setViewport(inport->getSize());
return trafoEvent;
}
示例2: createType
Serializable* KeyValueFactory::createType(const std::string& typeString) {
using tgt::ivec2;
using tgt::ivec3;
using tgt::ivec4;
using tgt::vec2;
using tgt::vec3;
using tgt::vec4;
using tgt::mat2;
using tgt::mat3;
using tgt::mat4;
if (typeString == "KeyValue_float")
return new PropertyKeyValue<float>(0, 0);
else if (typeString == "KeyValue_int")
return new PropertyKeyValue<int>(0, 0);
else if (typeString == "KeyValue_bool")
return new PropertyKeyValue<bool>(0, 0);
else if (typeString == "KeyValue_ivec2")
return new PropertyKeyValue<ivec2>(ivec2(0), 0);
else if (typeString == "KeyValue_ivec3")
return new PropertyKeyValue<ivec3>(ivec3(0), 0);
else if (typeString == "KeyValue_ivec4")
return new PropertyKeyValue<ivec4>(ivec4(0), 0);
else if (typeString == "KeyValue_vec2")
return new PropertyKeyValue<vec2>(vec2(0.0f), 0);
else if (typeString == "KeyValue_vec3")
return new PropertyKeyValue<vec3>(vec3(0.0f), 0);
else if (typeString == "KeyValue_vec4")
return new PropertyKeyValue<vec4>(vec4(0.0f), 0);
else if (typeString == "KeyValue_mat2")
return new PropertyKeyValue<mat2>(mat2(0.0f), 0);
else if (typeString == "KeyValue_mat3")
return new PropertyKeyValue<mat3>(mat3(0.0f), 0);
else if (typeString == "KeyValue_mat4")
return new PropertyKeyValue<mat4>(mat4(0.0f), 0);
else if (typeString == "KeyValue_Camera")
return new PropertyKeyValue<tgt::Camera>(tgt::Camera(vec3(0.0f), vec3(0.0f), vec3(0.0f)), 0);
else if (typeString == "KeyValue_string")
return new PropertyKeyValue<std::string>("", 0);
else if (typeString == "KeyValue_ShaderSource")
return new PropertyKeyValue<ShaderSource>(ShaderSource(), 0);
else if (typeString == "KeyValue_TransFunc")
return new PropertyKeyValue<TransFunc*>(new TransFunc(), 0);
else if (typeString == "KeyValue_VolumeCollection")
return new PropertyKeyValue<VolumeCollection*>(new VolumeCollection(), 0);
else if (typeString == "KeyValue_VolumeHandle")
return new PropertyKeyValue<VolumeHandle*>(new VolumeHandle(), 0);
else
return 0;
}
示例3: mouseMoveEvent
void TrackballNavigation::mouseMoveEvent(tgt::MouseEvent* e) {
e->ignore();
if (!trackball_ || !tracking_)
return;
if (trackballEnabled_) {
vec2 newMouse = scaleMouse( ivec2(e->x(), e->y()), e->viewport() );
if (mode_ == ROTATE_MODE) {
trackball_->rotate(newMouse, lastMousePosition_);
e->accept();
}
if (mode_ == SHIFT_MODE) {
trackball_->move(newMouse, lastMousePosition_);
e->accept();
}
if (mode_ == ZOOM_MODE) {
trackball_->zoom(newMouse, lastMousePosition_, mouseZoomInDirection_);
e->accept();
}
if (mode_ == ROLL_MODE) {
rollCameraHorz((newMouse.x-lastMousePosition_.x) / mouseRollAcuteness_);
e->accept();
}
lastMousePosition_ = newMouse;
// restrict distance within specified range
if (trackball_->getCenterDistance() < minDistance_)
trackball_->zoomAbsolute(minDistance_);
if (trackball_->getCenterDistance() > maxDistance_)
trackball_->zoomAbsolute(maxDistance_);
}
}
示例4: onEvent
void TripleView::onEvent(tgt::Event* e) {
tgt::MouseEvent* me = dynamic_cast<tgt::MouseEvent*>(e);
if (!me || mouseMoveEventProp_.accepts(me)) {
RenderProcessor::onEvent(e);
return;
}
switch(configuration_.getValue()) {
case abc:
if (me->x() < (me->viewport().x * 0.33333f)) {
tgt::MouseEvent newme(me->x(), me->y(), me->action(), me->modifiers(), me->button(), ivec2(me->viewport().x / 3, me->viewport().y));
newme.ignore(); // accepted is set to true by default
inport1_.distributeEvent(&newme);
if (newme.isAccepted())
me->accept();
}
else if (me->x() < (me->viewport().x * 0.66666f)) {
tgt::MouseEvent newme(me->x() - (me->viewport().x / 3), me->y(), me->action(), me->modifiers(), me->button(), ivec2(me->viewport().x / 3, me->viewport().y));
newme.ignore();
inport2_.distributeEvent(&newme);
if (newme.isAccepted())
me->accept();
}
else {
tgt::MouseEvent newme(me->x() - (me->viewport().x * 2 / 3), me->y(), me->action(), me->modifiers(), me->button(), ivec2(me->viewport().x / 3, me->viewport().y));
newme.ignore();
inport3_.distributeEvent(&newme);
if (newme.isAccepted())
me->accept();
}
break;
case Abc: distributeEventLargeSmallSmall(inport1_, inport2_, inport3_, me);
break;
case Bac: distributeEventLargeSmallSmall(inport2_, inport1_, inport3_, me);
break;
case Cab: distributeEventLargeSmallSmall(inport3_, inport1_, inport2_, me);
break;
case A: inport1_.distributeEvent(me);
break;
case B: inport2_.distributeEvent(me);
break;
case C: inport3_.distributeEvent(me);
break;
default:;
}
}
示例5: distributeEventLargeSmallSmall
void TripleView::distributeEventLargeSmallSmall(RenderPort& large, RenderPort& small1, RenderPort& small2, tgt::MouseEvent* me) {
if (me->x() < (me->viewport().x * 0.666666f)) {
tgt::MouseEvent newme(me->x(), me->y(), me->action(), me->modifiers(), me->button(), ivec2(static_cast<int>(me->viewport().x * 0.666666f), me->viewport().y));
newme.ignore(); // accepted is set to true by default
large.distributeEvent(&newme);
if (newme.isAccepted())
me->accept();
}
else if (me->y() < (me->viewport().y * 0.5)) {
tgt::MouseEvent newme(me->x() - static_cast<int>(me->viewport().x * 0.666666f), me->y(), me->action(), me->modifiers(), me->button(), ivec2(me->viewport().x / 3, me->viewport().y / 2));
newme.ignore();
small1.distributeEvent(&newme);
if (newme.isAccepted())
me->accept();
}
else {
tgt::MouseEvent newme(me->x() - static_cast<int>(me->viewport().x * 0.666666f), me->y() - static_cast<int>(me->viewport().y * 0.5f), me->action(), me->modifiers(), me->button(), ivec2(me->viewport().x / 3, me->viewport().y / 2));
newme.ignore();
small2.distributeEvent(&newme);
if (newme.isAccepted())
me->accept();
}
}
示例6: updateSizes
void TripleView::updateSizes() {
if (outport_.getReceivedSize() == tgt::ivec2(0))
return;
else {
tgt::ivec2 outsize = outport_.getReceivedSize();
switch(configuration_.getValue()) {
case abc: inport1_.requestSize(ivec2(static_cast<int>(outsize.x * 0.333333f), outsize.y));
inport2_.requestSize(ivec2(static_cast<int>(outsize.x * 0.333333f), outsize.y));
inport3_.requestSize(ivec2(static_cast<int>(outsize.x * 0.333333f), outsize.y));
break;
case Abc: inport1_.requestSize(ivec2(static_cast<int>(outsize.x * 0.666666f), outsize.y));
inport2_.requestSize(ivec2(static_cast<int>(outsize.x * 0.333333f), outsize.y / 2));
inport3_.requestSize(ivec2(static_cast<int>(outsize.x * 0.333333f), outsize.y / 2));
break;
case Bac: inport2_.requestSize(ivec2(static_cast<int>(outsize.x * 0.666666f), outsize.y));
inport1_.requestSize(ivec2(static_cast<int>(outsize.x * 0.333333f), outsize.y / 2));
inport3_.requestSize(ivec2(static_cast<int>(outsize.x * 0.333333f), outsize.y / 2));
break;
case Cab: inport3_.requestSize(ivec2(static_cast<int>(outsize.x * 0.666666f), outsize.y));
inport1_.requestSize(ivec2(static_cast<int>(outsize.x * 0.333333f), outsize.y / 2));
inport2_.requestSize(ivec2(static_cast<int>(outsize.x * 0.333333f), outsize.y / 2));
break;
case A: inport1_.requestSize(outport_.getReceivedSize());
break;
case B: inport2_.requestSize(outport_.getReceivedSize());
break;
case C: inport3_.requestSize(outport_.getReceivedSize());
break;
default:;
}
}
}
示例7: startMouseDrag
void TrackballNavigation::startMouseDrag(tgt::MouseEvent* e) {
lastMousePosition_ = scaleMouse(ivec2(e->x(), e->y()), e->viewport());
tracking_ = true;
}
示例8: onEvent
void InteractiveRegistrationWidget::onEvent(tgt::Event* e) {
e->ignore();
if(render_.get()) {
tgt::MouseEvent* me = dynamic_cast<tgt::MouseEvent*>(e);
if(me) {
if (me->action() & tgt::MouseEvent::PRESSED) {
vec4 c = pickingPort_.getRenderTarget()->getColorAtPos(ivec2(me->x(), me->viewport().y - me->y()));
if(c.a > 0.5f) {
if(c.r > 0.5f) {
mouseDown_ = 0;
e->accept();
}
else if(c.g > 0.5f) {
mouseDown_ = 2;
e->accept();
rotAngle_ = 0.0f;
}
else if(c.b > 0.5f) {
mouseDown_ = 1;
e->accept();
}
textPort_.setData("");
tgt::line3 l = camera_.get().getViewRay(me->viewport(), me->coord());
tgt::plane p(normalize(plane_.get()), planeDist_.get());
float t;
if(p.intersect(l, t)) {
// Calculate intersection points:
startDragCoord_ = l.getFromParam(t);
curDragCoord_ = startDragCoord_;
}
}
}
else if (me->action() & tgt::MouseEvent::MOTION) {
if(mouseDown_ >= 0) {
tgt::line3 l = camera_.get().getViewRay(me->viewport(), me->coord());
tgt::line3 prevL = camera_.get().getViewRay(me->viewport(), lastCoord_);
tgt::plane p(normalize(plane_.get()), planeDist_.get());
float t, prevT;
if(p.intersect(l, t) && p.intersect(prevL, prevT)) {
// Calculate intersection points:
tgt::vec3 i = l.getFromParam(t);
tgt::vec3 prevI = prevL.getFromParam(prevT);
curDragCoord_ = i;
if(mouseDown_ == 0) {
point_.set(point_.get() + i - prevI);
}
else if(mouseDown_ == 1) {
translate(i - prevI);
point_.set(point_.get() + i - prevI);
}
else if(mouseDown_ == 2) {
vec3 a = normalize(i - point_.get());
vec3 b = normalize(prevI - point_.get());
float angle = acos(dot(a, b));
// Check in which direction we need to rotate:
vec3 test = cross(a, b);
vec3 toCam = camera_.get().getPosition() - point_.get();
if(dot(test, toCam) < 0.0f)
angle *= -1.0f;
rotAngle_ += angle;
rotate(point_.get(), plane_.get(), angle);
std::stringstream ss;
ss << (rotAngle_ / (2.0f * tgt::PIf)) * 360.0f << "°";
textPort_.setData(ss.str());
}
}
e->accept();
}
}
else if (me->action() & tgt::MouseEvent::RELEASED) {
if(mouseDown_ >= 0) {
mouseDown_ = -1;
e->accept();
}
}
lastCoord_ = me->coord();
}
}
if(!e->accepted_)
RenderProcessor::onEvent(e);
}