• R/O
  • SSH
  • HTTPS

vima19: Commit


Commit MetaInfo

Revisión2547 (tree)
Tiempo2023-09-29 05:14:24
Autorhgtterry

Log Message

GameDirector 28-09-23 Picking Face

Cambiar Resumen

Diferencia incremental

--- Anim19_OSDN/CollisionTools.cpp (revision 2546)
+++ Anim19_OSDN/CollisionTools.cpp (revision 2547)
@@ -1,9 +1,11 @@
11 /******************************************************************************************
2-MOC - Minimal Ogre Collision v 1.0 beta
2+MOC - Minimal Ogre Collision v 1.0
33 The MIT License
44
5-Copyright (c) 2008 MouseVolcano (Thomas Gradl, Esa Kylli, Erik Biermann, Karolina Sefyrin)
5+Copyright (c) 2008, 2009 MouseVolcano (Thomas Gradl, Karolina Sefyrin), Esa Kylli
66
7+Thanks to Erik Biermann for the help with the Videos, SEO and Webwork
8+
79 Permission is hereby granted, free of charge, to any person obtaining a copy
810 of this software and associated documentation files (the "Software"), to deal
911 in the Software without restriction, including without limitation the rights
@@ -22,15 +24,38 @@
2224 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2325 THE SOFTWARE.
2426 ******************************************************************************************/
25-#include "StdAfx.h"
27+#include "stdafx.h"
2628 #include "CollisionTools.h"
2729
2830 namespace MOC {
2931
32+#ifdef ETM_TERRAIN
33+CollisionTools::CollisionTools(Ogre::SceneManager *sceneMgr, const ET::TerrainInfo* terrainInfo)
34+{
35+ mRaySceneQuery = sceneMgr->createRayQuery(Ogre::Ray());
36+ if (NULL == mRaySceneQuery)
37+ {
38+ // LOG_ERROR << "Failed to create Ogre::RaySceneQuery instance" << ENDLOG;
39+ return;
40+ }
41+ mRaySceneQuery->setSortByDistance(true);
42+
43+ mTSMRaySceneQuery = NULL;
44+
45+ mTerrainInfo = terrainInfo;
46+
47+ _heightAdjust = 0.0f;
48+
49+ pentity = NULL;
50+ distToColl = 0;
51+ myResult = Ogre::Vector3::ZERO;
52+}
53+#endif
54+
3055 CollisionTools::CollisionTools(Ogre::SceneManager *sceneMgr)
3156 {
3257 mSceneMgr = sceneMgr;
33-
58+
3459 mRaySceneQuery = mSceneMgr->createRayQuery(Ogre::Ray());
3560 if (NULL == mRaySceneQuery)
3661 {
@@ -38,11 +63,11 @@
3863 return;
3964 }
4065 mRaySceneQuery->setSortByDistance(true);
41-
66+
4267 mTSMRaySceneQuery = mSceneMgr->createRayQuery(Ogre::Ray());
43-
44- _heightAdjust = 0.0f;
4568
69+ _heightAdjust = 0.0f;
70+
4671 pentity = NULL;
4772 distToColl = 0;
4873 myResult = Ogre::Vector3::ZERO;
@@ -52,35 +77,40 @@
5277 {
5378 if (mRaySceneQuery != NULL)
5479 delete mRaySceneQuery;
55-
80+
5681 if (mTSMRaySceneQuery != NULL)
5782 delete mTSMRaySceneQuery;
5883 }
5984
60-//bool CollisionTools::raycastFromCamera(RenderWindow* rw, Camera* camera, const OIS::MouseEvent &e, Vector3 &result, ulong &target,float &closest_distance, const uint32 queryMask)
61-//{
62-// // Create the ray to test
63-// Real tx = (Real) e.state.X.abs / (Real) rw->getWidth();
64-// Real ty = (Real) e.state.Y.abs / (Real) rw->getHeight();
65-// Ray ray = camera->getCameraToViewportRay(tx, ty);
66-//
67-// return raycast(ray, result, target, closest_distance, queryMask);
68-//}
85+bool CollisionTools::raycastFromCamera(Ogre::RenderWindow* rw, Ogre::Camera* camera, const Ogre::Vector2 &mousecoords, Ogre::Vector3 &result, Ogre::Entity* &target,float &closest_distance, const Ogre::uint32 queryMask)
86+{
87+ return raycastFromCamera(rw, camera, mousecoords, result, (Ogre::MovableObject*&) target, closest_distance, queryMask);
88+}
6989
70-bool CollisionTools::collidesWithEntity(const Vector3& fromPoint, const Vector3& toPoint, const float collisionRadius, const float rayHeightLevel, const uint32 queryMask)
90+bool CollisionTools::raycastFromCamera(Ogre::RenderWindow* rw, Ogre::Camera* camera, const Ogre::Vector2 &mousecoords, Ogre::Vector3 &result, Ogre::MovableObject* &target,float &closest_distance, const Ogre::uint32 queryMask)
7191 {
72- Vector3 fromPointAdj(fromPoint.x, fromPoint.y + rayHeightLevel, fromPoint.z);
73- Vector3 toPointAdj(toPoint.x, toPoint.y + rayHeightLevel, toPoint.z);
74- Vector3 normal = toPointAdj - fromPointAdj;
92+ // Create the ray to test
93+ Ogre::Real tx = mousecoords.x / (Ogre::Real) rw->getWidth();
94+ Ogre::Real ty = mousecoords.y / (Ogre::Real) rw->getHeight();
95+ Ogre::Ray ray = camera->getCameraToViewportRay(tx, ty);
96+
97+ return raycast(ray, result, target, closest_distance, queryMask);
98+}
99+
100+bool CollisionTools::collidesWithEntity(const Ogre::Vector3& fromPoint, const Ogre::Vector3& toPoint, const float collisionRadius, const float rayHeightLevel, const Ogre::uint32 queryMask)
101+{
102+ Ogre::Vector3 fromPointAdj(fromPoint.x, fromPoint.y + rayHeightLevel, fromPoint.z);
103+ Ogre::Vector3 toPointAdj(toPoint.x, toPoint.y + rayHeightLevel, toPoint.z);
104+ Ogre::Vector3 normal = toPointAdj - fromPointAdj;
75105 float distToDest = normal.normalise();
76106
77- myResult = Ogre::Vector3::ZERO;;
78- Ogre::Entity* myObject = NULL;
107+ Ogre::Vector3 myResult(0, 0, 0);
108+ Ogre::MovableObject* myObject = NULL;
79109 distToColl = 0.0f;
80110
81- if (raycastFromPoint(fromPointAdj, normal, myResult, (ulong&)myObject, distToColl, queryMask))
111+ if (raycastFromPoint(fromPointAdj, normal, myResult, myObject, distToColl, queryMask))
82112 {
83- distToColl -= collisionRadius;
113+ distToColl -= collisionRadius;
84114 return (distToColl <= distToDest);
85115 }
86116 else
@@ -92,37 +122,37 @@
92122 float CollisionTools::getTSMHeightAt(const float x, const float z) {
93123 float y=0.0f;
94124
95- static Ray updateRay;
96-
97- updateRay.setOrigin(Vector3(x,9999,z));
98- updateRay.setDirection(Vector3::NEGATIVE_UNIT_Y);
99-
125+ static Ogre::Ray updateRay;
126+
127+ updateRay.setOrigin(Ogre::Vector3(x,9999,z));
128+ updateRay.setDirection(Ogre::Vector3::NEGATIVE_UNIT_Y);
129+
100130 mTSMRaySceneQuery->setRay(updateRay);
101- RaySceneQueryResult& qryResult = mTSMRaySceneQuery->execute();
102-
103- RaySceneQueryResult::iterator i = qryResult.begin();
131+ Ogre::RaySceneQueryResult& qryResult = mTSMRaySceneQuery->execute();
132+
133+ Ogre::RaySceneQueryResult::iterator i = qryResult.begin();
104134 if (i != qryResult.end() && i->worldFragment)
105135 {
106- y=i->worldFragment->singleIntersection.y;
107- }
136+ y=i->worldFragment->singleIntersection.y;
137+ }
108138 return y;
109139 }
110140
111-void CollisionTools::calculateY(SceneNode *n, const bool doTerrainCheck, const bool doGridCheck, const float gridWidth, const uint32 queryMask)
141+void CollisionTools::calculateY(Ogre::SceneNode *n, const bool doTerrainCheck, const bool doGridCheck, const float gridWidth, const Ogre::uint32 queryMask)
112142 {
113- Vector3 pos = n->getPosition();
114-
143+ Ogre::Vector3 pos = n->getPosition();
144+
115145 float x = pos.x;
116146 float z = pos.z;
117147 float y = pos.y;
118-
119- Vector3 myResult(0,0,0);
120- Ogre::Entity *myObject=NULL;
121- float distToColl = 0.0f;
122148
149+ Ogre::Vector3 myResult(0,0,0);
150+ Ogre::MovableObject *myObject=NULL;
151+ distToColl = 0.0f;
152+
123153 float terrY = 0, colY = 0, colY2 = 0;
124154
125- if( raycastFromPoint(Vector3(x,y,z),Vector3::NEGATIVE_UNIT_Y,myResult,(ulong&)myObject, distToColl, queryMask)){
155+ if( raycastFromPoint(Ogre::Vector3(x,y,z),Ogre::Vector3::NEGATIVE_UNIT_Y,myResult,myObject, distToColl, queryMask)){
126156 if (myObject != NULL) {
127157 colY = myResult.y;
128158 } else {
@@ -129,26 +159,26 @@
129159 colY = -99999;
130160 }
131161 }
132-
162+
133163 //if doGridCheck is on, repeat not to fall through small holes for example when crossing a hangbridge
134- if (doGridCheck) {
135- if( raycastFromPoint(Vector3(x,y,z)+(n->getOrientation()*Vector3(0,0,gridWidth)),Vector3::NEGATIVE_UNIT_Y,myResult,(ulong&)myObject, distToColl, queryMask)){
164+ if (doGridCheck) {
165+ if( raycastFromPoint(Ogre::Vector3(x,y,z)+(n->getOrientation()*Ogre::Vector3(0,0,gridWidth)),Ogre::Vector3::NEGATIVE_UNIT_Y,myResult, myObject, distToColl, queryMask)){
136166 if (myObject != NULL) {
137167 colY = myResult.y;
138168 } else {
139169 colY = -99999;
140- }
170+ }
141171 }
142172 if (colY<colY2) colY = colY2;
143173 }
144-
174+
145175 // set the parameter to false if you are not using ETM or TSM
146176 if (doTerrainCheck) {
147-
177+
148178 #ifdef ETM_TERRAIN
149179 // ETM height value
150180 terrY = mTerrainInfo->getHeightAt(x,z);
151-#else
181+#else
152182 // TSM height value
153183 terrY = getTSMHeightAt(x,z);
154184 #endif
@@ -167,11 +197,21 @@
167197 // raycast from a point in to the scene.
168198 // returns success or failure.
169199 // on success the point is returned in the result.
170-bool CollisionTools::raycastFromPoint(const Vector3 &point,
171- const Vector3 &normal,
172- Vector3 &result,ulong &target,float &closest_distance,
173- const uint32 queryMask)
200+bool CollisionTools::raycastFromPoint(const Ogre::Vector3 &point,
201+ const Ogre::Vector3 &normal,
202+ Ogre::Vector3 &result,Ogre::Entity* &target,
203+ float &closest_distance,
204+ const Ogre::uint32 queryMask)
174205 {
206+ return raycastFromPoint(point, normal, result,(Ogre::MovableObject*&) target, closest_distance, queryMask);
207+}
208+
209+bool CollisionTools::raycastFromPoint(const Ogre::Vector3 &point,
210+ const Ogre::Vector3 &normal,
211+ Ogre::Vector3 &result,Ogre::MovableObject* &target,
212+ float &closest_distance,
213+ const Ogre::uint32 queryMask)
214+{
175215 // create the ray to test
176216 static Ogre::Ray ray;
177217 ray.setOrigin(point);
@@ -180,8 +220,13 @@
180220 return raycast(ray, result, target, closest_distance, queryMask);
181221 }
182222
183-bool CollisionTools::raycast(const Ray &ray, Vector3 &result,ulong &target,float &closest_distance, const uint32 queryMask)
223+bool CollisionTools::raycast(const Ogre::Ray &ray, Ogre::Vector3 &result,Ogre::Entity* &target,float &closest_distance, const Ogre::uint32 queryMask)
184224 {
225+ return raycast(ray, result, (Ogre::MovableObject*&)target, closest_distance, queryMask);
226+}
227+
228+bool CollisionTools::raycast(const Ogre::Ray &ray, Ogre::Vector3 &result,Ogre::MovableObject* &target,float &closest_distance, const Ogre::uint32 queryMask)
229+{
185230 target = NULL;
186231
187232 // check we are initialised
@@ -202,7 +247,7 @@
202247 {
203248 //LOG_ERROR << "Cannot raycast without RaySceneQuery instance" << ENDLOG;
204249 return (false);
205- }
250+ }
206251
207252 // at this point we have raycast to a series of different objects bounding boxes.
208253 // we need to test these different objects to see which is the first polygon hit.
@@ -209,7 +254,7 @@
209254 // there are some minor optimizations (distance based) that mean we wont have to
210255 // check all of the objects most of the time, but the worst case scenario is that
211256 // we need to test every triangle of every object.
212- //Ogre::Real closest_distance = -1.0f;
257+ //Ogre::Ogre::Real closest_distance = -1.0f;
213258 closest_distance = -1.0f;
214259 Ogre::Vector3 closest_result;
215260 Ogre::RaySceneQueryResult &query_result = mRaySceneQuery->getLastResults();
@@ -225,26 +270,26 @@
225270
226271 // only check this result if its a hit against an entity
227272 if ((query_result[qr_idx].movable != NULL) &&
228- (query_result[qr_idx].movable->getMovableType().compare("Entity") == 0))
273+ (query_result[qr_idx].movable->getMovableType().compare("Entity") == 0))
229274 {
230275 // get the entity to check
231- pentity = static_cast<Ogre::Entity*>(query_result[qr_idx].movable);
232-
233- // mesh data to retrieve
276+ pentity = static_cast<Ogre::MovableObject*>(query_result[qr_idx].movable);
277+
278+ // mesh data to retrieve
234279 size_t vertex_count;
235280 size_t index_count;
236281 Ogre::Vector3 *vertices;
237- unsigned long *indices;
282+ Ogre::uint32 *indices;
238283
239284 // get the mesh information
240- GetMeshInformation(pentity->getMesh(), vertex_count, vertices, index_count, indices,
241- pentity->getParentNode()->getPosition(),
242- pentity->getParentNode()->getOrientation(),
243- pentity->getParentNode()->getScale());
285+ GetMeshInformation(((Ogre::Entity*)pentity)->getMesh(), vertex_count, vertices, index_count, indices,
286+ pentity->getParentNode()->_getDerivedPosition(),
287+ pentity->getParentNode()->_getDerivedOrientation(),
288+ pentity->getParentNode()->_getDerivedScale());
244289
245290 // test for hitting individual triangles on the mesh
246291 bool new_closest_found = false;
247- for (int i = 0; i < static_cast<int>(index_count); i += 3)
292+ for (size_t i = 0; i < index_count; i += 3)
248293 {
249294 // check for a hit against this triangle
250295 std::pair<bool, Ogre::Real> hit = Ogre::Math::intersects(ray, vertices[indices[i]],
@@ -271,10 +316,10 @@
271316 // closest_result before moving on to the next object.
272317 if (new_closest_found)
273318 {
274- target = (ulong)pentity;
275- closest_result = ray.getPoint(closest_distance);
319+ target = pentity;
320+ closest_result = ray.getPoint(closest_distance);
276321 }
277- }
322+ }
278323 }
279324
280325 // return the result
@@ -282,7 +327,6 @@
282327 {
283328 // raycast success
284329 result = closest_result;
285- Point = closest_result;
286330 return (true);
287331 }
288332 else
@@ -289,7 +333,7 @@
289333 {
290334 // raycast failed
291335 return (false);
292- }
336+ }
293337 }
294338
295339
@@ -299,7 +343,7 @@
299343 size_t &vertex_count,
300344 Ogre::Vector3* &vertices,
301345 size_t &index_count,
302- unsigned long* &indices,
346+ Ogre::uint32* &indices,
303347 const Ogre::Vector3 &position,
304348 const Ogre::Quaternion &orient,
305349 const Ogre::Vector3 &scale)
@@ -338,7 +382,7 @@
338382
339383 // Allocate space for the vertices and indices
340384 vertices = new Ogre::Vector3[vertex_count];
341- indices = new unsigned long[index_count];
385+ indices = new Ogre::uint32[index_count];
342386
343387 added_shared = false;
344388
@@ -366,10 +410,10 @@
366410 unsigned char* vertex =
367411 static_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
368412
369- // There is _no_ baseVertexPointerToElement() which takes an Ogre::Real or a double
370- // as second argument. So make it float, to avoid trouble when Ogre::Real will
413+ // There is _no_ baseVertexPointerToElement() which takes an Ogre::Ogre::Real or a double
414+ // as second argument. So make it float, to avoid trouble when Ogre::Ogre::Real will
371415 // be comiled/typedefed as double:
372- // Ogre::Real* pReal;
416+ // Ogre::Ogre::Real* pOgre::Real;
373417 float* pReal;
374418
375419 for( size_t j = 0; j < vertex_data->vertexCount; ++j, vertex += vbuf->getVertexSize())
@@ -392,7 +436,7 @@
392436
393437 bool use32bitindexes = (ibuf->getType() == Ogre::HardwareIndexBuffer::IT_32BIT);
394438
395- unsigned long* pLong = static_cast<unsigned long*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
439+ Ogre::uint32* pLong = static_cast<Ogre::uint32*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
396440 unsigned short* pShort = reinterpret_cast<unsigned short*>(pLong);
397441
398442
@@ -402,7 +446,7 @@
402446 {
403447 for ( size_t k = 0; k < numTris*3; ++k)
404448 {
405- indices[index_offset++] = pLong[k] + static_cast<unsigned long>(offset);
449+ indices[index_offset++] = pLong[k] + static_cast<Ogre::uint32>(offset);
406450 }
407451 }
408452 else
@@ -409,8 +453,8 @@
409453 {
410454 for ( size_t k = 0; k < numTris*3; ++k)
411455 {
412- indices[index_offset++] = static_cast<unsigned long>(pShort[k]) +
413- static_cast<unsigned long>(offset);
456+ indices[index_offset++] = static_cast<Ogre::uint32>(pShort[k]) +
457+ static_cast<Ogre::uint32>(offset);
414458 }
415459 }
416460
@@ -427,4 +471,4 @@
427471 return _heightAdjust;
428472 }
429473
430-};
474+};
\ No newline at end of file
--- Anim19_OSDN/CollisionTools.h (revision 2546)
+++ Anim19_OSDN/CollisionTools.h (revision 2547)
@@ -1,9 +1,11 @@
11 /******************************************************************************************
2-MOC - Minimal Ogre Collision v 1.0 beta
2+MOC - Minimal Ogre Collision v 1.0
33 The MIT License
44
5-Copyright (c) 2008 MouseVolcano (Thomas Gradl, Esa Kylli, Erik Biermann, Karolina Sefyrin)
5+Copyright (c) 2008, 2009 MouseVolcano (Thomas Gradl, Karolina Sefyrin), Esa Kylli
66
7+Thanks to Erik Biermann for the help with the Videos, SEO and Webwork
8+
79 Permission is hereby granted, free of charge, to any person obtaining a copy
810 of this software and associated documentation files (the "Software"), to deal
911 in the Software without restriction, including without limitation the rights
@@ -22,16 +24,12 @@
2224 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2325 THE SOFTWARE.
2426 ******************************************************************************************/
25-#pragma once
2627 #ifndef COLLISIONTOOLS_H
2728 #define COLLISIONTOOLS_H
2829
29-#pragma warning (disable : 4530)
30-
3130 #include <Ogre.h>
32-//#include <OIS\OISMouse.h>
3331
34-// comment if you dont use ETM as terrainmanager
32+// uncomment if you want to use ETM as terrainmanager
3533 //#define ETM_TERRAIN
3634
3735 #ifdef ETM_TERRAIN
@@ -38,8 +36,6 @@
3836 #include "ETTerrainInfo.h"
3937 #endif
4038
41-using namespace Ogre;
42-
4339 namespace MOC {
4440
4541 class CollisionTools {
@@ -46,33 +42,39 @@
4642 public:
4743 Ogre::RaySceneQuery *mRaySceneQuery;
4844 Ogre::RaySceneQuery *mTSMRaySceneQuery;
49-
50- SceneManager *mSceneMgr;
51- Ogre::Entity *pentity;
45+
46+ Ogre::SceneManager *mSceneMgr;
47+ Ogre::MovableObject *pentity;
5248 float distToColl;
53- Vector3 myResult;
54- Vector3 Point;
55-
56-#ifdef ETM_TERRAIN
49+ Ogre::Vector3 myResult;
50+ Ogre::Vector3 Point;
51+
52+#ifdef ETM_TERRAIN
5753 const ET::TerrainInfo* mTerrainInfo;
5854 CollisionTools(Ogre::SceneManager *sceneMgr, const ET::TerrainInfo* terrainInfo);
5955 #endif
6056
6157 CollisionTools(Ogre::SceneManager *sceneMgr);
62- ~CollisionTools();
58+ ~CollisionTools();
6359
64-// bool raycastFromCamera(RenderWindow* rw, Camera* camera, const OIS::MouseEvent &e, Vector3 &result, ulong &target,float &closest_distance, const uint32 queryMask = 0xFFFFFFFF);
60+ bool raycastFromCamera(Ogre::RenderWindow* rw, Ogre::Camera* camera, const Ogre::Vector2 &mousecoords, Ogre::Vector3 &result, Ogre::MovableObject* &target,float &closest_distance, const Ogre::uint32 queryMask = 0xFFFFFFFF);
61+ // convenience wrapper with Ogre::Entity to it:
62+ bool raycastFromCamera(Ogre::RenderWindow* rw, Ogre::Camera* camera, const Ogre::Vector2 &mousecoords, Ogre::Vector3 &result, Ogre::Entity* &target,float &closest_distance, const Ogre::uint32 queryMask = 0xFFFFFFFF);
6563
66- bool collidesWithEntity(const Vector3& fromPoint, const Vector3& toPoint, const float collisionRadius = 2.5f, const float rayHeightLevel = 0.0f, const uint32 queryMask = 0xFFFFFFFF);
64+ bool collidesWithEntity(const Ogre::Vector3& fromPoint, const Ogre::Vector3& toPoint, const float collisionRadius = 2.5f, const float rayHeightLevel = 0.0f, const Ogre::uint32 queryMask = 0xFFFFFFFF);
6765
68- void calculateY(SceneNode *n, const bool doTerrainCheck = true, const bool doGridCheck = true, const float gridWidth = 1.0f, const uint32 queryMask = 0xFFFFFFFF);
66+ void calculateY(Ogre::SceneNode *n, const bool doTerrainCheck = true, const bool doGridCheck = true, const float gridWidth = 1.0f, const Ogre::uint32 queryMask = 0xFFFFFFFF);
67+
68+ float getTSMHeightAt(const float x, const float z);
6969
70- float getTSMHeightAt(const float x, const float z);
70+ bool raycastFromPoint(const Ogre::Vector3 &point, const Ogre::Vector3 &normal, Ogre::Vector3 &result,Ogre::MovableObject* &target,float &closest_distance, const Ogre::uint32 queryMask = 0xFFFFFFFF);
71+ // convenience wrapper with Ogre::Entity to it:
72+ bool raycastFromPoint(const Ogre::Vector3 &point, const Ogre::Vector3 &normal, Ogre::Vector3 &result,Ogre::Entity* &target,float &closest_distance, const Ogre::uint32 queryMask = 0xFFFFFFFF);
73+
74+ bool raycast(const Ogre::Ray &ray, Ogre::Vector3 &result, Ogre::MovableObject* &target,float &closest_distance, const Ogre::uint32 queryMask = 0xFFFFFFFF);
75+ // convenience wrapper with Ogre::Entity to it:
76+ bool raycast(const Ogre::Ray &ray, Ogre::Vector3 &result, Ogre::Entity* &target,float &closest_distance, const Ogre::uint32 queryMask = 0xFFFFFFFF);
7177
72- bool raycastFromPoint(const Vector3 &point, const Vector3 &normal, Vector3 &result,ulong &target,float &closest_distance, const uint32 queryMask = 0xFFFFFFFF);
73-
74- bool raycast(const Ray &ray, Vector3 &result,ulong &target,float &closest_distance, const uint32 queryMask = 0xFFFFFFFF);
75-
7678 void setHeightAdjust(const float heightadjust);
7779 float getHeightAdjust(void);
7880
@@ -84,7 +86,7 @@
8486 size_t &vertex_count,
8587 Ogre::Vector3* &vertices,
8688 size_t &index_count,
87- unsigned long* &indices,
89+ Ogre::uint32* &indices,
8890 const Ogre::Vector3 &position,
8991 const Ogre::Quaternion &orient,
9092 const Ogre::Vector3 &scale);
--- Anim19_OSDN/DynamicCharacterController.cpp (revision 2546)
+++ Anim19_OSDN/DynamicCharacterController.cpp (revision 2547)
@@ -122,8 +122,6 @@
122122 AddGravity = 0;
123123 }
124124
125-
126-
127125 char buff[255];
128126 strcpy(buff, App->CL_Ogre->OgreListener->Pl_Entity_Name.c_str());
129127
--- Anim19_OSDN/GD19_App.cpp (revision 2546)
+++ Anim19_OSDN/GD19_App.cpp (revision 2547)
@@ -97,7 +97,7 @@
9797 CL_Logger = nullptr;
9898
9999 SBC_DCC = nullptr;
100-
100+ CL_Picking = nullptr;
101101 // ---------------------------------------------------- 29/12/21
102102 Com_CDialogs = nullptr;
103103
@@ -198,7 +198,7 @@
198198 CursorPosX = 500;
199199 CursorPosY = 500;
200200
201- Debug_App = 0;
201+ Debug_App = 1;
202202 V_New_Objects = 1;
203203
204204 EquityDirecory_FullPath[0] = 0;
@@ -589,6 +589,14 @@
589589 }
590590
591591 // *************************************************************************
592+// * Beep_Win:- Terry and Hazel Flanigan 2023 *
593+// *************************************************************************
594+void GD19_App::Beep_Win()
595+{
596+ Beep(440, 100);
597+}
598+
599+// *************************************************************************
592600 // * Custom_Button_Normal Terry Bernie *
593601 // *************************************************************************
594602 bool GD19_App::Custom_Button_Normal(LPNMCUSTOMDRAW item)
--- Anim19_OSDN/GD19_App.h (revision 2546)
+++ Anim19_OSDN/GD19_App.h (revision 2547)
@@ -95,7 +95,7 @@
9595 #include "SB_Logger.h"
9696
9797 #include "DynamicCharacterController.h"
98-
98+#include "SB_Picking.h"
9999 // :- Terry and Hazel Flanigan 2023
100100
101101 class GD19_App
@@ -178,6 +178,7 @@
178178
179179 DynamicCharacterController* SBC_DCC;
180180
181+ SB_Picking* CL_Picking;
181182
182183 Com_Diaolgs* Com_CDialogs; // Common Dialogs for App [291221]
183184 // -----------------------------------
@@ -209,7 +210,8 @@
209210 void Say(const char* Message);
210211 void Say_Int(int Value);
211212 void Say_Win(const char* Message);
212-
213+
214+ void Beep_Win();
213215 void Flash_Window();
214216
215217 void Disable_Panels(bool Disable);
--- Anim19_OSDN/GD19_Grid.cpp (revision 2546)
+++ Anim19_OSDN/GD19_Grid.cpp (revision 2547)
@@ -38,6 +38,9 @@
3838 HairManual = NULL;
3939 HairNode = NULL;
4040
41+ FaceManual = NULL;
42+ FaceNode = NULL;
43+
4144 DummyNode = NULL;
4245
4346 Crosshair_Ent = NULL;
@@ -46,6 +49,8 @@
4649 Selection_Ent = NULL;
4750 Selection_Node = NULL;
4851
52+ FaceColour = ColourValue(1, 0, 0, 1);
53+
4954 ColourHairZ = ColourValue(1, 0, 0, 1);
5055 ColourHairX = ColourValue(0, 0, 1, 1);
5156 ColourHairY = ColourValue(0, 1, 0, 1);
@@ -52,6 +57,10 @@
5257 ColourMain = ColourValue(0.7, 0.7, 0, 0.6);
5358 ColourDivision = ColourValue(1, 1, 1, 0.4);
5459
60+ HitVertices[0] = Ogre::Vector3(0, 0, 0);
61+ HitVertices[1] = Ogre::Vector3(10, 0, 0);
62+ HitVertices[2] = Ogre::Vector3(0, 10, 0);
63+
5564 YAxis_min = -8;
5665 YAxis_max = 8;
5766
@@ -175,6 +184,7 @@
175184 GridNode->setVisible(true);
176185 GridNode->setScale(Scale_X, Scale_Y, Scale_Z);
177186 }
187+
178188 // *************************************************************************
179189 // * Hair_Update:- Terry and Hazel Flanigan 2022 *
180190 // *************************************************************************
@@ -182,7 +192,7 @@
182192 {
183193 if (Create == 1)
184194 {
185- HairManual = App->CL_Ogre->mSceneMgr->createManualObject("HairManual");
195+ HairManual = App->CL_Ogre->mSceneMgr->createManualObject("FaceManual");
186196 HairManual->setRenderQueueGroup(5);
187197 }
188198
@@ -217,6 +227,7 @@
217227 HairNode->setVisible(true);
218228 HairNode->setScale(Scale_X, Scale_Y, Scale_Z);
219229 }
230+
220231 // *************************************************************************
221232 // * Grid_SetVisiable:- Terry and Hazel Flanigan 2022 *
222233 // *************************************************************************
@@ -224,6 +235,7 @@
224235 {
225236 GridNode->setVisible(Option);
226237 }
238+
227239 // *************************************************************************
228240 // * Hair_SetVisiable:- Terry and Hazel Flanigan 2022 *
229241 // *************************************************************************
@@ -233,6 +245,63 @@
233245
234246 }
235247
248+// *************************************************************************
249+// * Face_Update:- Terry and Hazel Flanigan 2022 *
250+// *************************************************************************
251+void SB_Grid::Face_Update(bool Create)
252+{
253+ if (Create == 1)
254+ {
255+ FaceManual = App->CL_Ogre->mSceneMgr->createManualObject("HairManual");
256+ FaceManual->setDynamic(true);
257+ FaceManual->setRenderQueueGroup(RENDER_QUEUE_MAX);
258+ }
236259
260+ FaceManual->clear();
261+ FaceManual->begin("BaseWhiteAlphaBlended", RenderOperation::OT_LINE_STRIP);
262+
263+ // X Axis
264+ FaceManual->position(HitVertices[0]);
265+ FaceManual->colour(FaceColour);
237266
267+ FaceManual->position(HitVertices[1]);
268+ FaceManual->colour(FaceColour);
269+
270+ FaceManual->position(HitVertices[2]);
271+ FaceManual->colour(FaceColour);
238272
273+ FaceManual->position(HitVertices[0]);
274+ FaceManual->colour(FaceColour);
275+
276+ FaceManual->end();
277+
278+ if (Create == 1)
279+ {
280+ FaceNode = App->CL_Ogre->mSceneMgr->getRootSceneNode()->createChildSceneNode();
281+ FaceNode->attachObject(FaceManual);
282+
283+ FaceNode->setPosition(0, 0, 0);
284+ FaceNode->setVisible(false);
285+ //FaceNode->setScale(Scale_X, Scale_Y, Scale_Z);
286+ }
287+}
288+
289+// *************************************************************************
290+// * Face_Update2:- Terry and Hazel Flanigan 2022 *
291+// *************************************************************************
292+void SB_Grid::Face_Update2()
293+{
294+
295+ FaceManual->beginUpdate(0);
296+
297+ FaceManual->position(HitVertices[0]);
298+
299+ FaceManual->position(HitVertices[1]);
300+
301+ FaceManual->position(HitVertices[2]);
302+
303+ FaceManual->position(HitVertices[0]);
304+ FaceManual->end();
305+}
306+
307+
--- Anim19_OSDN/GD19_Grid.h (revision 2546)
+++ Anim19_OSDN/GD19_Grid.h (revision 2547)
@@ -38,6 +38,11 @@
3838 void Grid_SetVisible(bool Option);
3939 void Hair_SetVisible(bool Option);
4040
41+ void Face_Update(bool Create);
42+ void Face_Update2();
43+
44+ Ogre::ColourValue FaceColour;
45+
4146 Ogre::ColourValue ColourMain;
4247 Ogre::ColourValue ColourHairZ;
4348 Ogre::ColourValue ColourHairX;
@@ -66,6 +71,9 @@
6671 ManualObject* HairManual;
6772 SceneNode* HairNode;
6873
74+ ManualObject* FaceManual;
75+ SceneNode* FaceNode;
76+
6977 SceneNode* DummyNode;
7078
7179 Ogre::Entity* Crosshair_Ent;
@@ -74,6 +82,9 @@
7482 Ogre::Entity* Selection_Ent;
7583 Ogre::SceneNode* Selection_Node;
7684
85+ Ogre::Vector3 HitVertices[2];
86+ Ogre::Vector2 HitFaceUVs[2];
87+
7788 bool ShowGridFlag;
7889 bool ShowDivisions;
7990 bool ShowHair;
--- Anim19_OSDN/GD19_OSDN.cpp (revision 2546)
+++ Anim19_OSDN/GD19_OSDN.cpp (revision 2547)
@@ -1213,6 +1213,18 @@
12131213 {
12141214 if (!ImGui::GetIO().WantCaptureMouse)
12151215 {
1216+ POINT p;
1217+ GetCursorPos(&p);
1218+ App->CursorPosX = p.x;
1219+ App->CursorPosY = p.y;
1220+ App->CL_Ogre->OgreListener->Pl_Cent500X = p.x;
1221+ App->CL_Ogre->OgreListener->Pl_Cent500Y = p.y;
1222+
1223+ if (App->CL_Ogre->OgreListener->GD_Selection_Mode == 1)
1224+ {
1225+ App->CL_Picking->Mouse_Pick_Entity();
1226+ }
1227+
12161228 SetCapture(App->ViewGLhWnd);// Bernie
12171229 SetCursorPos(App->CursorPosX, App->CursorPosY);
12181230 App->CL_Ogre->OgreListener->Pl_LeftMouseDown = 1;
--- Anim19_OSDN/GD19_Ogre.cpp (revision 2546)
+++ Anim19_OSDN/GD19_Ogre.cpp (revision 2547)
@@ -78,6 +78,7 @@
7878 // Set Up Grid Functions
7979 App->SBC_Grid->Grid_Update(1);
8080 App->SBC_Grid->Hair_Update(1);
81+ App->SBC_Grid->Face_Update(1);
8182
8283 App->SBC_Grid->DummyNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
8384
@@ -472,3 +473,4 @@
472473 strcat(buff, ".");
473474 strcat(buff, cMinor);
474475 }
476+
--- Anim19_OSDN/GD19_OgreListener.cpp (revision 2546)
+++ Anim19_OSDN/GD19_OgreListener.cpp (revision 2547)
@@ -32,8 +32,8 @@
3232 mCam = App->CL_Ogre->mCamera;
3333 Pl_mDummyCamera = App->CL_Ogre->mSceneMgr->createCamera("PickCamera");
3434 App->SBC_3DT->Pl_mDummyCamera = App->CL_Ogre->mSceneMgr->createCamera("ShootCamera");
35+ TestCamera = App->CL_Ogre->mSceneMgr->createCamera("PickCamera2");
3536
36-
3737 Wheel = 0;
3838 StopOgre = 0;
3939 ShowFPS = 1;
@@ -92,7 +92,7 @@
9292 CameraMode = 1; // Model Mode
9393
9494 ImGui_Render_Tab = Enums::ImGui_Camera;
95-
95+ App->CL_Picking = new SB_Picking(App->CL_Ogre->mSceneMgr);
9696 }
9797
9898 GD19_OgreListener::~GD19_OgreListener(void)
@@ -1114,13 +1114,19 @@
11141114 // *************************************************************************
11151115 bool GD19_OgreListener::SelectEntity_World(void)
11161116 {
1117+ return 1;
1118+ Ogre::Quaternion Q;
1119+
11171120 DistanceToCollision = 0;
11181121
11191122 Ogre::SceneNode *mNode;
11201123 Vector3 oldPos = App->CL_Ogre->mCamera->getPosition();
1124+
1125+ Q = App->CL_Ogre->mCamera->getOrientation();
1126+
11211127 Pl_mDummyCamera->setPosition(oldPos);
11221128
1123- Ogre::Quaternion Q;
1129+
11241130 Q = App->CL_Ogre->mCamera->getOrientation();
11251131
11261132 Pl_mDummyCamera->setOrientation(Q);
--- Anim19_OSDN/GD19_OgreListener.h (revision 2546)
+++ Anim19_OSDN/GD19_OgreListener.h (revision 2547)
@@ -65,6 +65,7 @@
6565
6666 bool SelectEntity_World(void);
6767
68+ Ogre::Camera* TestCamera;
6869 Ogre::Camera* mCam;
6970 Ogre::Camera* Pl_mDummyCamera;
7071 Vector3 Pl_mDummyTranslateVector;
--- Anim19_OSDN/SB_Markers.cpp (revision 2546)
+++ Anim19_OSDN/SB_Markers.cpp (revision 2547)
@@ -219,6 +219,17 @@
219219 {
220220 mPickSight = OverlayManager::getSingleton().getByName("MyOverlays/PicksightOverlay");
221221 mPickSight->hide();
222+
223+ Sight_Entity = App->CL_Ogre->mSceneMgr->createEntity("Arrow23", "Gizmo.mesh", App->CL_Ogre->App_Resource_Group);
224+ Sight_Node = App->CL_Ogre->mSceneMgr->getRootSceneNode()->createChildSceneNode();
225+ Sight_Node->attachObject(Sight_Entity);
226+
227+
228+ //mPickSight->add3D(Sight_Node);
229+
230+ Sight_Node->setPosition(0, 0, 0);
231+ Sight_Node->setVisible(true);
232+ Sight_Node->setScale(7, 7, 7);
222233 }
223234
224235 // **************************************************************************
--- Anim19_OSDN/SB_Markers.h (revision 2546)
+++ Anim19_OSDN/SB_Markers.h (revision 2547)
@@ -77,5 +77,8 @@
7777
7878 Ogre::Entity* BlueRotAxis_Ent;
7979 Ogre::SceneNode* BlueRotAxis_Node;
80+
81+ Ogre::Entity* Sight_Entity;
82+ Ogre::SceneNode* Sight_Node;
8083 };
8184
--- Anim19_OSDN/SB_Picking.cpp (nonexistent)
+++ Anim19_OSDN/SB_Picking.cpp (revision 2547)
@@ -0,0 +1,523 @@
1+/*
2+Copyright (c) 2023 World Editor -- HGT Software W.T.Flanigan H.C.Flanigan
3+
4+This software is provided 'as-is', without any express or implied
5+warranty. In no event will the authors be held liable for any damages
6+arising from the use of this software.
7+
8+Permission is granted to anyone to use this software for any purpose,
9+including commercial applications, and to alter it and redistribute it
10+freely, subject to the following restrictions:
11+
12+1. The origin of this software must not be misrepresented; you must not
13+claim that you wrote the original software. If you use this software
14+in a product, an acknowledgment in the product documentation would be
15+appreciated but is not required.
16+
17+2. Altered source versions must be plainly marked as such, and must not be
18+misrepresented as being the original software.
19+
20+3. This notice may not be removed or altered from any source
21+distribution.
22+*/
23+
24+#include "stdafx.h"
25+#include "GD19_App.h"
26+#include "SB_Picking.h"
27+
28+SB_Picking::SB_Picking(Ogre::SceneManager* sceneMgr)
29+{
30+ mSceneMgr = sceneMgr;
31+
32+ mRaySceneQuery = mSceneMgr->createRayQuery(Ogre::Ray());
33+ if (NULL == mRaySceneQuery)
34+ {
35+ App->Say("No Ray Query");
36+ return;
37+ }
38+ mRaySceneQuery->setSortByDistance(true);
39+
40+ pentity = NULL;
41+
42+ Total_vertex_count = 0;
43+ Total_index_count = 0;
44+ Face_Index = 0;
45+ Sub_Mesh_Count = 0;
46+ SubMesh_Face = 0;
47+}
48+
49+SB_Picking::~SB_Picking()
50+{
51+ if (mRaySceneQuery != NULL)
52+ {
53+ delete mRaySceneQuery;
54+ }
55+}
56+
57+// *************************************************************************
58+// * Mouse_Pick_Entity::Terry and Hazel Flanigan 2023 *
59+// *************************************************************************
60+void SB_Picking::Mouse_Pick_Entity()
61+{
62+ Total_vertex_count = 0;
63+ Total_index_count = 0;
64+ Face_Index = 0;
65+ Sub_Mesh_Count = 0;
66+ SubMesh_Face = 0;
67+
68+ Ogre::RenderWindow* rw = App->CL_Ogre->mWindow;
69+ Ogre::Camera* camera = App->CL_Ogre->mCamera;
70+
71+ ImGuiIO& io = ImGui::GetIO();
72+
73+ Ogre::Real tx = io.MousePos.x / (Ogre::Real)rw->getWidth();
74+ Ogre::Real ty = io.MousePos.y / (Ogre::Real)rw->getHeight();
75+
76+ Ogre::Ray ray = camera->getCameraToViewportRay(tx, ty);
77+
78+ Ogre::uint32 queryMask = -1;
79+ Ogre::Vector3 result = Ogre::Vector3(0,0,0);
80+ Ogre::MovableObject* target = NULL;
81+ closest_distance = 0;
82+
83+ Pl_Entity_Name = " ";
84+ App->CL_Ogre->OgreListener->Selected_Object_Name[0] = 0;
85+
86+ Ogre::SceneNode* mNode;
87+
88+ if (raycast(ray, result, target, closest_distance, queryMask))
89+ {
90+ //App->Beep_Win();
91+
92+ mNode = pentity->getParentSceneNode();
93+ Pl_Entity_Name = pentity->getName();
94+
95+ char buff[255];
96+ strcpy(buff, Pl_Entity_Name.c_str());
97+
98+ App->CL_Vm_ImGui->Show_Object_Selection = 1;
99+
100+ bool test = Ogre::StringUtil::match("Plane0", Pl_Entity_Name, true);
101+ if (test == 1)
102+ {
103+ Pl_Entity_Name = "---------";
104+ }
105+ else
106+ {
107+ bool test = Ogre::StringUtil::match("Player_1", Pl_Entity_Name, true);
108+ if (test == 1)
109+ {
110+ Pl_Entity_Name = "Player_1";
111+
112+ return;
113+ }
114+ else
115+ {
116+ char* pdest;
117+ int IntNum = 0;
118+ char buffer[255];
119+
120+ strcpy(buffer, Pl_Entity_Name.c_str());
121+ pdest = strstr(buffer, "GDEnt_");
122+ if (pdest != NULL)
123+ {
124+ sscanf((buffer + 6), "%i", &IntNum);
125+
126+ App->SBC_Markers->MarkerBB_Addjust(IntNum);
127+
128+ App->CL_Ogre->OgreListener->Selected_Entity_Index = IntNum;
129+ strcpy(App->CL_Ogre->OgreListener->Selected_Object_Name, App->SBC_Scene->V_Object[IntNum]->Mesh_Name);
130+
131+ App->SBC_FileView->SelectItem(App->SBC_Scene->V_Object[App->CL_Ogre->OgreListener->Selected_Entity_Index]->FileViewItem);
132+
133+ return;
134+
135+ }
136+ }
137+
138+ }
139+
140+ }
141+ else
142+ {
143+ Pl_Entity_Name = "---------";
144+ }
145+
146+}
147+
148+// *************************************************************************
149+// * raycast *
150+// *************************************************************************
151+bool SB_Picking::raycast(const Ogre::Ray& ray, Ogre::Vector3& result, Ogre::MovableObject*& target, float& closest_distance, const Ogre::uint32 queryMask)
152+{
153+ target = NULL;
154+
155+ if (mRaySceneQuery != NULL)
156+ {
157+ mRaySceneQuery->setRay(ray);
158+ mRaySceneQuery->setSortByDistance(true);
159+ mRaySceneQuery->setQueryMask(queryMask);
160+ // execute the query, returns a vector of hits
161+ if (mRaySceneQuery->execute().size() <= 0)
162+ {
163+ // raycast did not hit an objects bounding box
164+ return (false);
165+ }
166+ }
167+ else
168+ {
169+
170+ App->Say("No Ray Query");
171+ return (false);
172+ }
173+
174+ // at this point we have raycast to a series of different objects bounding boxes.
175+ // we need to test these different objects to see which is the first polygon hit.
176+ // there are some minor optimizations (distance based) that mean we wont have to
177+ // check all of the objects most of the time, but the worst case scenario is that
178+ // we need to test every triangle of every object.
179+ //Ogre::Ogre::Real closest_distance = -1.0f;
180+ closest_distance = -1.0f;
181+ Ogre::Vector3 closest_result;
182+ Ogre::RaySceneQueryResult& query_result = mRaySceneQuery->getLastResults();
183+ for (size_t qr_idx = 0; qr_idx < query_result.size(); qr_idx++)
184+ {
185+ // stop checking if we have found a raycast hit that is closer
186+ // than all remaining entities
187+ if ((closest_distance >= 0.0f) &&
188+ (closest_distance < query_result[qr_idx].distance))
189+ {
190+ break;
191+ }
192+
193+ // only check this result if its a hit against an entity
194+ if ((query_result[qr_idx].movable != NULL) &&
195+ (query_result[qr_idx].movable->getMovableType().compare("Entity") == 0))
196+ {
197+ // get the entity to check
198+ pentity = static_cast<Ogre::MovableObject*>(query_result[qr_idx].movable);
199+
200+
201+ // get the mesh information
202+ GetMeshInformation(((Ogre::Entity*)pentity)->getMesh(),
203+ pentity->getParentNode()->_getDerivedPosition(),
204+ pentity->getParentNode()->_getDerivedOrientation(),
205+ pentity->getParentNode()->_getDerivedScale());
206+
207+ // test for hitting individual triangles on the mesh
208+ bool new_closest_found = false;
209+ for (size_t i = 0; i < Total_index_count; i += 3)
210+ {
211+ // check for a hit against this triangle
212+ std::pair<bool, Ogre::Real> hit = Ogre::Math::intersects(ray, vertices[indices[i]],
213+ vertices[indices[i + 1]], vertices[indices[i + 2]], true, false);
214+
215+ // if it was a hit check if its the closest
216+ if (hit.first)
217+ {
218+ if ((closest_distance < 0.0f) ||
219+ (hit.second < closest_distance))
220+ {
221+ // this is the closest so far, save it off
222+ closest_distance = hit.second;
223+ new_closest_found = true;
224+
225+ Face_Index = i;
226+
227+ App->SBC_Grid->HitVertices[0] = vertices[indices[i]];
228+ App->SBC_Grid->HitVertices[1] = vertices[indices[i + 1]];
229+ App->SBC_Grid->HitVertices[2] = vertices[indices[i + 2]];
230+
231+ App->SBC_Grid->Face_Update2();
232+
233+ App->SBC_Grid->HitFaceUVs[0] = TextCords[Face_Index];
234+ App->SBC_Grid->HitFaceUVs[1] = TextCords[Face_Index + 1];
235+ App->SBC_Grid->HitFaceUVs[2] = TextCords[Face_Index + 2];
236+
237+ SubMesh_Face = Sub_Mesh_Indexs[Face_Index];
238+
239+ Get_Material_Data();
240+
241+ App->SBC_Grid->FaceNode->setVisible(true);
242+ }
243+ }
244+ }
245+
246+ // free the verticies and indicies memory
247+ delete[] vertices;
248+ delete[] indices;
249+ delete[] TextCords;
250+ delete[] Sub_Mesh_Indexs;
251+
252+ // if we found a new closest raycast for this object, update the
253+ // closest_result before moving on to the next object.
254+ if (new_closest_found)
255+ {
256+ target = pentity;
257+
258+ Sub_Mesh_Count = ((Ogre::Entity*)pentity)->getMesh()->getNumSubMeshes();
259+
260+ closest_result = ray.getPoint(closest_distance);
261+ }
262+ }
263+ }
264+
265+ // return the result
266+ if (closest_distance >= 0.0f)
267+ {
268+ // raycast success
269+ result = closest_result;
270+ return (true);
271+ }
272+ else
273+ {
274+ // raycast failed
275+ return (false);
276+ }
277+}
278+
279+// *************************************************************************
280+// * GetMeshInformation *
281+// *************************************************************************
282+void SB_Picking::GetMeshInformation(const Ogre::MeshPtr mesh, const Ogre::Vector3& position,const Ogre::Quaternion& orient,const Ogre::Vector3& scale)
283+{
284+ bool added_shared = false;
285+ size_t current_offset = 0;
286+ size_t shared_offset = 0;
287+ size_t next_offset = 0;
288+ size_t index_offset = 0;
289+
290+ Total_vertex_count = Total_index_count = 0;
291+
292+ // Calculate how many vertices and indices we're going to need
293+ for (unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i)
294+ {
295+ Ogre::SubMesh* submesh = mesh->getSubMesh(i);
296+
297+ // We only need to add the shared vertices once
298+ if (submesh->useSharedVertices)
299+ {
300+ if (!added_shared)
301+ {
302+ Total_vertex_count += mesh->sharedVertexData->vertexCount;
303+ added_shared = true;
304+ }
305+ }
306+ else
307+ {
308+ Total_vertex_count += submesh->vertexData->vertexCount;
309+ }
310+
311+ // Add the indices
312+ Total_index_count += submesh->indexData->indexCount;
313+ }
314+
315+ // Allocate space for the vertices and indices
316+ vertices = new Ogre::Vector3[Total_vertex_count];
317+ indices = new Ogre::uint32[Total_index_count];
318+ TextCords = new Ogre::Vector2[Total_vertex_count];
319+ Sub_Mesh_Indexs = new Ogre::uint32[Total_index_count];
320+
321+ added_shared = false;
322+
323+ // Run through the submeshes again, adding the data into the arrays
324+ for (unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i)
325+ {
326+ Ogre::SubMesh* submesh = mesh->getSubMesh(i);
327+
328+ Ogre::VertexData* vertex_data = submesh->useSharedVertices ? mesh->sharedVertexData : submesh->vertexData;
329+
330+ if ((!submesh->useSharedVertices) || (submesh->useSharedVertices && !added_shared))
331+ {
332+ if (submesh->useSharedVertices)
333+ {
334+ added_shared = true;
335+ shared_offset = current_offset;
336+ }
337+
338+ const Ogre::VertexElement* posElem =
339+ vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
340+
341+ Ogre::HardwareVertexBufferSharedPtr vbuf =
342+ vertex_data->vertexBufferBinding->getBuffer(posElem->getSource());
343+
344+ unsigned char* vertex =
345+ static_cast<unsigned char*>(vbuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
346+
347+ // There is _no_ baseVertexPointerToElement() which takes an Ogre::Ogre::Real or a double
348+ // as second argument. So make it float, to avoid trouble when Ogre::Ogre::Real will
349+ // be comiled/typedefed as double:
350+ // Ogre::Ogre::Real* pOgre::Real;
351+ float* pReal;
352+
353+ for (size_t j = 0; j < vertex_data->vertexCount; ++j, vertex += vbuf->getVertexSize())
354+ {
355+ posElem->baseVertexPointerToElement(vertex, &pReal);
356+
357+ Ogre::Vector3 pt(pReal[0], pReal[1], pReal[2]);
358+
359+ vertices[current_offset + j] = (orient * (pt * scale)) + position;
360+ }
361+
362+ vbuf->unlock();
363+ next_offset += vertex_data->vertexCount;
364+ }
365+
366+ Ogre::IndexData* index_data = submesh->indexData;
367+ size_t numTris = index_data->indexCount / 3;
368+ Ogre::HardwareIndexBufferSharedPtr ibuf = index_data->indexBuffer;
369+
370+ bool use32bitindexes = (ibuf->getType() == Ogre::HardwareIndexBuffer::IT_32BIT);
371+
372+ Ogre::uint32* pLong = static_cast<Ogre::uint32*>(ibuf->lock(Ogre::HardwareBuffer::HBL_READ_ONLY));
373+ unsigned short* pShort = reinterpret_cast<unsigned short*>(pLong);
374+
375+
376+ size_t offset = (submesh->useSharedVertices) ? shared_offset : current_offset;
377+
378+ if (use32bitindexes)
379+ {
380+ for (size_t k = 0; k < numTris * 3; ++k)
381+ {
382+ indices[index_offset++] = pLong[k] + static_cast<Ogre::uint32>(offset);
383+ }
384+ }
385+ else
386+ {
387+ for (size_t k = 0; k < numTris * 3; ++k)
388+ {
389+ indices[index_offset++] = static_cast<Ogre::uint32>(pShort[k]) +
390+ static_cast<Ogre::uint32>(offset);
391+ }
392+ }
393+
394+ ibuf->unlock();
395+ current_offset = next_offset;
396+ }
397+
398+ // Texture Cords UVS
399+ int textoffsset = 0;
400+
401+ for (unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i)
402+ {
403+ Ogre::SubMesh* submesh = mesh->getSubMesh(i);
404+
405+ Ogre::VertexData* vertex_data = submesh->useSharedVertices ? mesh->sharedVertexData : submesh->vertexData;
406+
407+ if ((!submesh->useSharedVertices) || (submesh->useSharedVertices && !added_shared))
408+ {
409+ if (submesh->useSharedVertices)
410+ {
411+ added_shared = true;
412+ shared_offset = current_offset;
413+ }
414+
415+ const Ogre::VertexElement* texElem = vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_TEXTURE_COORDINATES);
416+
417+ Ogre::HardwareVertexBufferSharedPtr vbufText =
418+ vertex_data->vertexBufferBinding->getBuffer(texElem->getSource());
419+
420+ byte* vertexText = (byte*)vbufText->lock(Ogre::HardwareBuffer::HBL_NORMAL);
421+ float* pRealText;
422+
423+ for (ulong j = 0; j < vertex_data->vertexCount; ++j, vertexText += vbufText->getVertexSize())
424+ {
425+ texElem->baseVertexPointerToElement(vertexText, &pRealText);
426+
427+ TextCords[textoffsset].x = pRealText[0];
428+ TextCords[textoffsset].y = pRealText[1];
429+
430+ Sub_Mesh_Indexs[textoffsset] = i;
431+
432+ textoffsset++;
433+ }
434+
435+ vbufText->unlock();
436+ }
437+ }
438+
439+}
440+
441+// *************************************************************************
442+// * Set_Face_UV *
443+// *************************************************************************
444+void SB_Picking::Set_Face_UV()
445+{
446+ bool added_shared = false;
447+ size_t current_offset = 0;
448+ size_t shared_offset = 0;
449+ size_t next_offset = 0;
450+ size_t index_offset = 0;
451+
452+ const Ogre::MeshPtr mesh = ((Ogre::Entity*)pentity)->getMesh();
453+
454+ // Texture Cords UVS
455+ int textoffsset = 0;
456+
457+ for (unsigned short i = 0; i < mesh->getNumSubMeshes(); ++i)
458+ {
459+ Ogre::SubMesh* submesh = mesh->getSubMesh(i);
460+
461+ Ogre::VertexData* vertex_data = submesh->useSharedVertices ? mesh->sharedVertexData : submesh->vertexData;
462+
463+ if ((!submesh->useSharedVertices) || (submesh->useSharedVertices && !added_shared))
464+ {
465+ if (submesh->useSharedVertices)
466+ {
467+ added_shared = true;
468+ shared_offset = current_offset;
469+ }
470+
471+ const Ogre::VertexElement* texElem = vertex_data->vertexDeclaration->findElementBySemantic(Ogre::VES_TEXTURE_COORDINATES);
472+
473+ Ogre::HardwareVertexBufferSharedPtr vbufText =
474+ vertex_data->vertexBufferBinding->getBuffer(texElem->getSource());
475+
476+ byte* vertexText = (byte*)vbufText->lock(Ogre::HardwareBuffer::HBL_NORMAL);
477+ float* pRealText;
478+
479+ for (ulong j = 0; j < vertex_data->vertexCount; ++j, vertexText += vbufText->getVertexSize())
480+ {
481+ texElem->baseVertexPointerToElement(vertexText, &pRealText);
482+
483+ if (textoffsset == Face_Index)
484+ {
485+ float v = pRealText[0];
486+
487+ // pRealText[0] = 0;
488+ pRealText[0] = 1 - v;
489+ }
490+
491+ if (textoffsset == Face_Index+1)
492+ {
493+ float v = pRealText[0];
494+
495+ //pRealText[0] = 0;
496+ pRealText[0] = 1 - v;
497+ }
498+
499+ if (textoffsset == Face_Index+2)
500+ {
501+ float v = pRealText[0];
502+
503+ // pRealText[0] = 1;
504+ pRealText[0] = 1 - v;
505+ }
506+
507+ textoffsset++;
508+ }
509+
510+ vbufText->unlock();
511+ }
512+ }
513+}
514+
515+// *************************************************************************
516+// * Get_Material_Data *
517+// *************************************************************************
518+void SB_Picking::Get_Material_Data()
519+{
520+ strcpy(FaceMaterial, ((Ogre::Entity*)pentity)->getMesh()->getSubMesh(SubMesh_Face)->getMaterialName().c_str());
521+ Ogre::MaterialPtr MatCurent = static_cast<Ogre::MaterialPtr> (Ogre::MaterialManager::getSingleton().getByName(FaceMaterial));
522+ strcpy(TextureName, MatCurent->getTechnique(0)->getPass(0)->getTextureUnitState(0)->getTextureName().c_str());
523+}
--- Anim19_OSDN/SB_Picking.h (nonexistent)
+++ Anim19_OSDN/SB_Picking.h (revision 2547)
@@ -0,0 +1,65 @@
1+#pragma once
2+
3+/*
4+Copyright (c) 2023 World Editor -- HGT Software W.T.Flanigan H.C.Flanigan
5+
6+This software is provided 'as-is', without any express or implied
7+warranty. In no event will the authors be held liable for any damages
8+arising from the use of this software.
9+
10+Permission is granted to anyone to use this software for any purpose,
11+including commercial applications, and to alter it and redistribute it
12+freely, subject to the following restrictions:
13+
14+1. The origin of this software must not be misrepresented; you must not
15+claim that you wrote the original software. If you use this software
16+in a product, an acknowledgment in the product documentation would be
17+appreciated but is not required.
18+
19+2. Altered source versions must be plainly marked as such, and must not be
20+misrepresented as being the original software.
21+
22+3. This notice may not be removed or altered from any source
23+distribution.
24+*/
25+
26+class SB_Picking
27+{
28+public:
29+ SB_Picking(Ogre::SceneManager* sceneMgr);
30+ ~SB_Picking();
31+
32+ void Mouse_Pick_Entity();
33+ void Set_Face_UV();
34+
35+ Ogre::String Pl_Entity_Name;
36+ float closest_distance;
37+
38+ Ogre::Vector3* vertices;
39+ Ogre::Vector2* TextCords;
40+ Ogre::uint32* indices;
41+
42+ Ogre::uint32* Sub_Mesh_Indexs;
43+
44+ int SubMesh_Face;
45+
46+ char FaceMaterial[MAX_PATH];
47+ char TextureName[MAX_PATH];
48+
49+ size_t Total_vertex_count;
50+ size_t Total_index_count;
51+
52+ int Face_Index;
53+ int Sub_Mesh_Count;
54+
55+private:
56+ bool raycast(const Ogre::Ray& ray, Ogre::Vector3& result, Ogre::MovableObject*& target, float& closest_distance, const Ogre::uint32 queryMask);
57+ void GetMeshInformation(const Ogre::MeshPtr mesh, const Ogre::Vector3& position, const Ogre::Quaternion& orient, const Ogre::Vector3& scale);
58+ void Get_Material_Data();
59+
60+ Ogre::SceneManager* mSceneMgr;
61+ Ogre::RaySceneQuery* mRaySceneQuery;
62+
63+ Ogre::MovableObject* pentity;
64+};
65+
--- Anim19_OSDN/SB_Project.cpp (revision 2546)
+++ Anim19_OSDN/SB_Project.cpp (revision 2547)
@@ -1653,6 +1653,7 @@
16531653 strcat(Object_Ini_Path, "Objects");
16541654 strcat(Object_Ini_Path, "\\");
16551655
1656+ //App->Say(m_Level_Name);
16561657 //---------------------------------------------------
16571658
16581659 strcat(Object_Ini_Path, "Objects.efd");
--- Anim19_OSDN/SB_TopTabs.cpp (revision 2546)
+++ Anim19_OSDN/SB_TopTabs.cpp (revision 2547)
@@ -713,13 +713,14 @@
713713 App->CL_Vm_ImGui->Show_Object_Selection = 0;
714714
715715 App->SBC_TopTabs->Toggle_Select_Flag = 0;
716- App->SBC_Markers->mPickSight->hide();
716+ //App->SBC_Markers->mPickSight->hide();
717717 App->CL_Ogre->OgreListener->GD_Selection_Mode = 0;
718718 }
719719 else
720720 {
721+ App->CL_Vm_ImGui->Show_Object_Selection = 1;
721722 App->SBC_TopTabs->Toggle_Select_Flag = 1;
722- App->SBC_Markers->mPickSight->show();
723+ //App->SBC_Markers->mPickSight->show();
723724 App->CL_Ogre->OgreListener->GD_Selection_Mode = 1;
724725 }
725726
--- Anim19_OSDN/VM_ImGui.cpp (revision 2546)
+++ Anim19_OSDN/VM_ImGui.cpp (revision 2547)
@@ -294,46 +294,45 @@
294294 }
295295 else
296296 {
297-
298297 ImGui::Text("Selected Object");
299298 ImGui::Separator();
300299
301- ImGui::Text("Internal Name: = %s",App->CL_Ogre->OgreListener->Pl_Entity_Name.c_str());
300+ ImGui::Text("Internal Name: = %s",App->CL_Picking->Pl_Entity_Name.c_str());
302301 ImGui::Text("Object Name: = %s",App->CL_Ogre->OgreListener->Selected_Object_Name);
303302
304303 ImGui::Text("");
304+ ImGui::Text("Sub Meshes: = %i", App->CL_Picking->Sub_Mesh_Count);
305+ ImGui::Text("Total Vertices: = %i", App->CL_Picking->Total_vertex_count);
306+ ImGui::Text("Total Indices: = %i", App->CL_Picking->Total_index_count);
307+ ImGui::Text("Total Faces: = %i", App->CL_Picking->Total_index_count/3);
305308
306- ImGui::Text("Edit Selected Object");
307- ImGui::Separator();
309+ ImGui::Text("");
308310
309- ImGui::Indent();
310- ImGui::Indent();
311- ImGui::Indent();
311+ ImGui::Text("Distance: = %f", App->CL_Picking->closest_distance);
312312
313- if (ImGui::Button("Yes"))
313+ if (App->CL_Picking->TextCords)
314314 {
315- App->SBC_TopTabs->Toggle_Select_Flag = 0;
316- App->SBC_Markers->mPickSight->hide();
317- App->CL_Ogre->OgreListener->GD_Selection_Mode = 0;
315+ int Face_Index = App->CL_Picking->Face_Index;
318316
319- RedrawWindow(App->SBC_TopTabs->Camera_TB_hWnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
317+ ImGui::Text("Sub Mesh: = %i", App->CL_Picking->SubMesh_Face);
318+ ImGui::Text("Face Index: = %i", Face_Index / 3);
319+ ImGui::Text("");
320+ ImGui::Text("Vert1: = %.3f %.3f %.3f", App->SBC_Grid->HitVertices[0].x, App->SBC_Grid->HitVertices[0].y, App->SBC_Grid->HitVertices[0].z);
321+ ImGui::Text("Vert1: = %.3f %.3f %.3f", App->SBC_Grid->HitVertices[1].x, App->SBC_Grid->HitVertices[1].y, App->SBC_Grid->HitVertices[1].z);
322+ ImGui::Text("Vert1: = %.3f %.3f %.3f", App->SBC_Grid->HitVertices[2].x, App->SBC_Grid->HitVertices[2].y, App->SBC_Grid->HitVertices[2].z);
323+ ImGui::Text("");
324+ ImGui::Text("UV1: = %f %f", App->SBC_Grid->HitFaceUVs[0].x, App->SBC_Grid->HitFaceUVs[0].y);
325+ ImGui::Text("UV2: = %f %f", App->SBC_Grid->HitFaceUVs[1].x, App->SBC_Grid->HitFaceUVs[1].y);
326+ ImGui::Text("UV3: = %f %f", App->SBC_Grid->HitFaceUVs[2].x, App->SBC_Grid->HitFaceUVs[2].y);
327+ ImGui::Text("");
328+ ImGui::Text("Face Material: = %s", App->CL_Picking->FaceMaterial);
329+ ImGui::Text("Texture: = %s", App->CL_Picking->TextureName);
320330
321- //App->SBC_FileView->Select_Item(App->CL_Ogre->OgreListener->Selected_Entity_Index);
322- App->SBC_FileView->SelectItem(App->SBC_Scene->V_Object[App->CL_Ogre->OgreListener->Selected_Entity_Index]->FileViewItem);
323- Show_Object_Selection = 0;
324331 }
325332
326- ImGui::SameLine();
327-
328- if (ImGui::Button("No"))
333+ if (ImGui::Button("Test"))
329334 {
330- App->SBC_TopTabs->Toggle_Select_Flag = 0;
331- App->SBC_Markers->mPickSight->hide();
332- App->CL_Ogre->OgreListener->GD_Selection_Mode = 0;
333-
334- RedrawWindow(App->SBC_TopTabs->Camera_TB_hWnd, NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
335-
336- Show_Object_Selection = 0;
335+ App->CL_Picking->Set_Face_UV();
337336 }
338337
339338 ImGui::End();
Show on old repository browser