//-------------------------------------------------------------- void testApp::updateMesh() { imageToSpaceScaling.set(1.0f,linesHeight,1.0f); ofPixelsRef tmpPixels = grayImage.getPixelsRef(); mesh.clear(); mesh.setMode( OF_PRIMITIVE_LINES ); int tmpIndex = 0; for( int y = 0; y < grayImage.getHeight(); y += lineSkip ) { tmpIndex = y * grayImage.getWidth(); for( int x = 0; x < grayImage.getWidth(); x++ ) { ofVec3f tmpVert(x, tmpPixels[tmpIndex]/255.0f, y); tmpVert *= imageToSpaceScaling; mesh.addVertex( tmpVert ); tmpIndex++; } } int tmpY = 0; for( int y = 0; y < grayImage.getHeight(); y += lineSkip ) { tmpIndex = tmpY * grayImage.getWidth(); tmpY++; for( int x = 0; x < grayImage.getWidth()-1; x++ ) { mesh.addIndex( tmpIndex ); mesh.addIndex( tmpIndex + 1 ); tmpIndex++; } } }
bool Manage3DCursor(Entity * io, bool simulate) { arx_assert(io); if(BLOCK_PLAYER_CONTROLS) return false; float ag = player.angle.getYaw(); if(ag > 180) ag = ag - 360; float drop_miny = (float)(g_size.center().y) - g_size.center().y * (ag * (1.f/70)); if(DANAEMouse.y < drop_miny) return false; Anglef temp = Anglef::ZERO; if(io->ioflags & IO_INVERTED) { temp.setYaw(180.f); temp.setPitch(-MAKEANGLE(270.f - io->angle.getPitch() - (player.angle.getPitch() - STARTED_ANGLE))); } else { temp.setPitch(MAKEANGLE(270.f - io->angle.getPitch() - (player.angle.getPitch() - STARTED_ANGLE))); } EERIE_3D_BBOX bbox; for(size_t i = 0; i < io->obj->vertexlist.size(); i++) { bbox.add(io->obj->vertexlist[i].v); } Vec3f mvectx = angleToVectorXZ(player.angle.getPitch() - 90.f); Vec2f mod = Vec2f(Vec2i(DANAEMouse) - g_size.center()) / Vec2f(g_size.center()) * Vec2f(160.f, 220.f); mvectx *= mod.x; Vec3f mvecty(0, mod.y, 0); Vec3f orgn = player.pos; orgn += angleToVector(player.angle) * 50.f; orgn += mvectx; orgn.y += mvecty.y; Vec3f dest = player.pos; dest += angleToVector(player.angle) * 10000.f; dest += mvectx; dest.y += mvecty.y * 5.f; Vec3f pos = orgn; Vec3f movev = glm::normalize(dest - orgn); float lastanything = 0.f; float height = -(bbox.max.y - bbox.min.y); if(height > -30.f) height = -30.f; Vec3f objcenter = bbox.min + (bbox.max - bbox.min) * Vec3f(0.5f); Vec3f collidpos = Vec3f_ZERO; bool collidpos_ok = false; { float maxdist = 0.f; for(size_t i = 0; i < io->obj->vertexlist.size(); i++) { const EERIE_VERTEX & vert = io->obj->vertexlist[i]; float dist = glm::distance(Vec2f(objcenter.x, objcenter.z), Vec2f(vert.v.x, vert.v.z)) - 4.f; maxdist = std::max(maxdist, dist); } if(io->obj->pbox) { Vec2f tmpVert(io->obj->pbox->vert[0].initpos.x, io->obj->pbox->vert[0].initpos.z); for(int i = 1; i < io->obj->pbox->nb_physvert; i++) { const PHYSVERT & physVert = io->obj->pbox->vert[i]; float dist = glm::distance(tmpVert, Vec2f(physVert.initpos.x, physVert.initpos.z)) + 14.f; maxdist = std::max(maxdist, dist); } } Cylinder cyl2; const float inc = 10.f; long iterating = 40; cyl2.height = std::min(-30.f, height); cyl2.radius = glm::clamp(maxdist, 20.f, 150.f); while(iterating > 0) { cyl2.origin = pos + movev * inc + Vec3f(0.f, bbox.max.y, 0.f); float anything = CheckAnythingInCylinder(cyl2, io, CFLAG_JUST_TEST | CFLAG_COLLIDE_NOCOL | CFLAG_NO_NPC_COLLIDE); if(anything < 0.f) { if(iterating == 40) { CANNOT_PUT_IT_HERE = 1; // TODO is this correct ? return true; } iterating = 0; collidpos = cyl2.origin; if(lastanything < 0.f) { pos.y += lastanything; collidpos.y += lastanything; } } else { pos = cyl2.origin; lastanything = anything; } iterating--; } collidpos_ok = iterating == -1; } objcenter = VRotateY(objcenter, temp.getPitch()); collidpos.x -= objcenter.x; collidpos.z -= objcenter.z; pos.x -= objcenter.x; pos.z -= objcenter.z; if(!collidpos_ok) { CANNOT_PUT_IT_HERE = 1; return false; } if(collidpos_ok && closerThan(player.pos, pos, 300.f)) { if(simulate) { ARX_INTERACTIVE_Teleport(io, pos, true); io->gameFlags &= ~GFLAG_NOCOMPUTATION; glm::quat rotation = glm::toQuat(toRotationMatrix(temp)); if(SPECIAL_DRAGINTER_RENDER) { if(glm::abs(lastanything) > glm::abs(height)) { TransformInfo t(collidpos, rotation, io->scale); static const float invisibility = 0.5f; DrawEERIEInter(io->obj, t, io, false, invisibility); } else { TransformInfo t(pos, rotation, io->scale); float invisibility = Cedric_GetInvisibility(io); DrawEERIEInter(io->obj, t, io, false, invisibility); } } } else { if(glm::abs(lastanything) > std::min(glm::abs(height), 12.0f)) { Entity * io = DRAGINTER; ARX_PLAYER_Remove_Invisibility(); io->obj->pbox->active = 1; io->obj->pbox->stopcount = 0; io->pos = collidpos; io->velocity = Vec3f_ZERO; io->stopped = 1; movev.x *= 0.0001f; movev.y = 0.1f; movev.z *= 0.0001f; Vec3f viewvector = movev; Anglef angle = temp; io->soundtime = 0; io->soundcount = 0; EERIE_PHYSICS_BOX_Launch(io->obj, io->pos, angle, viewvector); ARX_SOUND_PlaySFX(SND_WHOOSH, &pos); io->show = SHOW_FLAG_IN_SCENE; Set_DragInter(NULL); } else { ARX_PLAYER_Remove_Invisibility(); ARX_SOUND_PlayInterface(SND_INVSTD); ARX_INTERACTIVE_Teleport(io, pos, true); io->angle.setYaw(temp.getYaw()); io->angle.setPitch(270.f - temp.getPitch()); io->angle.setRoll(temp.getRoll()); io->stopped = 0; io->show = SHOW_FLAG_IN_SCENE; io->obj->pbox->active = 0; Set_DragInter(NULL); } } GRenderer->SetCulling(Renderer::CullNone); return true; } else { CANNOT_PUT_IT_HERE=-1; } return false; }