gamecreator Posted July 19, 2017 Share Posted July 19, 2017 Could anyone let me know what's wrong with my code? for(int i=0; i<model->GetSurface(0)->CountVertices(); i++) { Vec3 pos=model->GetSurface(0)->GetVertexPosition(i); pos.x=pos.x*Math::Cos(angle)-pos.y*Math::Sin(angle); pos.y=pos.y*Math::Cos(angle)+pos.x*Math::Sin(angle); model->GetSurface(0)->SetVertexPosition(i, pos); } It rotates the model but the more you do it, the smaller the model gets. I suspect there's a better way to do this and I'm open to suggestions (but I need to do it at the vertex level). Quote Link to comment Share on other sites More sharing options...
macklebee Posted July 19, 2017 Share Posted July 19, 2017 why does it have to be at the vertex level? Just rotating the model rotates the vertices so to the observer its the same thing. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
gamecreator Posted July 19, 2017 Author Share Posted July 19, 2017 6 hours ago, macklebee said: Just rotating the model rotates the vertices Yes and no. Visually, yes. In actuality, no. If you rotate a model and get a vertex position via model->GetSurface(0)->GetVertexPosition(0) for example, it will return the same vertex position after each turn. I'm playing around with making a road snap to terrain and I want to be able to rotate the road and snap the moved vertices to the proper terrain height. Quote Link to comment Share on other sites More sharing options...
gamecreator Posted July 19, 2017 Author Share Posted July 19, 2017 That's very nice of you to say but it's a pretty simple tool. I'm planning on releasing it for free with source. There won't be a GUI so you'll need to provide the map file location and the road file location in a text file that the program reads. 1 Quote Link to comment Share on other sites More sharing options...
gamecreator Posted July 19, 2017 Author Share Posted July 19, 2017 Right now it takes any model you have (doesn't even have to be a road), snaps all of its vertexes to the terrain height below them and exports an OBJ. Unfortunately I don't know anything about textured surfaces and UV coordinates and whatnot so the OBJ will be untextured so you need to retexture it in your modeling program. If someone wants to add that functionality later, they're welcome to do it. I kind of just brute-force the OBJ export. It works fine at the moment but I would have loved to have people be able to rotate the road. Quote Link to comment Share on other sites More sharing options...
macklebee Posted July 19, 2017 Share Posted July 19, 2017 5 hours ago, gamecreator said: Yes and no. Visually, yes. In actuality, no. If you rotate a model and get a vertex position via model->GetSurface(0)->GetVertexPosition(0) for example, it will return the same vertex position after each turn. Actually, yes and yes. It is actually changing the position of the vertices if you just rotate the model. The problem is that GetVertexPosition() returns the local position of the vertex. You need to transform that to a global position. window = Window:Create("Global/Local/Screen Example",0,0,800,600,Window.Center) context = Context:Create(window) world = World:Create() camera = Camera:Create() camera:Move(0,2,6) light = DirectionalLight:Create() light:SetRotation(35,35,0) model = Model:Box() model:SetColor(0.0,0.0,1.0) model:SetPosition(0,2,9) model:SetRotation(45,45,0) surface = model:GetSurface(0) marker = Model:Box() marker:SetScale(.05,.05,.05) marker:SetColor(1,0,0,1) while window:KeyDown(Key.Escape)==false do if window:Closed() then break end model:Turn(0,-0.2,0.5) localpos = surface:GetVertexPosition(0) globalpos = Transform:Point(localpos,model,nil) screenpos = camera:Project(globalpos) marker:SetPosition(globalpos) Time:Update() world:Update() world:Render() context:SetBlendMode(Blend.Alpha) context:DrawText("Local Vertex Position: "..localpos:ToString(),2,2) context:DrawText("Global Vertex Position: "..globalpos:ToString(),2,22) context:DrawText("Vert0",screenpos.x,screenpos.y) context:SetBlendMode(Blend.Solid) context:Sync(true) end 1 Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
gamecreator Posted July 20, 2017 Author Share Posted July 20, 2017 Thank you again macklebee. It looks like it works now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.