ATTENTION

This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices.


flexsim.com

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 11-27-2008
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default Scaling text in opengl

This is a question for an opengl expert (I think)

I have a silo that I want to write text on. But I want this text to stay the same when the silo changes size. So I called "drawtoobjectscale( current);" before I did the drawtext command. This works fine in x and y direction but doesn't work when I change the zsize. Then my text is extracted in z-direction

Any suggestions?

Steven
  #2  
Old 11-27-2008
tobias.biemueller tobias.biemueller is offline
Flexsim User
 
Join Date: Aug 2007
Location: Bielefeld, Germany
Posts: 42
Downloads: 22
Uploads: 0
Thanks: 23
Thanked 18 Times in 16 Posts
Rep Power: 164
tobias.biemueller is on a distinguished road
Default

Hi Steven,

if i understand it right, you mean the text should have the same size if the silo has 2 or 4 meters in any direction?
Then why you use drawtoobjectscale(current); and not drawtomodelscale(current)?

Or did i understand it wrong?
  #3  
Old 11-27-2008
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default

Hi Tobias,

I think you understand correctly but it just doesn't work. What I wrote was:

glPushMatrix();
//drawtomodelscale(current);
drawtoobjectscale( current);
double TextSize = 0.5;
drawtext(view, apchar(numtostring(MaxContent, 0, 1)), 0.1, -1.1, 0.2, TextSize, TextSize, 0.01, 90, 0, 0, 0, 0, 0, 1);
drawtext(view, "-----", 0.1, -1.1 , 0.4, TextSize, TextSize, 0.01, 90, 0, 0, 0, 0, 0, 1);
drawtext(view, apchar(numtostring(CurrentContent, 0, 1)), 0.1, -1.1, 0.6, TextSize, TextSize, 0.01, 90, 0, 0, 0, 0, 0, 1);
glPopMatrix();

If I use drawtoobjectscale, if I change the x and y values my text stays the same. If change the z-value my text changes
If I use drawtomodelscale, my text changes in all 3 (x,y,z) situations

So I don't know anymore

Steven
  #4  
Old 11-27-2008
Anthony Johnson's Avatar
Anthony Johnson Anthony Johnson is offline
Manager of Product Development
 
Join Date: Jul 2007
Posts: 440
Downloads: 86
Uploads: 4
Thanks: 171
Thanked 899 Times in 288 Posts
Rep Power: 735
Anthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond repute
Default

Hey Steven,
Yeah, the drawtext command is really weird in the way it scales. When the engine draws the object, it saves off the sx and sy of the object being drawn, and then as part of the drawtext command, it scales 1/sx, 1/sy. This means that when you call drawtext from within the draw trigger, the x and y size of the text will not change when you change the size of the object. However, by the fact that the drawtext command doesn't scale in the z direction, the thickness of the text will change. To fix that you can do the following:
Code:
spacescale(1,1,1/zsize(current));
drawtext(view, "Hello", 1, 0,0, 5, 5, 0.1, 0,0,0, 0,0,0, 1);
I honestly wish that we had implemented the drawtext command better from the start. In my opinion it shouldn't scale at all because it just causes confusion as to how to get the size right, especially when the draw code is doing its own translation, scaling and rotating. But we can't really change it because that would break old models. Anyway, there you go.
  #5  
Old 11-28-2008
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default

Anthony,

Thanks, it worked (of course it does if you tell me it will) but now if I changed it in y direction my text got thicker. So I probably have to play around with the different combination of drawtoobject/model scale (these are actually also GLScalef not!)

This opengl always puzzles me and I either have to think real hard or just try a lot to get what I want.

Anyway is there a chance that we get a drawtext2 command later on that fixes those issues?

Regards,

Steven
The Following User Says Thank You to Steven Hamoen For This Useful Post:
Kris Geisberger (12-05-2008)
  #6  
Old 11-29-2008
Anthony Johnson's Avatar
Anthony Johnson Anthony Johnson is offline
Manager of Product Development
 
Join Date: Jul 2007
Posts: 440
Downloads: 86
Uploads: 4
Thanks: 171
Thanked 899 Times in 288 Posts
Rep Power: 735
Anthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond repute
Default

Steven,
Yeah, that's why I wish we had implemented it different. There's an easy fix if you're just drawing the text how it was meant to be drawn, but as soon as you want to re-orient the text using scaling, rotating, etc., the fix no longer works.

I hate to add a command called drawtext2, because it just doesn't seem like good design to have all of these commands with a 2 next to them, like we didn't design it right the first time so we had to add another one (oh, wait, that's exactly the reason, ). I'd at least like to deceive people into believing our initial design was a good one. But I guess if that's the only way to fix it, maybe that's the way to go. Another option, perhaps, is to add an additional parameter to the drawtext command which, if 1, won't do the scaling. Or another option is to implement a completely new, simplified command that doesn't take all of the size, rotation, color, etc. parameters, because they're kind of redundant given that you can do your own scaling/rotating/coloring.

Anyway, there probably should be some solution provided for this issue in future releases. I'm just not sure which yet.

Also, as a side note, I personally don't like to use the commands drawtomodelscale or drawtoobjectscale, because they themselves can be somewhat deceiving. For example, if you're already in model scale, and you call drawtomodelscale, then it just messes the scaling up, and same for drawtoobject scale. I like to either use the glScalef() command, or just call spacescale(1/sx, 1/sy, 1/sz) and spacescale(sx,sy,sz), which are the same as calling drawtomodelscale and drawtoobjectscale respectively. This way, I can see exactly how it's being scaled in the code.
The Following 3 Users Say Thank You to Anthony Johnson For This Useful Post:
Tom David (11-30-2008)
  #7  
Old 12-09-2008
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default

Anthony or anybody else that can give me a hint,

Sorry, I feel really stupid but I can't get it right. What ever I do there is always something changing dimensions.

So if I would have a very simply piece of code (in the ondraw trigger of any object, a queue for instance)

double TextSize = 1;
spacescale( x, y, z);
drawtext(view, "Test", 0.1, -1.1, 0.2, TextSize, TextSize, 0.01, 90, 0, 0, 0, 0, 0, 1);

What do the x, y, z have to be to make the text not to scale? I found that x =1 works fine but the y and the z I can't find it out. Or do I have to do something else as well?

Steven
  #8  
Old 12-09-2008
Alex Christensen Alex Christensen is offline
Flexsim Technical Support
 
Join Date: Nov 2007
Location: Provo, UT
Posts: 96
Downloads: 41
Uploads: 8
Thanks: 29
Thanked 141 Times in 56 Posts
Rep Power: 298
Alex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to behold
Default

I got it to work with this:
Code:
double TextSize = 1;
spacescale( 1, 1, ysize(current)/zsize(current));
drawtext(view, "Test", 0.1, -1.1, 0.2, TextSize, TextSize, 0.01, 90, 0, 0, 0, 0, 0, 1);
Anthony is right that it's a little confusing to draw rotated text, but it's possible!
The Following 2 Users Say Thank You to Alex Christensen For This Useful Post:
RalfGruber (12-10-2008)
  #9  
Old 12-09-2008
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default

Alex,

Thanks, the divide y by z solution didn't spring to my mind at least

Unfortunately it doesn't work in my complete code but I do at the beginning say something like drawtomodelscale, so I probably have to compensate for that scaling first and then try with your solutions again etc. This OpenGl is wonderfull but is quite complex in combination with Flexsim

Is there a rule for rotating around a certain axis means a strange division?

Anyway thanks, it just means I have to spend a lot more time (or find a student to spent that time ) to get it exactly right.

Steven

BTW is there a way of resetting the matrix such that you can start fresh with drawing your text?
  #10  
Old 12-09-2008
Alex Christensen Alex Christensen is offline
Flexsim Technical Support
 
Join Date: Nov 2007
Location: Provo, UT
Posts: 96
Downloads: 41
Uploads: 8
Thanks: 29
Thanked 141 Times in 56 Posts
Rep Power: 298
Alex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to beholdAlex Christensen is a splendid one to behold
Default

That's what glPushMatrix and glPopMatrix are for. You can use them like this:
Code:
glPushMatrix();//save the current drawing position to the openGL matrix stack
//translate, rotate, scale, draw stuff...
glPopMatrix();//and we're back where we started
double TextSize = 1;
spacescale( 1, 1, ysize(current)/zsize(current));
drawtext(view, "Test", 0.1, -1.1, 0.2, TextSize, TextSize, 0.01, 90, 0, 0, 0, 0, 0, 1);
Just make sure that you have the same number of pushes as pops, or else you'll really mess up how Flexsim draws other objects.
  #11  
Old 12-09-2008
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default

Alex,

I already used the pushmatrix commands but as I understood it, it copies the previous matrix which means that any scaling and translating is copied with it. But any thing that you do in this matrix is not affecting the previous matrix. (correct me if I'm wrong here but that is what I got from my opengl reading)

But anyway I got it working now. First I used the translate and rotate command to sort off do everything in one plane and then I used:

spacescale( xsize(current), ysize(current) , zsize(current)/ysize(current));

This smoothend out all the previous scaling and with the idea of the division that you gave me I got it figured out. So as usual with opengl it takes some trial and error, but it can be done!

(it took me I think, over 4 hours in total for a dumb piece of text that has to be stationary, but after a certain amount of time it becomes a matter of principle)

Steven

Tags
opengl, scaling, text


Thread Thread Starter Forum Replies Last Post
How to display dynamic text next to an object Cliff King Tips and Tricks 4 11-11-2010 01:45 PM
Triangle and Text Demo Brandon Peterson Tips and Tricks 0 05-09-2008 10:12 AM
How to display 3D text/shapes in a static position regardless of the view angle. Regan Blackett Tips and Tricks 0 08-03-2007 10:51 AM


All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.