Author Topic: Transformation Query  (Read 6058 times)

0 Members and 1 Guest are viewing this topic.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Transformation Query
« on: October 05, 2019, 07:58:02 am »
Hi. Is there a function (either directly or in GL) in QB64 to convert the coordinate system from OpenGL to Cartesian coordinates?  (for hardware MAPTRIANGLE screens, it is one transformation settings for this use)
« Last Edit: October 05, 2019, 08:15:04 am by Petr »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Transformation Query
« Reply #1 on: October 05, 2019, 08:44:59 am »
Hi. Is there a function (either directly or in GL) in QB64 to convert the coordinate system from OpenGL to Cartesian coordinates?  (for hardware MAPTRIANGLE screens, it is one transformation settings for this use)


Hi Petr,

Isn't it WINDOW and didn't we discuss this before?

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Transformation Query
« Reply #2 on: October 05, 2019, 11:29:55 am »
Hi BPlus, I don't remember. I don't expect the Window statement to solve the shift of the X and Y axes depending on the value of the Z axis.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Transformation Query
« Reply #3 on: October 05, 2019, 11:37:44 am »
Hi BPlus, I don't remember. I don't expect the Window statement to solve the shift of the X and Y axes depending on the value of the Z axis.


Oh you're talking 3D stuff, now I understand.

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Transformation Query
« Reply #4 on: October 05, 2019, 11:59:58 am »
Not to rub this in everyone's face again but if you understand vectors, this picture shows how I compute 2D projections (QB64 Cartesian coordinates) form a general 3D construct. The equation circled on the bottom is literally an/the/indistinguishable form the answer you seek.

EDIT: Petr, if this is valuable to you I can help interpret the sketch.
« Last Edit: October 05, 2019, 12:05:21 pm by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Transformation Query
« Reply #5 on: October 05, 2019, 12:58:26 pm »
Hi STxAxTIC

If I know the direction of the 3D vector and its size, if the 3D vector points inwards or outwards, it is simply not parallel to the X or Y axis, its size needs to be reduced for 2D viewing (does not extend as much because its direction is not perpendicular to 2D view). Perhaps I wrote it right. I wonder how to calculate this decrease.
Wait! This does actually determine the endpoint of the vector? In fact, the angle of deflection determines the increment ratio in the X and Y axes, right? If the start and end points of the vector had the same depth, then the increment in 3D would be the same as in 2D. However, if the starting and ending 3D points have different depths, then for 2D display it is necessary to calculate the ratio by how much the 2D vector representing the 3D vector on the 2D monitor will grow in a particular axis.

Well, I have to test it!

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Transformation Query
« Reply #6 on: October 05, 2019, 06:01:17 pm »
You're asking the perfectly right question Petr.

This particular inquiry:

Quote
If I know the direction of the 3D vector and its size, if the 3D vector points inwards or outwards, it is simply not parallel to the X or Y axis, its size needs to be reduced for 2D viewing (does not extend as much because its direction is not perpendicular to 2D view). Perhaps I wrote it right. I wonder how to calculate this decrease.

... is answered by the equation I circled. This will be easiest in vector language, but tell me where you stand real quick. Do you know what I mean by a "dot product" specifically?
You're not done when it works, you're done when it's right.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Transformation Query
« Reply #7 on: October 06, 2019, 05:12:19 am »
Hi. I don't know this term (dot product), but I've already looked at Wikipedia for what it is. The scalar product does not offer a solution because the expected result of the function is two numbers. Quite precisely, it is about converting coordinates from 3D to 2D and vice versa. In order to understand one another, run this program to show you my problem (and of course there will be complications with another coordinate system).

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. CLS , &HFFFFFF11
  3. LINE (100, 100)-(200, 150), &HFFFFFF00, BF
  4. LINE (100, 100)-(200, 150), &HFF000000, B
  5. COLOR &HFF000000
  6. _PRINTSTRING (125, 120), "Button"
  7. _PRINTSTRING (100, 400), "This is button created in 2D. Button coordinates are 100,100 to 200,150. Press key"
  8. LINE (100, 400)-(800, 416), &HFFFFFF00, BF
  9. _PRINTSTRING (100, 400), "But now. This is placed to space....                                              "
  10. LINE (100, 400)-(800, 416), &HFFFFFF00, BF
  11. s = _COPYIMAGE(_DEST, 33)
  12.  
  13. FOR g = -1.7 TO -4 STEP -.01
  14.     w = _WIDTH(s)
  15.     h = _HEIGHT(s)
  16.     _MAPTRIANGLE (0, 0)-(w, 0)-(0, h), s TO(-2, 2, -1.9)-(2, 2, g)-(-2, -2, -1.9)
  17.     _MAPTRIANGLE (w, 0)-(0, h)-(w, h), s TO(2, 2, g)-(-2, -2, -1.9)-(2, -2, g)
  18.     _DISPLAY
  19.     _DELAY .05
  20.  
  21.     _MAPTRIANGLE (0, 0)-(w, 0)-(0, h), s TO(-2, 2, -1.9)-(2, 2, g)-(-2, -2, -1.9)
  22.     _MAPTRIANGLE (w, 0)-(0, h)-(w, h), s TO(2, 2, g)-(-2, -2, -1.9)-(2, -2, g)
  23.     COLOR &HFFFFFFFF
  24.     _PRINTSTRING (450, 584), "Which are 2D coordinates for button now?"
  25.     _DISPLAY
  26.  


Of course, I can read the coordinates for now, in case the 3D image stays the same. Well, it's not a solution, it's just a bypassing the problem.
« Last Edit: October 06, 2019, 06:18:45 am by Petr »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Transformation Query
« Reply #8 on: October 06, 2019, 09:40:51 am »
Hi Petr
but is the area pictured by _Maptriangles  avaiable for other graphic instructions?

with this I got nothing
Code: QB64: [Select]
  1.     _MAPTRIANGLE (0, 0)-(w, 0)-(0, h), s TO(-2, 2, -1.9)-(2, 2, g)-(-2, -2, -1.9)
  2.     _MAPTRIANGLE (w, 0)-(0, h)-(w, h), s TO(2, 2, g)-(-2, -2, -1.9)-(2, -2, g)
  3.     LINE (100, 100)-(200, 150), &HFFFFFFFF, B ' debug line
  4.     COLOR &HFFFFFFFF
  5.     _PRINTSTRING (450, 584), "Which are 2D coordinates for button now?"
  6.     _DISPLAY
  7.     _DELAY .05
I have tried a method of interpolation between extreme X and X of the point considered ( x1 to new X1 as MaxX to newMaxX) but to verify this I wanted to use a graphic method... but it seems that here I am in the deep blue I am not able to show original button on the screen overlapping the final image got using _maptriangle.

Programming isn't difficult, only it's  consuming time and coffee

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Transformation Query
« Reply #9 on: October 06, 2019, 09:46:59 am »
My dear Petr:

Nice job trying to research the dot product, or scalar product, or projection, or whatever anyone likes to call it. Unfortunately:

Quote
The scalar product does not offer a solution because the expected result of the function is two numbers.

EDIT: I just chose a second interpretation of your confusion so read the edit history of this post only if its interesting. Unfortunately its worse than I thought. I'm a little sick today so best of luck with this. The answer is right in front of you where I put it though. Keep on studying. For instance, count the number of dot products in the note I posted. There's a bit more than one.

EDIT 2: Are you familiar with vector language in the first place? I.e., the arrow over a letter means its really a list, right?
« Last Edit: October 06, 2019, 09:55:11 am by STxAxTIC »
You're not done when it works, you're done when it's right.

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Transformation Query
« Reply #10 on: October 06, 2019, 09:55:15 am »
Hi TempodiBasic, use _DISPLAYORDER and CLS, 0 IN 32 BIT screen for transparent software screen background. As in this source:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2. CLS , &HFFFFFF11
  3. LINE (100, 100)-(200, 150), &HFFFFFF00, BF
  4. LINE (100, 100)-(200, 150), &HFF000000, B
  5. COLOR &HFF000000
  6. _PRINTSTRING (125, 120), "Button"
  7. _PRINTSTRING (100, 400), "This is button created in 2D. Button coordinates are 100,100 to 200,150. Press key"
  8. LINE (100, 400)-(800, 416), &HFFFFFF00, BF
  9. _PRINTSTRING (100, 400), "But now. This is placed to space....                                              "
  10. LINE (100, 400)-(800, 416), &HFFFFFF00, BF
  11. s = _COPYIMAGE(_DEST, 33)
  12. CLS , 0
  13.  
  14.  
  15. FOR g = -1.7 TO -4 STEP -.01
  16.     w = _WIDTH(s)
  17.     h = _HEIGHT(s)
  18.     _MAPTRIANGLE (0, 0)-(w, 0)-(0, h), s TO(-2, 2, -1.9)-(2, 2, g)-(-2, -2, -1.9)
  19.     _MAPTRIANGLE (w, 0)-(0, h)-(w, h), s TO(2, 2, g)-(-2, -2, -1.9)-(2, -2, g)
  20.     _DISPLAY
  21.     _DELAY .05
  22.     _MAPTRIANGLE (0, 0)-(w, 0)-(0, h), s TO(-2, 2, -1.9)-(2, 2, g)-(-2, -2, -1.9)
  23.     _MAPTRIANGLE (w, 0)-(0, h)-(w, h), s TO(2, 2, g)-(-2, -2, -1.9)-(2, -2, g)
  24.     COLOR &HFF000000
  25.     _PRINTSTRING (40, 584), "Which are 2D coordinates for button now?"
  26.     _DISPLAY
  27.  


Hi STxAxTIC, please be patient with patience, today is not one of my bright days. The scalar product of vectors returns one number. Yes. I agree. To express a point in 2D, however, I need the 2 numbers X, Y. Therefore, I think the scalar product is not related to the 2D conversion. It's possible that I'm wrong, of course.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Transformation Query
« Reply #11 on: October 06, 2019, 10:48:17 am »
Hi Petr,

Code: QB64: [Select]
  1. _MAPTRIANGLE (w, 0)-(0, h)-(w, h), s TO(2, 2, g)-(-2, -2, -1.9)-(2, -2, g)

This is real eye opener for the 2nd, 3D, way to use _MAPTRIANGLE.

I played around with X, Y of the TO destination because it seems to have completely different coordinate system than screen to which it draws, sort of... like I change all 2's to 1's or 4's and same thing seems to be drawn through the loop of swing the text rectangle on left hinge opening door on right side but when I put 1's in instead of 2's my final screen is different.

So just translating x, y of screen to what _MAPTRIANGLE draws would require a study of Source code to _MAPTRIANGLE to see how it converts X, Y and then of course ultimately the Z's in question.

I don't see how learning Dot Product or Vectors will help you use _MAPTRIANGLE??? but it would give STxAxTIC some company to discuss his favorite subject :D 

(He, STxAxTIC, might consider some sort of tutorial on vectors and how it helps in rendering 3D space, I know I would be interested if he doesn't mind starting at elementary level.)

« Last Edit: October 06, 2019, 11:14:19 am by bplus »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Transformation Query
« Reply #12 on: October 06, 2019, 10:56:20 am »
Hi BPlus. MAPTRIANGLE 3D (use hardware images) use OpenGL Coordinate system.


Converting coordinates between OpenGL and 2D is not so easy. This is way how to compile mouse to 3D coordinate system.


I assumed a built-in function in QB64 when it offers 3D and OpenGL environments. It does not really matter if I convert 3D coordinates to 2D or vice versa, unfortunately, without conversion between coordinate systems, the use of the mouse is limited to software screens only or OpenGL without real depth.


« Last Edit: October 06, 2019, 10:59:46 am by Petr »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Transformation Query
« Reply #13 on: October 06, 2019, 11:19:14 am »
Hi BPlus. MAPTRIANGLE 3D (use hardware images) use OpenGL Coordinate system.


Converting coordinates between OpenGL and 2D is not so easy. This is way how to compile mouse to 3D coordinate system.


I assumed a built-in function in QB64 when it offers 3D and OpenGL environments. It does not really matter if I convert 3D coordinates to 2D or vice versa, unfortunately, without conversion between coordinate systems, the use of the mouse is limited to software screens only or OpenGL without real depth.

hmm... maybe need source code to GL too to see how it converts the coordinates it is passed from QB64.

... so enter the Matrix... :D
« Last Edit: October 06, 2019, 11:20:35 am by bplus »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Transformation Query
« Reply #14 on: October 06, 2019, 11:26:40 am »
BPlus, I think the solution is directly contained in the 3D point itself. Coordinates X, Y, Z. If Z were the same as the depth of the 2D screen, that is, the depth of 3D would be at the same depth as the 2D screen, then X in 2D would be the same as X in 3D and Y as well. (I am thinking of looking directly at the screen). If the depth is higher, the point moves toward the center of the screen (in OpenGL, the starting point is 0.0.0 in the middle of the screen). Problem is, what this ratio is. At least I think so.

BPlus, on the proposal to use the function from OpenGL. It would be nice, but I'm a pessimist. Well, I'll try it somehow (in own way), myself, although it's probably very beyond my knowledge. Thanks for support.