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 03-13-2013
Vadim Fooks's Avatar
Vadim Fooks Vadim Fooks is offline
Flexsim User
 
Join Date: Feb 2012
Posts: 67
Downloads: 26
Uploads: 0
Thanks: 50
Thanked 24 Times in 13 Posts
Rep Power: 118
Vadim Fooks will become famous soon enough
Default drawline ignores rgb parameters. Sometimes.

Ladies and Gentlemen,

I have encountered an interesting problem.
I am writing a bit of code that generate rectangles in a 3D view.
Problem is the generated rectanges appear black in 3D view regardless of the RGB values I pass to the drawline().
As soon as I drop a single object into the view, the problem disappears and reappears again if I delete this object. What am I doing wrong?




Black:



I drop in a processor and the color appears:



Here is a snippet of a code that draws the box:

Code:
// OnDraw
treenode current = parnode(1);
treenode view = parnode(2);
treenode blockMetadata = parnode(3);
drawtomodelscale(current);
// .....
DrawBox(view, xbo, ybo, rz, sx, sy, xo, yo, zo, 1, 0, 0);
drawtoobjectscale(current);
return 1;
// DrawBox
/**Draw a box on the ground*/
treenode view = parnode(1);
double x      = parval (2); 
double y      = parval (3); 
double theta  = parval (4); 
double width  = parval (5); 
double depth  = parval (6);  
double xOrigin= parval (7); 
double yOrigin= parval (8); 
double zOrigin= parval (9);
double r      = parval (10); 
double g      = parval (11); 
double b      = parval (12);
double x1 = (x) + width/2.0 * cos(degreestoradians(theta));
double y1 = (y) + width/2.0 * sin(degreestoradians(theta));
double x2 = (x) + width/2.0 * cos(degreestoradians(theta+180));
double y2 = (y) + width/2.0 * sin(degreestoradians(theta+180));
// Corners
double xc0 = (x1) + (depth/2.0) * cos(degreestoradians(theta+90));
double yc0 = (y1) + (depth/2.0) * sin(degreestoradians(theta+90));
double xc1 = (x1) + (depth/2.0) * cos(degreestoradians(theta-90));
double yc1 = (y1) + (depth/2.0) * sin(degreestoradians(theta-90));
double xc2 = (x2) + (depth/2.0) * cos(degreestoradians(theta-90));
double yc2 = (y2) + (depth/2.0) * sin(degreestoradians(theta-90));
double xc3 = (x2) + (depth/2.0) * cos(degreestoradians(theta+90));
double yc3 = (y2) + (depth/2.0) * sin(degreestoradians(theta+90));
drawline(view, xc0 - xOrigin, yc0 - yOrigin, -zOrigin, xc1 - xOrigin, yc1 - yOrigin, -zOrigin, r, g, b);
drawline(view, xc1 - xOrigin, yc1 - yOrigin, -zOrigin, xc2 - xOrigin, yc2 - yOrigin, -zOrigin, r, g, b);
drawline(view, xc2 - xOrigin, yc2 - yOrigin, -zOrigin, xc3 - xOrigin, yc3 - yOrigin, -zOrigin, r, g, b);
drawline(view, xc0 - xOrigin, yc0 - yOrigin, -zOrigin, xc3 - xOrigin, yc3 - yOrigin, -zOrigin, r, g, b);
// Centroid
double offset = min(width, depth)/10.0;
drawline(view, x - xOrigin + offset, y - yOrigin + offset, -zOrigin, x - xOrigin - offset, y - yOrigin - offset, -zOrigin, r, g, b);
drawline(view, x - xOrigin - offset, y - yOrigin + offset, -zOrigin, x - xOrigin + offset, y - yOrigin - offset, -zOrigin, r, g, b);
Attached Images
File Type: jpg black_and_white.jpg (65.5 KB, 167 views)
File Type: jpg color.jpg (120.6 KB, 171 views)
  #2  
Old 03-14-2013
mark.gormley mark.gormley is offline
Flexsim User
 
Join Date: Oct 2008
Posts: 58
Downloads: 12
Uploads: 0
Thanks: 32
Thanked 63 Times in 29 Posts
Rep Power: 181
mark.gormley has a spectacular aura aboutmark.gormley has a spectacular aura about
Default

I dont get the colour disapearing when draw this, but the lines arent drawn completly.
This changes when I add a processor in as above.

The way I can see to get around this is to add:
glDisable(GL_TEXTURE_2D);
at the top of your draw box command and then:
glEnable(GL_TEXTURE_2D);
at the end.

It looks like there is a slight issue in the implementation of the drawline command which is causing the textures to get messed up. drawtext has a similar problem.

Last edited by mark.gormley; 03-14-2013 at 03:32 AM.
The Following User Says Thank You to mark.gormley For This Useful Post:
Vadim Fooks (03-14-2013)
  #3  
Old 03-14-2013
Phil BoBo's Avatar
Phil BoBo Phil BoBo is offline
Flexsim Development
 
Join Date: Jan 2008
Posts: 756
Downloads: 109
Uploads: 18
Thanks: 385
Thanked 1,483 Times in 525 Posts
Rep Power: 1174
Phil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond reputePhil BoBo has a reputation beyond repute
Default

To optimize the graphics rendering speed, we no longer set the OpenGL state to default values before calling OnDraw. Because of this, it may be in a strange state (such as having textures turned on and a texture available to draw).

Adding a glDisable(GL_TEXTURE_2D) before calling drawline() should fix the problem.

The reason it changes when you add a processor is because the opengl state is different depending on what object was drawn previously.
The Following 5 Users Say Thank You to Phil BoBo For This Useful Post:
Vadim Fooks (03-14-2013)


Thread Thread Starter Forum Replies Last Post
Controlling Rack Parameters Through GUI shashanktrivedi Q&A 1 06-26-2011 06:23 AM
Model parameters custom gui shashanktrivedi Q&A 2 04-24-2011 06:21 AM
How to send more than 3 parameters by senddelaymessage() Hao Zhou Q&A 3 03-02-2011 12:20 PM
runspeed with 2 parameters? Steven Hamoen Q&A 3 10-01-2010 11:33 AM
Passing parameters in executefsnode Sung Kim Q&A 2 06-01-2010 09:37 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.